From c4d8638674fb32f82acdeb0a72178800060b66cd Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 8 Sep 2021 19:06:38 +0200 Subject: [PATCH] Add user closing fonticon autocomplete with escape --- src/Components/Modules/TextRenderer.cpp | 14 ++++++++++++++ src/Components/Modules/TextRenderer.hpp | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 0feb8097..f681de53 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -232,6 +232,7 @@ namespace Components if(fontIconStart < 0 || fontIconStart == edit->cursor || !isalpha(static_cast(edit->buffer[fontIconStart]))) { context.autocompleteActive = false; + context.userClosed = false; context.lastHash = 0; context.resultCount = 0; return; @@ -245,6 +246,10 @@ namespace Components else if(context.selectedOffset >= context.resultOffset + FontIconAutocompleteContext::MAX_RESULTS) context.resultOffset = context.selectedOffset - (FontIconAutocompleteContext::MAX_RESULTS - 1); + // If the user closed the context do not draw or update + if (context.userClosed) + return; + context.autocompleteActive = true; // No need to update results when in modifiers @@ -453,6 +458,15 @@ namespace Components AutocompleteFill(context, scrPlace, edit); return true; + case Game::K_ESCAPE: + if (!context.userClosed) + { + context.autocompleteActive = false; + context.userClosed = true; + return true; + } + return false; + default: return false; } diff --git a/src/Components/Modules/TextRenderer.hpp b/src/Components/Modules/TextRenderer.hpp index 7328330c..99b537cb 100644 --- a/src/Components/Modules/TextRenderer.hpp +++ b/src/Components/Modules/TextRenderer.hpp @@ -79,6 +79,7 @@ namespace Components bool autocompleteActive; bool inModifiers; + bool userClosed; unsigned int lastHash; std::string lastQuery; FontIconAutocompleteResult results[MAX_RESULTS];