From b585bca90b17d638edf10c68f016095afa0dc6b6 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 30 Dec 2020 15:04:43 -0500 Subject: [PATCH 1/3] look_menu_search: fix crash due to certain cursor keys not restoring list Fixes #1737 --- plugins/search.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/search.cpp b/plugins/search.cpp index 27958f6dc..7b791dc7f 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -115,13 +115,16 @@ static string get_unit_description(df::unit *unit) return desc; } -static bool cursor_key_pressed (std::set *input) +static bool cursor_key_pressed (std::set *input, bool in_entry_mode) { - // give text input (e.g. "2") priority over cursor keys - for (auto it = input->begin(); it != input->end(); ++it) + if (in_entry_mode) { - if (Screen::keyToChar(*it) != -1) - return false; + // give text input (e.g. "2") priority over cursor keys + for (auto it = input->begin(); it != input->end(); ++it) + { + if (Screen::keyToChar(*it) != -1) + return false; + } } return input->count(df::interface_key::CURSOR_UP) || @@ -249,7 +252,7 @@ public: // ENTER or ESC: leave typing mode end_entry_mode(); } - else if (cursor_key_pressed(input)) + else if (cursor_key_pressed(input, entry_mode)) { // Arrow key pressed. Leave entry mode and allow screen to process key end_entry_mode(); @@ -1953,7 +1956,7 @@ public: end_entry_mode(); return false; } - if (cursor_key_pressed(input)) + if (cursor_key_pressed(input, in_entry_mode())) { end_entry_mode(); clear_search(); From 936a13181aa777372781e44ceb1677d2ed303887 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 30 Dec 2020 15:08:20 -0500 Subject: [PATCH 2/3] Update changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index fdc7c13e7..94c187b08 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -35,6 +35,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - `embark-assistant`: fixed order of factors when calculating min temperature +- `search`: fixed crash when searching the ``k`` sidebar and navigating to another tile with certain keys, like ``<`` or ``>`` # 0.47.04-r4 From 4fbd763c1a2b1a0579d68d125a6d7ae798dd03f3 Mon Sep 17 00:00:00 2001 From: lethosor Date: Fri, 29 Jan 2021 00:28:32 -0500 Subject: [PATCH 3/3] Also cancel 'k' search when hotkeys (F1 - Shift-F8) are pressed --- plugins/search.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/search.cpp b/plugins/search.cpp index 7b791dc7f..9ecae6460 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -1956,7 +1956,9 @@ public: end_entry_mode(); return false; } - if (cursor_key_pressed(input, in_entry_mode())) + bool hotkey_pressed = + input->lower_bound(interface_key::D_HOTKEY1) != input->upper_bound(interface_key::D_HOTKEY16); + if (cursor_key_pressed(input, in_entry_mode()) || hotkey_pressed) { end_entry_mode(); clear_search();