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

fix(web): keep macOS Command-arrow navigation at editor boundaries (#22011)

Yash Singh committed Oct 19, 2026 at 18:39 UTC e8d87689b8b885a03aedc0d1ce7f6e3dfb500cf1
2 files changed +132 -27
apps/web/src/components/ComposerPromptEditorTiptap.navigation.browser.test.tsx
+105 -13
@@ -2,7 +2,7 @@ import type { Editor } from "@tiptap/core";
2 import { TextSelection } from "@tiptap/pm/state";
3 import { act, createRef } from "react";
4 import { createRoot, type Root } from "react-dom/client";
5 -import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
5 +import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
6
7 import { serializeEditorDoc } from "~/composer-rich-text-doc";
8 import { ComposerPromptEditor, type ComposerPromptEditorHandle } from "./ComposerPromptEditor";
@@ -23,6 +23,7 @@ beforeEach(() => {
23 afterEach(async () => {
24 await act(async () => root.unmount());
25 container.remove();
26 + vi.restoreAllMocks();
27 vi.unstubAllGlobals();
28 });
29
@@ -97,19 +98,110 @@ it("leaves vertical navigation between paragraphs to the browser", async () => {
98 });
99 });
100
100 -it.each([
101 - { shiftKey: true },
102 - { altKey: true },
103 - { metaKey: true },
104 - { ctrlKey: true },
105 - { isComposing: true },
106 -])("preserves modified Up behavior for %j", async (options) => {
107 - const editor = await mountEditor(draft);
108 - await act(async () => {
109 - expect(press(editor, "ArrowUp", options)).toBe(false);
110 - editor.commands.insertContent("x");
101 +it.each([{ shiftKey: true }, { altKey: true }, { ctrlKey: true }, { isComposing: true }])(
102 + "preserves modified Up behavior for %j",
103 + async (options) => {
104 + const editor = await mountEditor(draft);
105 + await act(async () => {
106 + expect(press(editor, "ArrowUp", options)).toBe(false);
107 + editor.commands.insertContent("x");
108 + });
109 + expect(serializeEditorDoc(editor.state.doc).value).toBe(draft.replace("> **", "> **x"));
110 + },
111 +);
112 +
113 +describe("macOS boundary navigation", () => {
114 + beforeEach(() => {
115 + vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
116 + container.style.width = "600px";
117 + });
118 +
119 + const markdown = String.raw`Fixed the top padding to 16px and updated the offline index and ZIP.
120 +
121 +**Yes: [HW08, problem 6, page 2](/Users/yashsingh/.t3/scratch/2026-10-16-gather-all-info-about-the-2fcd52f5/calculus-resources/files/HW08.pdf)** asks for the absolute maximum and minimum of
122 +\[
123 +f(x,y)=2x^2+y^2,\qquad x^2+y^2\le16.
124 +\]
125 +That's exactly a disk with the circular boundary \(x^2+y^2=16\), and it is within section 14.7.
126 +
127 +The original Fall 2022, 2023, and 2024 sample exams also have circle-constrained extrema problems, all question 6. Those explicitly require Lagrange multipliers, so they were removed from your filtered copies. **HW08 #6 is the best match for your exam.**`;
128 +
129 + it.each(["ArrowRight", "ArrowDown"])(
130 + "keeps Command-%s after the closing marker in the pasted draft",
131 + async (key) => {
132 + const editor = await mountEditor(markdown);
133 + await act(async () => {
134 + editor.view.dispatch(editor.state.tr.setSelection(TextSelection.atEnd(editor.state.doc)));
135 + editor.view.focus();
136 + expect(press(editor, "ArrowRight")).toBe(true);
137 + expect(press(editor, key, { metaKey: true })).toBe(true);
138 + expect(editor.state.selection.eq(TextSelection.atEnd(editor.state.doc))).toBe(true);
139 + // Force the DOM selection rewrite that used to pull the caret back.
140 + editor.view.updateState(editor.state);
141 + const markers = editor.view.dom.querySelectorAll(".composer-rich-marker");
142 + const closingMarker = markers[markers.length - 1];
143 + const caret = window.getSelection()?.getRangeAt(0);
144 + if (!closingMarker || !caret) throw new Error("Caret or closing marker is missing");
145 + const markerRange = document.createRange();
146 + markerRange.selectNode(closingMarker);
147 + expect(caret.compareBoundaryPoints(Range.START_TO_END, markerRange)).toBeGreaterThanOrEqual(
148 + 0,
149 + );
150 + editor.commands.insertContent("x");
151 + });
152 + expect(serializeEditorDoc(editor.state.doc).value).toBe(markdown + "x");
153 + },
154 + );
155 +
156 + it.each(["ArrowRight", "ArrowDown"])(
157 + "moves Command-%s from inside bold to outside its closing marker",
158 + async (key) => {
159 + const editor = await mountEditor("**bold**");
160 + await act(async () => {
161 + editor.commands.setTextSelection(3);
162 + editor.view.focus();
163 + expect(press(editor, key, { metaKey: true })).toBe(true);
164 + editor.commands.insertContent("x");
165 + });
166 + expect(serializeEditorDoc(editor.state.doc).value).toBe("**bold**x");
167 + },
168 + );
169 +
170 + it.each(["ArrowLeft", "ArrowUp"])("moves Command-%s before the opening marker", async (key) => {
171 + const editor = await mountEditor("**bold**");
172 + await act(async () => {
173 + editor.commands.setTextSelection(3);
174 + editor.view.focus();
175 + expect(press(editor, key, { metaKey: true })).toBe(true);
176 + editor.commands.insertContent("x");
177 + });
178 + expect(serializeEditorDoc(editor.state.doc).value).toBe("x**bold**");
179 + });
180 +
181 + it.each(["ArrowRight", "ArrowDown"])(
182 + "extends Shift-Command-%s to the end without collapsing the selection",
183 + async (key) => {
184 + const editor = await mountEditor("**bold**");
185 + await act(async () => {
186 + editor.commands.setTextSelection(3);
187 + editor.view.focus();
188 + expect(press(editor, key, { metaKey: true, shiftKey: true })).toBe(true);
189 + expect(editor.state.selection.anchor).toBe(3);
190 + expect(editor.state.selection.head).toBe(TextSelection.atEnd(editor.state.doc).to);
191 + editor.commands.insertContent("x");
192 + });
193 + expect(serializeEditorDoc(editor.state.doc).value).toBe("**box**");
194 + },
195 + );
196 +
197 + it("leaves Command-arrow navigation to the browser on other platforms", async () => {
198 + vi.spyOn(navigator, "platform", "get").mockReturnValue("Linux x86_64");
199 + const editor = await mountEditor("**bold**");
200 + await act(async () => {
201 + editor.view.focus();
202 + expect(press(editor, "ArrowDown", { metaKey: true })).toBe(false);
203 + });
204 });
112 - expect(serializeEditorDoc(editor.state.doc).value).toBe(draft.replace("> **", "> **x"));
205 });
206
207 it("leaves literal Markdown navigation to the browser in plain mode", async () => {
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+27 -14
@@ -1106,11 +1106,19 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
1106 editorProps: {
1107 attributes: editorAttributes,
1108 handleKeyDown: (view, event) => {
1109 + const boundary = event.metaKey
1110 + ? event.key === "ArrowLeft" || event.key === "ArrowRight"
1111 + ? "lineboundary"
1112 + : event.key === "ArrowUp" || event.key === "ArrowDown"
1113 + ? "documentboundary"
1114 + : null
1115 + : event.key === "Home" || event.key === "End"
1116 + ? "lineboundary"
1117 + : null;
1118 if (
1119 isMacPlatform(navigator.platform) &&
1111 - (event.key === "Home" || event.key === "End") &&
1120 + boundary &&
1121 !event.altKey &&
1113 - !event.metaKey &&
1122 !event.ctrlKey &&
1123 !event.isComposing
1124 ) {
@@ -1122,23 +1130,28 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
1130 ) {
1131 event.preventDefault();
1132 event.stopPropagation();
1133 + const backward =
1134 + event.key === "Home" || event.key === "ArrowLeft" || event.key === "ArrowUp";
1135 selection.modify(
1136 event.shiftKey ? "extend" : "move",
1127 - event.key === "Home" ? "backward" : "forward",
1128 - "lineboundary",
1137 + backward ? "backward" : "forward",
1138 + boundary,
1139 );
1140 if (selection.anchorNode && selection.focusNode) {
1131 - view.dispatch(
1132 - view.state.tr
1133 - .setSelection(
1134 - TextSelection.create(
1135 - view.state.doc,
1136 - view.posAtDOM(selection.anchorNode, selection.anchorOffset),
1137 - view.posAtDOM(selection.focusNode, selection.focusOffset),
1138 - ),
1139 - )
1140 - .scrollIntoView(),
1141 + const tr = view.state.tr.setSelection(
1142 + TextSelection.create(
1143 + view.state.doc,
1144 + view.posAtDOM(selection.anchorNode, selection.anchorOffset),
1145 + view.posAtDOM(selection.focusNode, selection.focusOffset),
1146 + ),
1147 );
1148 + // A marker has two caret stops at one document position. Keep
1149 + // the outer stop when native navigation reaches a boundary.
1150 + if (richText && tr.selection.empty) {
1151 + const { $head } = tr.selection;
1152 + tr.setStoredMarks((backward ? $head.nodeBefore : $head.nodeAfter)?.marks ?? []);
1153 + }
1154 + view.dispatch(tr.scrollIntoView());
1155 }
1156 return true;
1157 }