From 31322bcc76bbe3fc2d6c75303a6129b2869b18ff Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 6 Aug 2025 22:20:31 +0200 Subject: [PATCH] fix: Unavailable menu items still being visible in the command palette --- .../builtin/source/content/command_palette_commands.cpp | 7 +++++++ .../builtin/source/content/views/view_command_palette.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 20112d415..ce528477e 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include #include @@ -358,6 +360,11 @@ namespace hex::plugin::builtin { if (!entry.enabledCallback()) continue; + if (entry.view != nullptr) { + if (View::getLastFocusedView() != entry.view) + continue; + } + std::vector names; std::transform(entry.unlocalizedNames.begin(), entry.unlocalizedNames.end(), std::back_inserter(names), [](auto &name) { return Lang(name); }); diff --git a/plugins/builtin/source/content/views/view_command_palette.cpp b/plugins/builtin/source/content/views/view_command_palette.cpp index 8c7fe87f7..e243c342b 100644 --- a/plugins/builtin/source/content/views/view_command_palette.cpp +++ b/plugins/builtin/source/content/views/view_command_palette.cpp @@ -118,9 +118,15 @@ namespace hex::plugin::builtin { // Draw the results if (ImGui::BeginChild("##results", ImGui::GetContentRegionAvail(), ImGuiChildFlags_NavFlattened, ImGuiWindowFlags_AlwaysVerticalScrollbar)) { + u32 id = 1; for (const auto &[displayResult, matchedCommand, callback] : m_lastResults) { + ImGui::PushID(id); ImGui::PushItemFlag(ImGuiItemFlags_NoTabStop, false); - ON_SCOPE_EXIT { ImGui::PopItemFlag(); }; + ON_SCOPE_EXIT { + ImGui::PopItemFlag(); + ImGui::PopID(); + id += 1; + }; // Allow executing a command by clicking on it or selecting it with the keyboard and pressing enter if (ImGui::Selectable(displayResult.c_str(), false, ImGuiSelectableFlags_NoAutoClosePopups)) {