Skip to content

Commit 2a40aa0

Browse files
committed
fix(web): citation markers sit in the gutter instead of covering text
Co-Authored-By: GPT-6.1 Sol via T3 Code
1 parent e4a8754 commit 2a40aa0

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎apps/web/src/components/chat/AssistantCitationMarkers.browser.test.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ it("keeps source observations across typing and releases virtualized sources", a
1313
mocks.findAnchor.mockReset();
1414
const viewport = document.createElement("div");
1515
const source = document.createElement("p");
16-
source.textContent = "hello";
16+
viewport.style.cssText = "position: fixed; left: 0; top: 0; width: 400px; height: 100px";
17+
source.style.width = "200px";
18+
source.textContent = "hello again";
1719
viewport.append(source);
1820
document.body.append(viewport);
1921
using _fixture = { [Symbol.dispose]: () => viewport.remove() };
2022
mocks.findAnchor.mockImplementation(() => {
2123
if (!viewport.contains(source)) return null;
2224
const range = document.createRange();
23-
range.selectNodeContents(source);
25+
range.setStart(source.firstChild!, 0);
26+
range.setEnd(source.firstChild!, 5);
2427
return { source, range };
2528
});
2629
const prompt = serializeAssistantCitation({
@@ -50,6 +53,9 @@ it("keeps source observations across typing and releases virtualized sources", a
5053
expect(markers[0]!.style.left).not.toBe("");
5154
expect(markers[0]!.style.left).not.toBe(markers[1]!.style.left);
5255
expect(markers[0]!.style.top).toBe(markers[1]!.style.top);
56+
expect(
57+
Number.parseFloat(markers[0]!.style.left) + viewport.getBoundingClientRect().left,
58+
).toBeGreaterThanOrEqual(source.getBoundingClientRect().right);
5359
});
5460
using disconnect = vi.spyOn(MutationObserver.prototype, "disconnect");
5561
const searches = mocks.findAnchor.mock.calls.length;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ function CitationMarkers({
7373
rect.left < bounds.right,
7474
);
7575
button.hidden = !rect;
76-
if (rect) {
77-
const rectKey = `${rect.right}:${rect.bottom}`;
76+
if (rect && anchor) {
77+
const sourceRight = anchor.source.getBoundingClientRect().right;
78+
const rectKey = `${sourceRight}:${rect.bottom}`;
7879
const occurrence = occurrences.get(rectKey) ?? 0;
7980
occurrences.set(rectKey, occurrence + 1);
8081
const base = Math.min(
8182
Math.max(0, bounds.width - 20),
82-
Math.max(0, rect.right - bounds.left + 3),
83+
Math.max(0, sourceRight - bounds.left + 3),
8384
);
8485
const offset = occurrence * 22;
8586
const left =

0 commit comments

Comments
 (0)