1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00
pdf.js/web
Nicolò Ribaudo da5b681b16
[chrome] Fix text selection with .markedContent
The current text layer approach based on absolutely positioned
`<span>` elements by default causes flickering with text selection,
and we have browser-specific workarounds to solve that.

In Chrome, the workaround involves moving the `.endOfContent` element to
right after the last element that contains some selected content. This
works well in simple PDFs, but breaks when we have `span.markedContent`
elements. Given a text layer structure like the following, rendered
as four consecutive lines:
```html
<span class="markedContent">
  <br>
  <span>development enter the construction phase (estimated at around</span>
</span>
<span class="markedContent">
  <br>
  <span>300 MEUR).</span>
</span>
<span class="markedContent">
  <br>
  <span>Kreate's EBITA increased to 2.8 MEUR (Q4'23: 2.7 MEUR) and the</span>
</span>
<span class="markedContent">
  <br>
  <span>margin rose to 3.7% (Q4'23: 3.4%). However, profitability was</span>
</span>
```
when starting to select from inside the first line and dragging down
to the empty space after the second line, Chrome will anchor the
selection at the beginning of either the `<br>` or the `<span>` inside
the last `.markedContent`, depending on whether the selection is in
"per-character mode" (i.e. click and drag) or "per-word mode" (i.e.
double click and drag). This causes us to insert the `.endOfContent`
element in the wrong place (one element too far), which causes one
more line to be selected, which triggers another `"selecctionchange"`
event, which causes us to move `.endOfContent` again, and so on, looping
until when the whole page is selected.

