Skip to content

Commit

Permalink
fix(game): don't start/stop text/IME input
Browse files Browse the repository at this point in the history
SDL2 enables IME input by default (it won't be in SDL3).
We ask SDL2 to start/stop IME input when we enter/exit search box.
So, after using search, IME input is disabled, but ImGui relies on it
always being enabled - it uses it for keyboard input, but it doesn't
start/stop IME itself (since [1]; they reenabled that
on SDL3 though [2]; issue itself is [3]).

We can (and actually could) activate IME even outside of text input. :(

Fixes #83 ([ImGui] Text
input doesn't work after using song search).

[1] ocornut/imgui@a7703fe
[2] ocornut/imgui@fab96a6
[3] ocornut/imgui#6306
  • Loading branch information
chown2 committed Apr 25, 2024
1 parent 6e59baf commit 50c7d60
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/game/graphics/SDL2/window_SDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ void startTextInput(const RectF& textBox, const std::string& oldText, std::funct
r.w = static_cast<int>(std::ceil(scaledTextBox.w));
r.h = static_cast<int>(std::ceil(scaledTextBox.h));
SDL_SetTextInputRect(&r);
SDL_StartTextInput();
// Do *not* start and stop text inputs. They are enabled by default in SDL2.
// https://github.com/ocornut/imgui/issues/6306
// TODO(SDL3): uncomment this, it won't longer be enabled by default.
// SDL_StartTextInput();
isEditing = true;

::funUpdateText(textBuf);
Expand All @@ -585,7 +588,9 @@ void stopTextInput()

isEditing = false;
funUpdateText = [](const std::string&) {};
SDL_StopTextInput();
// See the comment for SDL_StartTextInput above.
// TODO(SDL3): uncomment this.
// SDL_StopTextInput();
}


Expand Down

0 comments on commit 50c7d60

Please sign in to comment.