From d36bd253e8d1d5d7a60a69f803582158a9993de9 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 21 Mar 2024 23:50:13 +0100 Subject: [PATCH] feat: Allow shift-selecting multiple find view occurrences --- plugins/builtin/include/content/views/view_find.hpp | 1 + plugins/builtin/source/content/views/view_find.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/include/content/views/view_find.hpp b/plugins/builtin/include/content/views/view_find.hpp index b3088b08e..25ac94cce 100644 --- a/plugins/builtin/include/content/views/view_find.hpp +++ b/plugins/builtin/include/content/views/view_find.hpp @@ -101,6 +101,7 @@ namespace hex::plugin::builtin { using OccurrenceTree = wolv::container::IntervalTree; PerProvider> m_foundOccurrences, m_sortedOccurrences; + PerProvider m_lastSelectedOccurrence; PerProvider m_occurrenceTree; PerProvider m_currFilter; diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 8ed0c917b..a977a4bea 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -531,6 +531,7 @@ namespace hex::plugin::builtin { } m_sortedOccurrences.get(provider) = m_foundOccurrences.get(provider); + m_lastSelectedOccurrence = nullptr; for (const auto &occurrence : m_foundOccurrences.get(provider)) m_occurrenceTree->insert({ occurrence.region.getStartAddress(), occurrence.region.getEndAddress() }, occurrence); @@ -895,6 +896,7 @@ namespace hex::plugin::builtin { m_foundOccurrences->clear(); m_sortedOccurrences->clear(); m_occurrenceTree->clear(); + m_lastSelectedOccurrence = nullptr; EventHighlightingChanged::post(); } @@ -1007,7 +1009,11 @@ namespace hex::plugin::builtin { ImGuiExt::TextFormatted("{}", value); ImGui::SameLine(); if (ImGui::Selectable("##line", foundItem.selected, ImGuiSelectableFlags_SpanAllColumns)) { - if (ImGui::GetIO().KeyCtrl) { + if (ImGui::GetIO().KeyShift && m_lastSelectedOccurrence != nullptr) { + for (auto start = std::min(&foundItem, m_lastSelectedOccurrence.get(provider)); start <= std::max(&foundItem, m_lastSelectedOccurrence.get(provider)); start += 1) + start->selected = true; + + } else if (ImGui::GetIO().KeyCtrl) { foundItem.selected = !foundItem.selected; } else { for (auto &occurrence : *m_sortedOccurrences) @@ -1015,6 +1021,8 @@ namespace hex::plugin::builtin { foundItem.selected = true; ImHexApi::HexEditor::setSelection(foundItem.region.getStartAddress(), foundItem.region.getSize()); } + + m_lastSelectedOccurrence = &foundItem; } drawContextMenu(foundItem, value);