From bf7fda2b88bc2a195d91622cb405221e34391727 Mon Sep 17 00:00:00 2001 From: hrdl <31923882+hrdl-github@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:33:04 +0200 Subject: [PATCH] Add expand_all_highlights command --- pdf_viewer/document_view.cpp | 9 +++++++++ pdf_viewer/document_view.h | 1 + pdf_viewer/input.cpp | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/pdf_viewer/document_view.cpp b/pdf_viewer/document_view.cpp index 9eea74ce2..03c3f05ce 100644 --- a/pdf_viewer/document_view.cpp +++ b/pdf_viewer/document_view.cpp @@ -204,6 +204,15 @@ void DocumentView::expand_highlight_with_index(int index) { add_highlight(hl.selection_begin, hl.selection_end, true, hl.type); } +void DocumentView::expand_all_highlights() { + std::size_t num_highlights = current_document->get_highlights().size(); + if (num_highlights > 0) { + for (; num_highlights--;) { + expand_highlight_with_index(0); + } + } +} + float DocumentView::get_offset_x() { return offset_x; } diff --git a/pdf_viewer/document_view.h b/pdf_viewer/document_view.h index 6f67bb634..f62783d76 100644 --- a/pdf_viewer/document_view.h +++ b/pdf_viewer/document_view.h @@ -79,6 +79,7 @@ class DocumentView { void delete_highlight(Highlight hl); void delete_closest_bookmark_to_offset(float offset); void expand_highlight_with_index(int index); + void expand_all_highlights(); float get_offset_x(); float get_offset_y(); AbsoluteDocumentPos get_offsets(); diff --git a/pdf_viewer/input.cpp b/pdf_viewer/input.cpp index 033c7618e..28b91cb6c 100644 --- a/pdf_viewer/input.cpp +++ b/pdf_viewer/input.cpp @@ -641,6 +641,17 @@ class ExpandHighlightCommand : public Command { } }; +class ExpandAllHighlightsCommand : public Command { + void perform(MainWidget* widget) { + widget->main_document_view->expand_all_highlights(); + widget->validate_render(); + } + + std::string get_name() { + return "expand_all_highlights"; + } +}; + class GotoPortalCommand : public Command { void perform(MainWidget* widget) { std::optional link = widget->main_document_view->find_closest_portal(); @@ -2239,6 +2250,7 @@ CommandManager::CommandManager(ConfigManager* config_manager) { new_commands["delete_bookmark"] = []() {return std::make_unique< DeleteBookmarkCommand>(); }; new_commands["delete_highlight"] = []() {return std::make_unique< DeleteHighlightCommand>(); }; new_commands["expand_highlight"] = []() {return std::make_unique< ExpandHighlightCommand>(); }; + new_commands["expand_all_highlights"] = []() {return std::make_unique< ExpandAllHighlightsCommand>(); }; new_commands["goto_link"] = []() {return std::make_unique< GotoPortalCommand>(); }; new_commands["goto_portal"] = []() {return std::make_unique< GotoPortalCommand>(); }; new_commands["edit_link"] = []() {return std::make_unique< EditPortalCommand>(); };