Add user closing fonticon autocomplete with escape

This commit is contained in:
Jan 2021-09-08 19:06:38 +02:00
parent cfefd7d220
commit c4d8638674
2 changed files with 15 additions and 0 deletions

View File

@ -232,6 +232,7 @@ namespace Components
if(fontIconStart < 0 || fontIconStart == edit->cursor || !isalpha(static_cast<unsigned char>(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;
}

View File

@ -79,6 +79,7 @@ namespace Components
bool autocompleteActive;
bool inModifiers;
bool userClosed;
unsigned int lastHash;
std::string lastQuery;
FontIconAutocompleteResult results[MAX_RESULTS];