From 948b5b2d9c247a9519243174f039c998b18fe9bf Mon Sep 17 00:00:00 2001 From: iTrooz_ Date: Tue, 1 Nov 2022 09:33:11 +0100 Subject: [PATCH] ux: Change "Esc" key behavior on hex editor popups (#810) * set same behaviour for PopupGoto and PopupFind * Force close the popup when user is editing an input --- .../builtin/source/content/views/view_hex_editor.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 19c50a0e4..0421d4fc0 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -44,8 +44,10 @@ namespace hex::plugin::builtin { ImGui::EndTabItem(); } - ImGui::SetKeyboardFocusHere(); - ImGui::SetNextFrameWantCaptureKeyboard(true); + if(this->m_requestFocus){ + ImGui::SetKeyboardFocusHere(); + this->m_requestFocus = false; + } if (ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) { if (auto result = this->m_evaluator.evaluate(this->m_input); result.has_value()) { const auto inputResult = result.value(); @@ -92,6 +94,7 @@ namespace hex::plugin::builtin { Mode m_mode = Mode::Absolute; + bool m_requestFocus = true; std::string m_input; MathEvaluator m_evaluator; }; @@ -781,6 +784,11 @@ namespace hex::plugin::builtin { ImGui::SetNextWindowPos(ImGui::GetWindowPos() + ImGui::GetWindowContentRegionMin() - ImGui::GetStyle().WindowPadding, ImGuiCond_Appearing); if (ImGui::BeginPopup("##hex_editor_popup", ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |ImGuiWindowFlags_NoTitleBar)) { + + // Force close the popup when user is editing an input + if(ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Escape))){ + ImGui::CloseCurrentPopup(); + } if (this->m_currPopup != nullptr) this->m_currPopup->draw(this);