-
Notifications
You must be signed in to change notification settings - Fork 0
Fix mobile selection toolbar #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -569,9 +569,13 @@ export const OVERLAY_SCRIPT = String.raw` | |
| var exact = (e > s) ? tm.full.slice(s, e) : sel.toString(); | ||
| return { exact: exact, prefix: tm.full.slice(Math.max(0, s-32), s), suffix: tm.full.slice(e, e+32) }; | ||
| } | ||
| document.addEventListener("mouseup", function(ev){ | ||
| if (ev.target && ev.target.closest && (ev.target.closest("[data-jh-chip]") || ev.target.closest(".jh-pop"))) return; | ||
| setTimeout(function(){ | ||
| var selectionTimer = null; | ||
| function fromOverlayChrome(ev){ | ||
| var t = ev && ev.target; | ||
| return !!(t && t.closest && (t.closest("[data-jh-chip]") || t.closest(".jh-pop"))); | ||
| } | ||
| function reportSelection(){ | ||
| try { | ||
| var sel = window.getSelection(); | ||
| if (!sel || !sel.rangeCount || sel.isCollapsed || !sel.toString().trim()){ send({type:"jh:selectionCleared"}); return; } | ||
| var anchor = anchorFromSelection(sel); | ||
|
|
@@ -580,7 +584,35 @@ export const OVERLAY_SCRIPT = String.raw` | |
| top: rect.top + window.scrollY, left: rect.left, right: rect.right, bottom: rect.bottom + window.scrollY, | ||
| viewTop: rect.top | ||
| }}); | ||
| }, 10); | ||
| } catch(e) { | ||
| send({type:"jh:selectionCleared"}); | ||
| } | ||
| } | ||
| function queueSelectionReport(delay){ | ||
| if (selectionTimer) clearTimeout(selectionTimer); | ||
| selectionTimer = setTimeout(function(){ | ||
| selectionTimer = null; | ||
| reportSelection(); | ||
| }, delay); | ||
| } | ||
| document.addEventListener("mouseup", function(ev){ | ||
| if (fromOverlayChrome(ev)) return; | ||
| queueSelectionReport(10); | ||
| }); | ||
| document.addEventListener("keyup", function(ev){ | ||
| if (fromOverlayChrome(ev)) return; | ||
| queueSelectionReport(10); | ||
| }); | ||
| document.addEventListener("touchend", function(ev){ | ||
| if (fromOverlayChrome(ev)) return; | ||
| queueSelectionReport(80); | ||
| }, {passive:true}); | ||
| document.addEventListener("pointerup", function(ev){ | ||
| if (fromOverlayChrome(ev)) return; | ||
| queueSelectionReport(30); | ||
| }); | ||
| document.addEventListener("selectionchange", function(){ | ||
| queueSelectionReport(120); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Selectionchange ignores overlay chromeMedium Severity The new Additional Locations (1)Reviewed by Cursor Bugbot for commit b511f84. Configure here. |
||
| }); | ||
|
|
||
| window.addEventListener("message", function(ev){ | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shared timer drops intended delays
High Severity
The
queueSelectionReportfunction's single shared timer means events with shorter delays can prematurely cancel and override pending selection reports from events with longer delays. This can cause selection to be read too early, particularly on touch devices where events are synthesized, leading tojh:selectionClearedor a stale selection rect before the selection fully settles.Reviewed by Cursor Bugbot for commit b511f84. Configure here.