The best way to control Claude Code, Codex and more from any computer or phone
fix(web): reopened composer drafts keep quote spacing and show the caret (#31880)
Julius Marminge committed
Nov 14, 2026 at 18:49 UTC
ed6cb97f07df59c01467b919073550d310da3ef4
4 files changed
+55
-1
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+17
@@ -532,6 +532,23 @@ async function focusAt(editor: Editor, position: number | "end") {
532
vi.runOnlyPendingTimers();
533
}
534
535
+it("reopens a long draft scrolled to its caret without taking focus", async () => {
536
+ // App CSS is not loaded here; give the editor its own scroll box.
537
+ const style = document.head.appendChild(document.createElement("style"));
538
+ // The bottom padding stands in for space reserved under overlaid controls.
539
+ style.textContent =
540
+ ".composer-tiptap { max-height: 120px; overflow-y: auto; padding-bottom: 48px; }";
541
+ using _style = { [Symbol.dispose]: () => style.remove() };
542
+ const value = Array.from({ length: 40 }, (_, line) => `line ${line + 1}`).join("\n");
543
+ await using screen = await mountEditor(value);
544
+ const { editor } = screen;
545
+ const scroller = editor.view.dom;
546
+ await vi.waitFor(() => expect(scroller.scrollTop).toBeGreaterThan(0));
547
+ expect(document.activeElement).not.toBe(scroller);
548
+ const caret = editor.view.coordsAtPos(editor.state.selection.head);
549
+ expect(caret.bottom).toBeLessThanOrEqual(scroller.getBoundingClientRect().bottom - 48 + 1);
550
+});
551
+
552
describe("Markdown markers around styled text", () => {
553
it.each([
554
{ keys: "{Backspace}", expected: "**** after" },
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+19
@@ -1631,6 +1631,12 @@ function ComposerPromptEditorTiptapInner(
1631
selectMarkdownOffset(editor, normalizedExpandedCursor);
1632
const map = serializeEditorDoc(editor.state.doc);
1633
if (isFocused) scrollTiptapCaretIntoView(editor);
1634
+ // A redraw later in this commit drops the editor's scroll offset, so reveal on the next frame.
1635
+ else if (initialSelection) {
1636
+ window.requestAnimationFrame(() => {
1637
+ if (!editor.isDestroyed) revealCaretInEditor(editor);
1638
+ });
1639
+ }
1640
if (pendingCitation) {
1641
citationRequestRef.current = null;
1642
const target = map.runs.find(
@@ -1944,6 +1950,19 @@ function scrollTiptapCaretIntoView(editor: TiptapEditor): void {
1950
editor.view.dispatch(editor.state.tr.scrollIntoView());
1951
}
1952
1953
+/** Scrolls only the editor's own box: a mounting composer must not move the timeline or page. */
1954
+function revealCaretInEditor(editor: TiptapEditor): void {
1955
+ const scroller = editor.view.dom;
1956
+ const caret = editor.view.coordsAtPos(editor.state.selection.head);
1957
+ const box = scroller.getBoundingClientRect();
1958
+ // Padding can be reserved for controls drawn over the box, such as mobile pending-answer actions.
1959
+ const style = getComputedStyle(scroller);
1960
+ const bottom = box.bottom - parseFloat(style.paddingBottom);
1961
+ const top = box.top + parseFloat(style.paddingTop);
1962
+ if (caret.bottom > bottom) scroller.scrollTop += caret.bottom - bottom;
1963
+ else if (caret.top < top) scroller.scrollTop -= top - caret.top;
1964
+}
1965
+
1966
function caretLineRect(range: Range, edge: "start" | "end"): DOMRect | null {
1967
const collapsedRects = Array.from(range.getClientRects()).filter((rect) => rect.height > 0);
1968
const collapsedRect = edge === "start" ? collapsedRects.at(-1) : collapsedRects[0];
apps/web/src/composer-rich-text-doc.test.ts
+9
@@ -570,6 +570,15 @@ describe("composer rich text document model", () => {
570
);
571
});
572
573
+ it("reopens without an empty line between the quote and the comment", () => {
574
+ const { doc, map } = serialize(quote("quoted"), paragraph("Comment to it"));
575
+ const reopened = ProseMirrorNode.fromJSON(
576
+ schema,
577
+ buildDocJson(map.value, (name) => ({ label: name, description: null })),
578
+ );
579
+ expect(reopened.toJSON()).toEqual(doc.toJSON());
580
+ });
581
+
582
it("settles on the blank line when a draft glued it to the quote", () => {
583
const settled = "before\n> quoted\n\nafter";
584
expect(roundTrip("before\n> quoted\nafter").value).toBe(settled);
apps/web/src/composer-rich-text-doc.ts
+10
-1
@@ -1077,7 +1077,12 @@ export function buildTiptapContent(
1077
});
1078
openQuote = null;
1079
};
1080
- for (const entry of entries) {
1080
+ const isProseLine = (entry: (typeof entries)[number] | undefined, empty: boolean) =>
1081
+ entry !== undefined &&
1082
+ "line" in entry &&
1083
+ !entry.line.list &&
1084
+ (entry.line.inline.length === 0) === empty;
1085
+ for (const [entryIndex, entry] of entries.entries()) {
1086
if ("quote" in entry) {
1087
flushLists();
1088
if (openQuote && openQuote.prefix !== entry.quote.prefix) flushQuote();
@@ -1085,7 +1090,11 @@ export function buildTiptapContent(
1090
openQuote.content.push(entry.quote.inline);
1091
continue;
1092
}
1093
+ // The serializer separates a quote from the prose after it with one blank line; it is not an empty paragraph.
1094
+ const quoteSeparator =
1095
+ openQuote !== null && isProseLine(entry, true) && isProseLine(entries[entryIndex + 1], false);
1096
flushQuote();
1097
+ if (quoteSeparator) continue;
1098
if ("code" in entry) {
1099
flushLists();
1100
blocks.push(entry.code);