@devries-cameron20 / t3code Mirror · read-only / commits / 2d377bfb1c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 23:00 UTC

fix(web): dismiss selection actions when pressing buttons (#12950)

Yash Singh committed Sep 21, 2026 at 17:11 UTC 2d377bfb1c8c85a61679fa6cdb6e8181cfb13626
2 files changed +37 -2
apps/web/src/lib/selectionActions.test.ts
+33 -2
@@ -24,7 +24,12 @@ function createSelectionSurface({ interactiveActions = false } = {}) {
24 });
25 const element = Object.assign(new EventTarget(), {
26 ownerDocument: document,
27 - contains: (target: unknown): boolean => target === element,
27 + contains: (target: unknown): boolean => target === element || target === buttonIcon,
28 + closest: () => null,
29 + });
30 + const button = new EventTarget();
31 + const buttonIcon = Object.assign(new EventTarget(), {
32 + closest: (selector: string) => (selector === "button, [role=button]" ? button : null),
33 });
34 const onSelection = vi.fn();
35 const onDismiss = vi.fn();
@@ -58,7 +63,7 @@ function createSelectionSurface({ interactiveActions = false } = {}) {
63 const press = event("pointerdown", { button, isPrimary });
64 Object.defineProperty(press, "target", { value: target });
65 document.dispatchEvent(press);
61 - if (target === element && !consumed) element.dispatchEvent(press);
66 + if (element.contains(target) && !consumed) element.dispatchEvent(press);
67 };
68 const focus = (target: EventTarget) => {
69 document.activeElement = target;
@@ -92,6 +97,7 @@ function createSelectionSurface({ interactiveActions = false } = {}) {
97 view,
98 document,
99 element,
100 + buttonIcon,
101 actionElement,
102 field,
103 onSelection,
@@ -177,6 +183,31 @@ describe("selection action gestures", () => {
183 expect(surface.onSelection).not.toHaveBeenCalled();
184 });
185
186 + it.each([1, 2])(
187 + "dismisses selection actions when a button is pressed after %i clicks",
188 + (detail) => {
189 + const surface = createSelectionSurface();
190 + surface.down();
191 + surface.up({ detail });
192 + surface.flush();
193 + surface.onSelection.mockClear();
194 + surface.onDismiss.mockClear();
195 +
196 + surface.down({ target: surface.buttonIcon });
197 + surface.up();
198 + surface.change();
199 + surface.flush(1000);
200 + expect(surface.onDismiss).toHaveBeenCalledWith("interaction");
201 + expect(surface.onSelection).not.toHaveBeenCalled();
202 +
203 + surface.down();
204 + surface.change();
205 + surface.up();
206 + surface.flush();
207 + expect(surface.onSelection).toHaveBeenCalledOnce();
208 + },
209 + );
210 +
211 it("ignores nonprimary pointers and non-left mouseup without ending a left drag", () => {
212 const surface = createSelectionSurface();
213 surface.down({ isPrimary: false });
apps/web/src/lib/selectionActions.ts
+4
@@ -101,6 +101,10 @@ export function observeSelectionActions({
101 };
102 const onSelectionStart = (event: PointerEvent) => {
103 if (!event.isPrimary) return;
104 + const target = event.target as Element | null;
105 + // Buttons can preserve an existing text selection while opening a menu.
106 + // Their release must not reopen selection actions beside the button.
107 + if (target?.closest("button, [role=button]")) return;
108 // A surface may consume a press for a link or terminal mouse reporting.
109 gestureActive = event.button === 0 && !event.defaultPrevented;
110 dismissed = !gestureActive;