Skip to content

Commit ad11d97

Browse files
committed
fix(web): Cite button stays anchored to the selected text
1 parent 5dcb59e commit ad11d97

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎apps/web/src/components/chat/AssistantSelectionToolbar.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ export function AssistantSelectionToolbar({
6161
return;
6262
}
6363
const rects = captured.range.getClientRects();
64+
const pointerOnText =
65+
pointer !== null &&
66+
Array.from(rects).some(
67+
(line) =>
68+
pointer.x >= line.left - 8 &&
69+
pointer.x <= line.right + 8 &&
70+
pointer.y >= line.top - 8 &&
71+
pointer.y <= line.bottom + 8,
72+
);
6473
setSelection({
6574
sourceAnchor: { source: captured.source, range: captured.range, viewport },
6675
citation: {
@@ -72,7 +81,7 @@ export function AssistantSelectionToolbar({
7281
position: resolveSelectionActionPosition({
7382
bounds: viewportRect,
7483
selectionRect: rects.item(rects.length - 1) ?? rect,
75-
pointer,
84+
pointer: pointerOnText ? pointer : null,
7685
viewport: { width: window.innerWidth, height: window.innerHeight },
7786
}),
7887
});

0 commit comments

Comments
 (0)