This commit fixes the issue by making sure that when the end of the
selection range points to the _begining_ of an element, we walk back
the dom finding the first non-empty element, and attatch `.endOfContent`
to the end of that.
2025-04-07 17:36:40 +02:00
..
images [Editor] Add the possibility to change a signature description (bug 1948116) 2025-02-14 14:00:45 +01:00
.gitignore Support multiple wasm-files in the development viewer 2025-01-18 09:35:11 +01:00
alt_text_manager.js Add a new closeIfActive method in the OverlayManager class 2025-02-14 15:43:00 +01:00
annotation_editor_layer_builder.css [api-major] Apply the userUnit using CSS, to fix the text/annotation layers (bug 1947248) 2025-02-11 14:36:06 +01:00
annotation_editor_layer_builder.js [api-major] Change viewer component render-methods to take parameter objects 2025-01-21 23:29:45 +01:00
annotation_editor_params.js Merge pull request #19339 from calixteman/signature_tools 2025-01-30 10:54:56 +01:00
annotation_layer_builder.css [api-major] Apply the userUnit using CSS, to fix the text/annotation layers (bug 1947248) 2025-02-11 14:36:06 +01:00
annotation_layer_builder.js Fix autolinking error due to redundant annotations on zooming 2025-02-19 13:18:31 +01:00
app.js Merge pull request #19733 from Snuffleupagus/import-vite-ignore 2025-03-30 11:58:20 +02:00
app_options.js [api-minor] Enable enableAutoLinking by default 2025-03-21 11:49:03 +01:00
autolinker.js Add new bounding-box helpers in Util to reduce code duplication 2025-03-23 19:20:02 +01:00
base_pdf_page_view.js Reset #renderError on RenderingCancelledException (PR 19128 follow-up) 2025-02-25 16:46:01 +01:00
base_tree_viewer.js Limit base-class initialization checks to development and TESTING modes 2024-08-12 12:26:35 +02:00
caret_browsing.js Update the CaretBrowsingMode toolbar-height if the toolbarDensity preference changes (PR 18786 follow-up) 2024-10-01 19:43:16 +02:00
chrome-i18n-allow-access-to-file-urls.json Add translations of "Allow access to file URLs" 2015-08-14 18:59:55 +02:00
chromecom.js [Editor] Add the possibility to change a signature description (bug 1948116) 2025-02-14 14:00:45 +01:00
compressed.tracemonkey-pldi-09.pdf Add Makefile. Move some files around to make building the website easier. 2011-07-05 10:53:57 -07:00
debugger.css Fix the textLayer-opacity when using the FontInspector (PR 17533 follow-up) 2024-01-26 18:31:38 +01:00
debugger.mjs Use arrow function with various Array methods 2025-03-02 15:19:04 +01:00
dialog.css [Editor] Fix the style of the buttons in dialog (bug 1953003) 2025-03-11 20:03:23 +01:00
download_manager.js Do not stringify errors when logging them 2024-12-06 14:47:22 +01:00
draw_layer_builder.css [Editor] Add a new base class to allow to add a drawing in the SVG layer. 2024-11-28 15:23:03 +01:00
draw_layer_builder.js [api-major] Change viewer component render-methods to take parameter objects 2025-01-21 23:29:45 +01:00
editor_undo_bar.js [Editor] (WIP) Add a new tool in order to add an handwritten signature to a pdf (bug 1942343) 2025-01-29 21:52:14 +01:00
event_utils.js Add the possibility to dispatch some pdf.js events at the chrome level (bug 1904585) 2024-06-25 21:03:34 +02:00
external_services.js Add the possibility to compress/decompress the signature data in order to store them in the logins storage in Firefox (bug 1946171) 2025-02-10 19:09:51 +01:00
firefox_print_service.js [api-minor] Implement basic support for OptionalContent Usage dicts (issue 5764, bug 1826783) 2024-03-12 13:18:15 +01:00
firefoxcom.js [Editor] Add some telemetry for the signature editor (bug 1945827) 2025-02-24 21:10:04 +01:00
generic_scripting.js [api-minor] Attempt to improve support for using the PDF.js builds with Vite 2025-03-28 16:34:00 +01:00
generic_signature_storage.js [Editor] Add some telemetry for the signature editor (bug 1945827) 2025-02-24 21:10:04 +01:00
genericcom.js Don't bundle the FakeMLManager class in regular builds 2025-02-27 12:59:58 +01:00
genericl10n.js Replace the regular expression in GenericL10n.#getPaths with simple string parsing 2025-03-14 15:54:14 +01:00
grab_to_pan.js Use the stopEvent helper function everywhere possible 2024-11-28 13:25:56 +01:00
interfaces.js Stop sending the unused options parameter to various download-methods in the viewer 2024-08-02 20:46:13 +02:00
l10n.js Do not stringify errors when logging them 2024-12-06 14:47:22 +01:00
message_bar.css [Editor] Add a border to the undo button in the snackbar in order to make a contrast (bug 1952563) 2025-03-28 21:42:57 +01:00
new_alt_text_manager.js Add a new closeIfActive method in the OverlayManager class 2025-02-14 15:43:00 +01:00
overlay_manager.js Add a new closeIfActive method in the OverlayManager class 2025-02-14 15:43:00 +01:00
password_prompt.js Add a new closeIfActive method in the OverlayManager class 2025-02-14 15:43:00 +01:00
pdf_attachment_viewer.js [api-minor] Improve the FileSpec implementation 2024-05-01 18:02:05 +02:00
pdf_cursor_tools.js Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up) 2024-09-28 12:29:51 +02:00
pdf_document_properties.js Move the getPage call in PDFDocumentProperties class 2024-12-01 12:25:16 +01:00
pdf_find_bar.js Support toggling the PDFFindBar options with the Enter key (issue 19175) 2024-12-06 17:53:28 +01:00
pdf_find_controller.js Remove a few eslint-disable statements in the web/ folder 2025-02-17 13:40:09 +01:00
pdf_find_utils.js [api-minor] Don't normalize the text used in the text layer. 2023-04-17 14:31:23 +02:00
pdf_history.js [CRX] Remove obsolete manifest features 2024-08-25 20:34:03 +02:00
pdf_layer_viewer.js Re-factor how PDFLayerViewer decides if the UI needs to updated on "optionalcontentconfigchanged" events 2024-10-01 13:25:22 +02:00
pdf_link_service.js Re-use the isValidExplicitDest helper function in the worker/viewer 2025-03-01 12:08:56 +01:00
pdf_outline_viewer.js [api-minor] Move the page reference/number caching into the API 2024-04-29 18:54:06 +02:00
pdf_page_detail_view.js Add an OutputScale static method to get the devicePixelRatio 2025-03-12 21:07:06 +01:00
pdf_page_view.js [api-minor] Enable enableAutoLinking by default 2025-03-21 11:49:03 +01:00
pdf_presentation_mode.js Remove event listeners with signal in web/pdf_presentation_mode.js 2024-04-18 18:41:18 +02:00
pdf_print_service.js Remove a few eslint-disable statements in the web/ folder 2025-02-17 13:40:09 +01:00
pdf_rendering_queue.js Avoid degrading scroll performance due to the detail view 2025-02-21 10:00:57 -08:00
pdf_scripting_manager.component.js Use shorter arrow functions where possible 2024-01-21 10:13:12 +01:00
pdf_scripting_manager.js Do not stringify errors when logging them 2024-12-06 14:47:22 +01:00
pdf_sidebar.js Remove the sidebar resizing event listeners with an AbortController 2024-08-10 12:24:59 +02:00
pdf_single_page_viewer.js Remove the abstract BaseViewer-class 2022-09-08 12:38:17 +02:00
pdf_thumbnail_view.js Inline the PDFThumbnailView.prototype.#finishRenderTask helper method 2025-03-15 14:19:16 +01:00
pdf_thumbnail_viewer.js Support the maxCanvasPixels option in the thumbnails code 2025-03-10 14:12:07 +01:00
pdf_viewer.component.js Ensure that GenericL10n works if the locale files cannot be loaded 2024-01-31 14:07:11 +01:00
pdf_viewer.css [Editor] Populate the 'Add signature' menu with the saved signatures (bug 1947828) 2025-02-13 15:59:57 +01:00
pdf_viewer.js Merge pull request #19701 from Snuffleupagus/enableAutoLinking-true 2025-03-25 18:18:08 +01:00
pdfjs.js Introduce a helper function for clamping a value to a range 2025-03-06 14:05:26 +01:00
preferences.js Limit base-class initialization checks to development and TESTING modes 2024-08-12 12:26:35 +02:00
print_utils.js Handle appending consistently in the xfaLayer regardless of rendering intent (PR 17177 follow-up) 2023-10-26 12:05:33 +02:00
secondary_toolbar.js Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up) 2024-09-28 12:29:51 +02:00
signature_manager.css [Editor] in the signature UI, disable the description input if there is no signature (bug 1956114) 2025-03-26 23:02:13 +01:00
signature_manager.js [Editor] in the signature UI, disable the description input if there is no signature (bug 1956114) 2025-03-26 23:02:13 +01:00
struct_tree_layer_builder.js [api-major] Apply the userUnit using CSS, to fix the text/annotation layers (bug 1947248) 2025-02-11 14:36:06 +01:00
stubs-geckoview.js [Editor] Add a new dialog for the signature editor (bug 1945574) 2025-02-05 23:00:38 +01:00
text_accessibility.js [Editor] Add the parent tag id (if any) to the serialized editors (bug 1845087) 2023-09-07 18:22:33 +02:00
text_highlighter.js Fix left offset when scrolling to search result 2024-12-16 16:04:13 +01:00
text_layer_builder.css Make tagged images visible for screen readers (bug 1708040) 2024-09-05 17:59:42 +02:00
text_layer_builder.js [chrome] Fix text selection with .markedContent 2025-04-07 17:36:40 +02:00
toggle_button.css Remove unused CSS variables 2025-01-07 10:29:23 +01:00
toolbar-geckoview.js [GeckoView] Remove the open-in-app button (bug 1832519) 2024-03-04 19:32:12 +01:00
toolbar.js Merge pull request #19339 from calixteman/signature_tools 2025-01-30 10:54:56 +01:00
ui_utils.js Introduce a helper function for clamping a value to a range 2025-03-06 14:05:26 +01:00
view_history.js Add a bit more validation in the ViewHistory constructor 2020-03-21 13:55:06 +01:00
viewer-geckoview.css [GV] Increase the height (48px) of the toolbar in order to fit the a11y recommendations (bug 1838602) 2024-10-02 19:17:40 +02:00
viewer-geckoview.html Remove all the translatable strings from the html 2025-03-13 18:38:29 +01:00
viewer-geckoview.js Upgrade eslint-plugin-perfectionist to version 4.2.0 2024-12-07 13:44:48 +01:00
viewer-snippet-chrome-extension.html [api-minor] Move to Fluent for the localization (bug 1858715) 2023-10-19 11:20:41 +02:00
viewer-snippet-chrome-overlays.html Convert the existing overlays to use <dialog> elements (issue 14698) 2022-03-28 11:36:29 +02:00
viewer-snippet-firefox-extension.html [api-major] Output JavaScript modules in the builds (issue 10317) 2023-10-07 09:31:08 +02:00
viewer-snippet.html [api-minor] Move to Fluent for the localization (bug 1858715) 2023-10-19 11:20:41 +02:00
viewer.css [Editor] Fix the color of the labels in the editing doorhangers 2025-02-20 19:31:57 +01:00
viewer.html Improve addSignatureDescription/editSignatureDescription handling (issue 19683) 2025-03-19 11:38:56 +01:00
viewer.js [Editor] Add the possibility to change a signature description (bug 1948116) 2025-02-14 14:00:45 +01:00
xfa_layer_builder.css Remove unnecessary alpha-value from CSS rgb colors 2023-10-06 09:50:03 +02:00
xfa_layer_builder.js [api-major] Change viewer component render-methods to take parameter objects 2025-01-21 23:29:45 +01:00