add clipboard support for SDL2 and copy-paste for Editor (#1491)

This commit is contained in:
Dennis Brakhane
2026-01-13 15:23:41 +01:00
committed by GitHub
parent 19bcf5bd32
commit d16e42e5c2
2 changed files with 24 additions and 8 deletions
+16 -8
View File
@@ -37,6 +37,7 @@ int sdl_loop()
SDL_Event event;
while(SDL_PollEvent(&event)){
bool textinput_action_delete = false;
wi::input::sdlinput::ProcessEvent(event);
switch(event.type){
case SDL_QUIT:
editor.Exit();
@@ -59,12 +60,20 @@ int sdl_loop()
break;
}
case SDL_KEYDOWN:
if(event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE
|| event.key.keysym.scancode == SDL_SCANCODE_DELETE
|| event.key.keysym.scancode == SDL_SCANCODE_KP_BACKSPACE){
wi::gui::TextInputField::DeleteFromInput();
textinput_action_delete = true;
}
if(event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE
|| event.key.keysym.scancode == SDL_SCANCODE_KP_BACKSPACE) {
wi::gui::TextInputField::DeleteFromInput();
textinput_action_delete = true;
} else if(wi::input::Down(wi::input::KEYBOARD_BUTTON_LCONTROL) || wi::input::Down(wi::input::KEYBOARD_BUTTON_RCONTROL)) {
// HACK: AddInput will check if Ctrl is pressed and
// handle Ctrl-C/Ctrl-V/Ctrl-X for us, but
// wi::input::Down will only be accurate after
// wi::input::Update was run, which will happen next
// frame, which is too late for us. So we just call it
// now and then call AddInput
wi::input::Update(editor.window, editor.canvas);
wi::gui::TextInputField::AddInput('?'); // AddInput actually ignores the argument when Ctrl is pressed
}
break;
case SDL_TEXTINPUT:
if(!textinput_action_delete){
@@ -80,7 +89,6 @@ int sdl_loop()
default:
break;
}
wi::input::sdlinput::ProcessEvent(event);
}
}
@@ -108,7 +116,7 @@ void set_window_icon(SDL_Window *window) {
rmask, gmask, bmask, amask);
SDL_SetWindowIcon(window, icon);
SDL_FreeSurface(icon);
}
+8
View File
@@ -2217,6 +2217,10 @@ namespace wi::helper
}
::GlobalUnlock(wbuf_handle);
::CloseClipboard();
#elif defined(SDL2)
char* str = SDL_GetClipboardText();
StringConvert(str, wstr);
SDL_free(str);
#elif defined(__APPLE__)
std::string str = wi::apple::GetClipboardText();
StringConvert(str, wstr);
@@ -2244,6 +2248,10 @@ namespace wi::helper
if (::SetClipboardData(CF_UNICODETEXT, wbuf_handle) == NULL)
::GlobalFree(wbuf_handle);
::CloseClipboard();
#elif defined(SDL2)
std::string str;
StringConvert(wstr, str);
SDL_SetClipboardText(str.c_str());
#elif defined(__APPLE__)
std::string str;
StringConvert(wstr, str);