From 2c56adde5a31a182a5457f80b01ff71c3fda579d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Tue, 1 Aug 2023 18:41:34 +0200 Subject: [PATCH] Work around some input method bug on windows At least this fixes Hangul input for me. I'm sure nobody else had any problems with it and I'm sure everyone will start having problems with it now :) --- src/gui/interface/Engine.cpp | 7 ++++++- src/gui/interface/Engine.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui/interface/Engine.cpp b/src/gui/interface/Engine.cpp index 57b27900e..e9adf3834 100644 --- a/src/gui/interface/Engine.cpp +++ b/src/gui/interface/Engine.cpp @@ -249,10 +249,15 @@ void Engine::onTextEditing(String text, int start) // arrives. We also forward a textediting event on every packet, // which is redundant, but should be okay, as textediting events are // not supposed to have an effect on the actual text being edited. - if (start == 0) + // * We define a first-y looking packet as one with a start parameter + // lower than or equal to the start parameter of the previous packet. + // This is general enough that it seems to work around the bugs + // of all SDL input method backends. + if (start <= lastTextEditingStart) { textEditingBuf.clear(); } + lastTextEditingStart = start; textEditingBuf.append(text); if (state_ && !ignoreEvents) state_->DoTextEditing(textEditingBuf); diff --git a/src/gui/interface/Engine.h b/src/gui/interface/Engine.h index 3e8bbe69d..1eaba3ac5 100644 --- a/src/gui/interface/Engine.h +++ b/src/gui/interface/Engine.h @@ -5,6 +5,7 @@ #include "common/ExplicitSingleton.h" #include "graphics/Pixel.h" #include "gui/interface/Point.h" +#include class Graphics; namespace ui @@ -92,6 +93,7 @@ namespace ui bool resizable; bool textInput = false; + int lastTextEditingStart = INT_MAX; float dt; float fps;