From 115c0716d44c74bc358ce1d1abdd3d21f4070086 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 31 Oct 2023 00:22:31 +0000 Subject: [PATCH] TextInput: A couple of fixes 1. Fixes `erase`. 2. Marks some events that will handle TextInput as handled. 3. Adds Ctrl+A. --- Source/DiabloUI/text_input.cpp | 11 ++++++++++- Source/DiabloUI/text_input.hpp | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/DiabloUI/text_input.cpp b/Source/DiabloUI/text_input.cpp index 79199ec17..ea99dce43 100644 --- a/Source/DiabloUI/text_input.cpp +++ b/Source/DiabloUI/text_input.cpp @@ -33,6 +33,12 @@ bool HandleInputEvent(const SDL_Event &event, TextInputState &state, case SDL_KEYDOWN: { switch (event.key.keysym.sym) { #ifndef USE_SDL1 + case SDLK_a: + if (isCtrl) { + state.setCursorToStart(); + state.setSelectCursorToEnd(); + } + return true; case SDLK_c: if (isCtrl) { const std::string selectedText { state.selectedText() }; @@ -92,8 +98,11 @@ bool HandleInputEvent(const SDL_Event &event, TextInputState &state, typeFn(utf8); return true; } +#else + // Mark events that will also trigger SDL_TEXTINPUT as handled. + return !isCtrl && !isAlt + && event.key.keysym.sym >= SDLK_SPACE && event.key.keysym.sym <= SDLK_z; #endif - return false; } #ifndef USE_SDL1 case SDL_TEXTINPUT: diff --git a/Source/DiabloUI/text_input.hpp b/Source/DiabloUI/text_input.hpp index 1e05785d5..b35a181e4 100644 --- a/Source/DiabloUI/text_input.hpp +++ b/Source/DiabloUI/text_input.hpp @@ -90,7 +90,7 @@ class TextInputState { void erase(size_t pos, size_t len) { - std::memmove(&buf_[pos], &buf_[pos + len], len); + std::memmove(&buf_[pos], &buf_[pos + len], len_ - (pos + len)); len_ -= len; buf_[len_] = '\0'; }