Mode2UpLit: skip page-flip when a text selection is active#1540
Open
Mode2UpLit: skip page-flip when a text selection is active#1540
Conversation
Mode2UpLit.handlePageClick is bound to mouseup on the 2up book container and unconditionally flips the page when the mouseup target is inside a .BRpagecontainer. Because mouseup also fires at the end of a text-selection drag, releasing the mouse after selecting text triggers the page-flip and clobbers the selection. The text_selection plugin tries to prevent this by attaching its own mouseup handler on the text layer that calls stopPropagation, but only when the mouseup lands on a BRwordElement or BRspace. If the drag ends on blank space between words or on the page margin, the plugin's handler doesn't fire and the flip still runs. Check `window.getSelection().toString().trim()` at the top of handlePageClick and bail if it has content. Safe in all browsers — the getSelection API is universally supported and reports the currently active selection synchronously on mouseup.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1540 +/- ##
==========================================
- Coverage 68.98% 68.97% -0.02%
==========================================
Files 65 65
Lines 5556 5557 +1
Branches 1229 1230 +1
==========================================
Hits 3833 3833
- Misses 1689 1690 +1
Partials 34 34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mode2UpLit.handlePageClickunconditionally flips the page on any left-clickmouseupinside a.BRpagecontainer. When a user drags across text to select it, releasing the mouse at the end of the selection firesmouseupand triggers the page-flip, clobbering the selection.Reproduction
archive.org/details/goody)..BRwordElementor.BRspace— e.g. on blank space between words or on the page margin.Why the text_selection plugin doesn't catch it
The text_selection plugin attaches a
mouseup.textSelectPluginHandlerto the text layer that callsevent.stopPropagation(), which works — but only when themouseuptarget is inside the text layer. If the drag ends on blank space or the page image, the plugin's handler doesn't fire and the event bubbles up to.br-mode-2up__book's@mouseup=${handlePageClick}.Fix
Check
window.getSelection().toString().trim()at the top ofhandlePageClickand bail if it has content. A single early-return — no new event listeners, no timing dependencies.Verification
Offshoot works around this in https://git.archive.org/www/offshoot/-/merge_requests/1049 by attaching a capture-phase
mouseuplistener on the BookReader root container that callsstopPropagationwhen a selection is active. Upstream-fixing it here lets offshoot drop that workaround entirely.Manually verified on offshoot's review app: selection now survives the mouseup in every case — on-word, between-word, on-margin, crossing-page-boundary.
Risk
Low. The check fires only when there's an actual non-whitespace selection, which is unambiguously a selection-drag. No effect on tap-to-flip behavior (tap has no selection at mouseup time).