From 0596adf87c07de2dc59ba8d427830d446e472f19 Mon Sep 17 00:00:00 2001 From: hrdl <31923882+hrdl-github@users.noreply.github.com> Date: Sat, 10 Jun 2023 12:03:26 +0200 Subject: [PATCH] Extend selection start and end positions to coincide with highlight --- pdf_viewer/document.cpp | 2 +- pdf_viewer/document_view.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pdf_viewer/document.cpp b/pdf_viewer/document.cpp index 6e6182015..81c21e226 100644 --- a/pdf_viewer/document.cpp +++ b/pdf_viewer/document.cpp @@ -80,7 +80,7 @@ void Document::fill_highlight_rects(fz_context* ctx, fz_document* doc_) { std::vector highlight_rects; std::vector merged_rects; std::wstring highlight_text; - get_text_selection(ctx, highlight.selection_begin, highlight.selection_end, true, highlight_rects, highlight_text, doc_); + get_text_selection(ctx, highlight.selection_begin, highlight.selection_end, false, highlight_rects, highlight_text, doc_); merge_selected_character_rects(highlight_rects, merged_rects); if (i < highlights.size()) { diff --git a/pdf_viewer/document_view.cpp b/pdf_viewer/document_view.cpp index 348e0e619..0ca1b792b 100644 --- a/pdf_viewer/document_view.cpp +++ b/pdf_viewer/document_view.cpp @@ -307,7 +307,9 @@ void DocumentView::add_highlight(AbsoluteDocumentPos selection_begin, AbsoluteDo get_text_selection(selection_begin, selection_end, is_word_selection, selected_characters, selected_text); merge_selected_character_rects(selected_characters, merged_characters); if (selected_text.size() > 0) { - current_document->add_highlight(selected_text, merged_characters, selection_begin, selection_end, type); + const fz_rect& rect1 = selected_characters.front(); + const fz_rect& rect2 = selected_characters.back(); + current_document->add_highlight(selected_text, merged_characters, {rect1.x0, (rect1.y0 + rect1.y1) / 2}, {rect2.x0, (rect2.y0 + rect2.y1) / 2}, type); } } }