Skip to content

Commit

Permalink
Add expand_all_highlights command
Browse files Browse the repository at this point in the history
  • Loading branch information
hrdl-github committed Sep 29, 2023
1 parent 225a670 commit bf7fda2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pdf_viewer/document_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/document_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions pdf_viewer/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Portal> link = widget->main_document_view->find_closest_portal();
Expand Down Expand Up @@ -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>(); };
Expand Down

0 comments on commit bf7fda2

Please sign in to comment.