@devries-cameron20 / t3code Mirror · read-only / commits / d02e292610
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, 15:30 UTC

fix(web): cite works on responses that end before a tool call (#17713)

maria committed Oct 10, 2026 at 01:23 UTC d02e292610ea5eff171d388211ba3ede2f0467a0
2 files changed +32 -1
apps/web/src/lib/assistantTextSelection.test.ts
+23
@@ -56,6 +56,13 @@ class SelectionNode {
56 get nodeType() {
57 return this.tagName === "#text" ? 3 : 1;
58 }
59 + get ownerDocument() {
60 + // `user-select: none` inherits, like Chromium's computed style.
61 + const getComputedStyle = (element: SelectionNode) => ({
62 + userSelect: element.closest("[data-select-none]") ? "none" : "auto",
63 + });
64 + return { defaultView: { getComputedStyle } };
65 + }
66 get length() {
67 return this.data.length;
68 }
@@ -259,6 +266,22 @@ describe("captureAssistantTextSelection", () => {
266 expect(capture(source, nativeSelection([quote, 0], [timestampText, 1]))).toBeNull();
267 });
268
269 + it("captures a triple-clicked response that ends before a tool row and the next response", () => {
270 + const quote = textNode("Recording your answers in the session note:");
271 + const source = assistantSource(new SelectionNode("P").append(quote));
272 + const nextParagraph = new SelectionNode("P").append(textNode("1. What it means."));
273 + const viewport = new SelectionNode("MAIN").append(
274 + source,
275 + new SelectionNode("DIV", "", { "data-select-none": "" }).append(textNode("echo ok")),
276 + new SelectionNode("H3", "", { "data-select-none": "" }).append(textNode("T3 Code")),
277 + assistantSource(nextParagraph),
278 + );
279 +
280 + expect(capture(viewport, nativeSelection([quote, 0], [nextParagraph, 0]))?.selector).toEqual(
281 + selector(quote.data),
282 + );
283 + });
284 +
285 it("does not attribute an empty starting endpoint to the previous response", () => {
286 const previous = textNode("Previous response.");
287 const quote = textNode("Selected response.");
apps/web/src/lib/assistantTextSelection.ts
+9 -1
@@ -189,13 +189,21 @@ function isUsableRange(root: HTMLElement, range: Range): boolean {
189 return true;
190 }
191
192 +function isUnselectable(text: Text): boolean {
193 + const element = text.parentElement;
194 + const view = element?.ownerDocument?.defaultView;
195 + return !!element && !!view && view.getComputedStyle(element).userSelect === "none";
196 +}
197 +
198 function selectedTextBoundary(range: Range, node: Node, last: boolean): Text | null {
199 if (!range.intersectsNode(node)) return null;
200 if (node.nodeType === 3) {
201 const text = node as Text;
202 const start = node === range.startContainer ? range.startOffset : 0;
203 const end = node === range.endContainer ? range.endOffset : text.length;
198 - return start < end ? text : null;
204 + // Triple-click ranges run through unselectable rows (tool calls, timestamps,
205 + // author headings) into the next response; that text is not selected.
206 + return start < end && !isUnselectable(text) ? text : null;
207 }
208 for (
209 let child = last ? node.lastChild : node.firstChild;