From 066a013804e0cd9890f01f41f8ba679c9b55c355 Mon Sep 17 00:00:00 2001 From: 7415963987456321 Date: Mon, 29 Apr 2024 21:19:12 +0000 Subject: [PATCH 1/3] fix: typo 'begining'->'beginning' Should clarify the code, makes it easier to find if it is correctly spelled --- pdf_viewer/input.cpp | 1 - scripts/sioyek-generator.py | 2 +- scripts/sioyek.py | 4 ++-- scripts/summary_highlight_server.py | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pdf_viewer/input.cpp b/pdf_viewer/input.cpp index faaac2db1..2bbe67e45 100644 --- a/pdf_viewer/input.cpp +++ b/pdf_viewer/input.cpp @@ -2310,7 +2310,6 @@ CommandManager::CommandManager(ConfigManager* config_manager) { new_commands["focus_text"] = []() {return std::make_unique< FocusTextCommand>(); }; new_commands["goto_window"] = []() {return std::make_unique< GotoWindowCommand>(); }; new_commands["toggle_smooth_scroll_mode"] = []() {return std::make_unique< ToggleSmoothScrollModeCommand>(); }; - new_commands["goto_begining"] = []() {return std::make_unique< GotoBeginningCommand>(); }; new_commands["toggle_scrollbar"] = []() {return std::make_unique< ToggleScrollbarCommand>(); }; new_commands["overview_to_portal"] = []() {return std::make_unique< OverviewToPortalCommand>(); }; new_commands["select_rect"] = []() {return std::make_unique< SelectRectCommand>(); }; diff --git a/scripts/sioyek-generator.py b/scripts/sioyek-generator.py index 56aa67023..aceeca63b 100644 --- a/scripts/sioyek-generator.py +++ b/scripts/sioyek-generator.py @@ -2,7 +2,7 @@ script used to generate sioyek.py file ''' sioyek_commands = { - "goto_begining": [False, False, False, True], + "goto_beginning": [False, False, False, True], "goto_end": [False, False, False, True], "goto_definition": [False, False, False, False], "overview_definition": [False, False, False, False], diff --git a/scripts/sioyek.py b/scripts/sioyek.py index 557974c8b..840c56fcf 100644 --- a/scripts/sioyek.py +++ b/scripts/sioyek.py @@ -83,9 +83,9 @@ def run_command(self, command_name, text=None, focus=False): else: subprocess.run(params) - def goto_begining(self, focus=False): + def goto_beginning(self, focus=False): data = None - self.run_command("goto_begining", data, focus=focus) + self.run_command("goto_beginning", data, focus=focus) def goto_end(self, focus=False): data = None diff --git a/scripts/summary_highlight_server.py b/scripts/summary_highlight_server.py index 1792a6ac2..21f2facbf 100644 --- a/scripts/summary_highlight_server.py +++ b/scripts/summary_highlight_server.py @@ -31,7 +31,7 @@ def decode(outputs_ids): def roll_encoding(encoding): # by default if encodings are smaller than maximum length, they are padded with - # zeroes at the end. We need the zero padding to be at the begining for next + # zeroes at the end. We need the zero padding to be at the beginning for next # character prediction to work new_encoding = torch.clone(encoding) num_rows = encoding.shape[0] @@ -163,4 +163,4 @@ def handle_text_mask(): return jsonify({'text': refined_imask, 'page': page}) - app.run() \ No newline at end of file + app.run() From b709d5a501ab7e7da05c2058f81d1c4a8663fbd2 Mon Sep 17 00:00:00 2001 From: 7415963987456321 Date: Mon, 29 Apr 2024 23:51:27 +0000 Subject: [PATCH 2/3] Implement goto_beginning() and fix top and bottom scrolling This implements goto_beginning() and simplifies the goto_end() function --- pdf_viewer/document_view.cpp | 12 ++++++++++-- pdf_viewer/document_view.h | 1 + pdf_viewer/input.cpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pdf_viewer/document_view.cpp b/pdf_viewer/document_view.cpp index afcb173b6..0094fb1c4 100644 --- a/pdf_viewer/document_view.cpp +++ b/pdf_viewer/document_view.cpp @@ -441,10 +441,18 @@ void DocumentView::goto_mark(char symbol) { } } } + +void DocumentView::goto_beginning() { + if (current_document) { + goto_page(0); + } +} + void DocumentView::goto_end() { if (current_document) { - int last_page_index = current_document->num_pages() - 1; - set_offset_y(current_document->get_accum_page_height(last_page_index) + current_document->get_page_height(last_page_index)); + int last_page_index = current_document->num_pages()-1; + goto_page(last_page_index); + goto_bottom_of_page(); } } diff --git a/pdf_viewer/document_view.h b/pdf_viewer/document_view.h index ffe1c7701..11e803ad2 100644 --- a/pdf_viewer/document_view.h +++ b/pdf_viewer/document_view.h @@ -106,6 +106,7 @@ class DocumentView { NormalizedWindowPos window_to_normalized_window_pos(WindowPos window_pos); void goto_mark(char symbol); void goto_end(); + void goto_beginning(); void goto_left(); void goto_left_smart(); diff --git a/pdf_viewer/input.cpp b/pdf_viewer/input.cpp index 2bbe67e45..eb18e3539 100644 --- a/pdf_viewer/input.cpp +++ b/pdf_viewer/input.cpp @@ -740,7 +740,7 @@ class GotoBeginningCommand : public Command { main_widget->main_document_view->goto_page(num_repeats - 1 + main_widget->main_document_view->get_page_offset()); } else { - main_widget->main_document_view->set_offset_y(0.0f); + main_widget->main_document_view->goto_beginning(); } } From d806bcf77af489e4659ec427a96ff8e7f0023ec6 Mon Sep 17 00:00:00 2001 From: 7415963987456321 Date: Tue, 30 Apr 2024 01:35:38 +0000 Subject: [PATCH 3/3] Change how num_repeats offsets the page jump --- pdf_viewer/input.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pdf_viewer/input.cpp b/pdf_viewer/input.cpp index eb18e3539..715d760de 100644 --- a/pdf_viewer/input.cpp +++ b/pdf_viewer/input.cpp @@ -737,7 +737,7 @@ class GotoBeginningCommand : public Command { public: void perform(MainWidget* main_widget) { if (num_repeats) { - main_widget->main_document_view->goto_page(num_repeats - 1 + main_widget->main_document_view->get_page_offset()); + main_widget->main_document_view->goto_page(num_repeats + main_widget->main_document_view->get_page_offset()); } else { main_widget->main_document_view->goto_beginning(); @@ -756,8 +756,10 @@ class GotoBeginningCommand : public Command { class GotoEndCommand : public Command { public: void perform(MainWidget* main_widget) { + int num_pages = main_widget->main_document_view->get_document()->num_pages()-1; if (num_repeats > 0) { - main_widget->main_document_view->goto_page(num_repeats - 1 + main_widget->main_document_view->get_page_offset()); + main_widget->main_document_view->goto_page(num_pages - num_repeats); + main_widget->main_document_view->goto_bottom_of_page(); } else { main_widget->main_document_view->goto_end();