@devries-cameron20 / t3code Mirror · read-only / commits / 8003dd8c7b
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 22, 09:30 UTC

fix(web): Shift+Tab moves a nested composer list item back out (#27016)

Co-authored-by: tsmith165 <16846767+tsmith165@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>

tsmith165 committed Oct 31, 2026 at 01:45 UTC 8003dd8c7bfa3b23ad55800d88a8b82c9340ecd7
4 files changed +92 -23
apps/web/src/components/chat/composerCommandKey.ts
+28 -22
@@ -20,7 +20,12 @@ import { type PendingUserInput } from "../../session-logic";
20 import { type PreviewAnnotationPayload } from "@t3tools/contracts";
21 import { type ReviewCommentContext } from "../../reviewCommentContext";
22 import { composerTargetKey } from "../../composerDraftStore";
23 -import { listContinuationForEnter, listIndentForTab } from "../../composer-list-continuation";
23 +import {
24 + type ComposerListEdit,
25 + listContinuationForEnter,
26 + listIndentForTab,
27 + listOutdentForTab,
28 +} from "../../composer-list-continuation";
29 import type { Dispatch, RefObject, SetStateAction } from "react";
30
31 /**
@@ -172,6 +177,25 @@ export function composerCommandKeyHandler(input: {
177 return true;
178 };
179
180 + const applyListEdit = (
181 + event: KeyboardEvent,
182 + listEdit: (value: string, start: number, end: number) => ComposerListEdit | null,
183 + ): boolean => {
184 + if (isLiteralPendingAnswer || event.isComposing) return false;
185 + const selection = composerEditorRef.current?.readSelectionRange();
186 + const snapshot = readComposerSnapshot();
187 + if (!selection || selection.start !== selection.end || snapshot.value !== promptRef.current) {
188 + return false;
189 + }
190 + const edit = listEdit(snapshot.value, selection.start, selection.end);
191 + return (
192 + edit !== null &&
193 + applyPromptReplacement(edit.start, edit.end, edit.replacement, {
194 + expandedCursorAfterReplace: edit.cursorAfter,
195 + })
196 + );
197 + };
198 +
199 const onComposerCommandKey = (key: string, event: KeyboardEvent, isTaskItem = false) => {
200 const submissionIntent = composerSubmissionIntentForKey({
201 event,
@@ -183,6 +207,7 @@ export function composerCommandKeyHandler(input: {
207 prompt: promptRef.current,
208 });
209 if (key === "Tab" && event.shiftKey && submissionIntent === null) {
210 + if (applyListEdit(event, listOutdentForTab)) return true;
211 if (!planModeUiEnabled) return false;
212 toggleInteractionMode();
213 return true;
@@ -229,27 +254,8 @@ export function composerCommandKeyHandler(input: {
254 return true;
255 }
256 if (key === "Enter" && isTaskItem) return false;
232 - if (
233 - !isLiteralPendingAnswer &&
234 - !event.isComposing &&
235 - (key === "Enter" || (key === "Tab" && !event.shiftKey))
236 - ) {
237 - const selection = composerEditorRef.current?.readSelectionRange();
238 - const snapshot = readComposerSnapshot();
239 - if (selection && selection.start === selection.end && snapshot.value === promptRef.current) {
240 - const edit =
241 - key === "Enter"
242 - ? listContinuationForEnter(snapshot.value, selection.start)
243 - : listIndentForTab(snapshot.value, selection.start, selection.end);
244 - if (
245 - edit &&
246 - applyPromptReplacement(edit.start, edit.end, edit.replacement, {
247 - expandedCursorAfterReplace: edit.cursorAfter,
248 - })
249 - ) {
250 - return true;
251 - }
252 - }
257 + if (key === "Enter" || (key === "Tab" && !event.shiftKey)) {
258 + return applyListEdit(event, key === "Enter" ? listContinuationForEnter : listIndentForTab);
259 }
260 return false;
261 };
apps/web/src/composer-list-continuation.test.ts
+25
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
3 import {
4 listContinuationForEnter,
5 listIndentForTab,
6 + listOutdentForTab,
7 nextOrderedMarkerText,
8 } from "./composer-list-continuation";
9
@@ -86,6 +87,30 @@ describe("composer list indentation", () => {
87 const edit = listIndentForTab(value, value.length, value.length)!;
88 expect(applyEdit(value, edit)).toBe("1. parent\n 1. first\n 2. second");
89 });
90 +
91 + it.each(["- parent\n- child", "1. parent\n2. child", " 7. child"])(
92 + "undoes Tab on %j with Shift+Tab and keeps the caret on its text",
93 + (value) => {
94 + const cursor = value.lastIndexOf("child") + 2;
95 + const nest = listIndentForTab(value, cursor, cursor)!;
96 + const nested = applyEdit(value, nest);
97 + const edit = listOutdentForTab(nested, nest.cursorAfter, nest.cursorAfter)!;
98 + expect(applyEdit(nested, edit)).toBe(value);
99 + expect(edit.cursorAfter).toBe(cursor);
100 + },
101 + );
102 +
103 + it.each([
104 + ["1. a\n 1. b\n2. c", "1. a\n2. b\n3. c"],
105 + ["- a\n 5. b", "- a\n5. b"],
106 + ])("outdents %j to %j and renumbers only within the parent's list", (value, expected) => {
107 + const edit = listOutdentForTab(value, value.indexOf("b"), value.indexOf("b"))!;
108 + expect(applyEdit(value, edit)).toBe(expected);
109 + });
110 +
111 + it("leaves a top-level item alone so Shift+Tab can still switch Build/Plan", () => {
112 + expect(listOutdentForTab("- item", 6, 6)).toBeNull();
113 + });
114 });
115
116 describe("nextOrderedMarkerText", () => {
apps/web/src/composer-list-continuation.ts
+38
@@ -302,3 +302,41 @@ export function listIndentForTab(
302 }
303 return { start: line.start, end: line.start, replacement: " ", cursorAfter: start + 2 };
304 }
305 +
306 +export function listOutdentForTab(
307 + value: string,
308 + start: number,
309 + end: number,
310 +): ComposerListEdit | null {
311 + if (!Number.isInteger(start) || start !== end || start < 0 || start > value.length) return null;
312 + const line = currentLine(value, start);
313 + const parsed = parseListMarker(line.text);
314 + if (!parsed?.marker.indent) return null;
315 + const tokens = inlineTokenRanges(value);
316 + if (isInsideInlineToken(tokens, start)) return null;
317 + const { marker } = parsed;
318 + const parent = parentMarker(value, line.start, marker, tokens);
319 + // With no parent above, undo one step of Tab's two-space fallback.
320 + const indent = parent?.indent ?? marker.indent.replace(/^(?:\t| {1,2})/, "");
321 + const continues =
322 + parent?.kind === "ordered" &&
323 + marker.kind === "ordered" &&
324 + parent.delimiter === marker.delimiter;
325 + const number = continues ? nestedNumber(marker, parent) : { replacedLength: 0, text: "" };
326 + const replacedEnd = line.start + marker.indent.length + number.replacedLength;
327 + const replacement = indent + number.text;
328 + const cursorAfter =
329 + start < replacedEnd
330 + ? line.start + indent.length
331 + : start - replacedEnd + line.start + replacement.length;
332 + const renumbered = continues ? renumberFollowingItems(value, line.end, parent, tokens) : null;
333 + if (renumbered) {
334 + return {
335 + start: line.start,
336 + end: renumbered.end,
337 + replacement: replacement + value.slice(replacedEnd, line.end) + renumbered.text,
338 + cursorAfter,
339 + };
340 + }
341 + return { start: line.start, end: replacedEnd, replacement, cursorAfter };
342 +}
docs/user/composer.md
+1 -1
@@ -23,7 +23,7 @@ included, and `#1234` without a space still looks up a pull request.
23
24 Enter sends. In a list or quote, **Shift+Enter** continues it, and Shift+Enter
25 on an empty line moves out one level, then leaves it; **Tab** nests a list item
26 -under the one above. In a code block, Enter
26 +under the one above and **Shift+Tab** moves it back out. In a code block, Enter
27 starts a new line at the current indentation, **Tab** and **Shift+Tab** indent
28 the selected lines, and a closing ` ``` ` followed by Enter, or two blank lines
29 at the end, leave the block. **Backspace** at the start of a code block turns it