Repository navigation
fix(web): Cite shows for text selected by touch #81
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
Merged
+102
−5
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
| import { fakeTimers } from "../../test/render"; | ||
| import { observeSelectionActions } from "./selectionActions"; | ||
|
|
||
| describe("observeSelectionActions", () => { | ||
| it("reports a touch long-press selection that cancels the pointer", async () => { | ||
| const element = document.createElement("div"); | ||
| element.textContent = "Select this text on a phone"; | ||
| document.body.append(element); | ||
| const onSelection = vi.fn(); | ||
| const actions = observeSelectionActions({ element, onSelection, onDismiss: vi.fn() }); | ||
| document.addEventListener("selectionchange", actions.selectionChanged); | ||
| using _cleanup = { | ||
| [Symbol.dispose]: () => { | ||
| document.removeEventListener("selectionchange", actions.selectionChanged); | ||
| actions.dispose(); | ||
| element.remove(); | ||
| }, | ||
| }; | ||
|
|
||
| const touch = { bubbles: true, isPrimary: true, pointerType: "touch", button: 0 }; | ||
| element.dispatchEvent(new PointerEvent("pointerdown", touch)); | ||
| element.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true })); | ||
| window.dispatchEvent(new PointerEvent("pointercancel", touch)); | ||
| window.getSelection()!.selectAllChildren(element); | ||
|
|
||
| await vi.waitFor(() => expect(onSelection).toHaveBeenCalledWith(null)); | ||
| }); | ||
|
|
||
| it("keeps a dismissed touch selection hidden when the viewport scrolls", () => { | ||
| const element = document.createElement("div"); | ||
| element.textContent = "Select this text on a phone"; | ||
| document.body.append(element); | ||
| const onSelection = vi.fn(); | ||
| const actions = observeSelectionActions({ | ||
| element, | ||
| restoreAfterScroll: true, | ||
| onSelection, | ||
| onDismiss: vi.fn(), | ||
| }); | ||
| using _timers = fakeTimers(); | ||
| using _cleanup = { | ||
| [Symbol.dispose]: () => { | ||
| actions.dispose(); | ||
| element.remove(); | ||
| }, | ||
| }; | ||
|
|
||
| const touch = { bubbles: true, isPrimary: true, pointerType: "touch", button: 0 }; | ||
| element.dispatchEvent(new PointerEvent("pointerdown", touch)); | ||
| window.dispatchEvent(new PointerEvent("pointercancel", touch)); | ||
| actions.selectionChanged(); | ||
| vi.advanceTimersByTime(1_000); | ||
| expect(onSelection).toHaveBeenCalledTimes(1); | ||
|
|
||
| document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" })); | ||
| element.dispatchEvent(new Event("scroll")); | ||
| actions.selectionChanged(); | ||
| vi.advanceTimersByTime(1_000); | ||
| expect(onSelection).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # ADR 0026: Show Cite for touch text selections | ||
|
|
||
| - Status: accepted | ||
| - Date: 2026-10-26 | ||
| - Compared with upstream: `pingdotgg/t3code` at `6ffde5ba3` (2026-10-26) | ||
|
|
||
| Selecting assistant text in a mobile browser (seen on Chrome for Android) never | ||
| showed the **Cite** button. A touch selection starts with a long-press. That | ||
| long-press fires `contextmenu` and `pointercancel`, and both dismissed the | ||
| selection action. The handles that adjust the selection afterwards fire no | ||
| pointer events, so the `mouseup` that shows the action on desktop never came. | ||
|
|
||
| [`observeSelectionActions`](../../apps/web/src/lib/selectionActions.ts) now | ||
| remembers whether the last primary pointer was touch. For touch it ignores | ||
| `contextmenu`, does not dismiss on `pointercancel`, and shows the action once | ||
| `selectionchange` or scrolling has settled for 150 ms. An explicit dismissal, | ||
| such as Escape, still holds until the next press. Mouse and pen behaviour is | ||
| unchanged. | ||
|
|
||
| When updating from upstream, keep the touch path if upstream's observer still | ||
| waits for `mouseup`. Remove this if upstream handles touch selections itself. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.