Skip to content

[hold] Document view #5: Improve text overlay alignment for PageViewer selection accuracy#610

Draft
hoyla wants to merge 4 commits intomainfrom
ljh-pageviewer-ux-3
Draft

[hold] Document view #5: Improve text overlay alignment for PageViewer selection accuracy#610
hoyla wants to merge 4 commits intomainfrom
ljh-pageviewer-ux-3

Conversation

@hoyla
Copy link
Copy Markdown
Contributor

@hoyla hoyla commented Mar 13, 2026

This is an attempt to address the way text selection in the PageViewer is often misaligned vertically. A little robot tells me that the browser was adding default padding vertically, affecting selection. This removes that.

This doesn't fix the much more serious problem of text selection and highlighting being misaligned in terms of character counts down the page. But it does at least get the user onto the right line.

Add line-height: 1 and white-space: pre to .pfi-page__pdf-text to prevent browser defaults from distorting the invisible text overlay geometry.

  • The default line-height (~1.2) added extra vertical space above/below each text div, causing the selectable area to be taller than the actual glyph; and on pages with lots of lines eventually shifts the selection and highlight to below the text.
  • white-space: pre prevents the browser from collapsing whitespace or wrapping text, keeping positions aligned with where PDF.js placed them. Allegedly.

Before:

Picture 65

To select "workspaces section" the user actually has to drag the cursor across what appears to be the line below to get the selection right. The highlight itself is also too tall, although this actually helps since it overlaps the text, unlike the required cursor action.

After:

Picture 66

Cursor drag (and the highlight itself) aligns more accurately to the displayed text.

Testing:

  • Looks good on local dev but..
  • Probably needs some quite thorough testing with different documents on playground

@hoyla hoyla added document viewer ux/ui fix Departmental tracking: fix labels Mar 13, 2026
@hoyla hoyla self-assigned this Mar 14, 2026
@hoyla hoyla force-pushed the ljh-pageviewer-ux-3 branch from 0270c65 to 3a53c7f Compare March 19, 2026 09:54
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2026

@hoyla hoyla changed the title Improve text overlay alignment for PageViewer selection accuracy Document view #5: Improve text overlay alignment for PageViewer selection accuracy Mar 23, 2026
@hoyla hoyla force-pushed the ljh-pageviewer-ux-3 branch from e47d25b to fa1e491 Compare March 27, 2026 14:47
hoyla added 4 commits April 1, 2026 12:43
Add line-height: 1 and white-space: pre to .pfi-page__pdf-text to
prevent browser defaults from distorting the invisible text overlay
geometry. The default line-height (~1.2) adds extra vertical space
above/below each text div, causing the selectable area to be taller
than the actual glyph. white-space: pre prevents the browser from
collapsing whitespace or wrapping text, keeping positions aligned
with where PDF.js placed them.
When a highlight has multiple spans (e.g. multi-line highlights), each
span was receiving the same id and key. Duplicate DOM ids are invalid
HTML and duplicate React keys defeat reconciliation. Append the span
index to make both unique.
The opacity property is not supported in ::selection pseudo-elements
and was silently ignored by all browsers. Remove it along with the
now-unnecessary comment explaining the workaround.
textContent is the correct API for extracting plain text from DOM
elements. innerHTML could return markup if PDF.js ever added internal
elements to the text divs, while textContent always returns the raw
text content.
@hoyla hoyla force-pushed the ljh-pageviewer-ux-3 branch from fa1e491 to 58817f1 Compare April 1, 2026 11:43
@hoyla hoyla changed the title Document view #5: Improve text overlay alignment for PageViewer selection accuracy [hold] Document view #5: Improve text overlay alignment for PageViewer selection accuracy Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

document viewer fix Departmental tracking: fix ux/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant