The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keep a leading blank line selected when indenting code (#34307)
Romil committed
Nov 12, 2026 at 10:24 UTC
3de3c9ffff678a0c54d324e9d0ef7b5767a95e54
2 files changed
+8
-4
apps/web/src/composer-code-block.test.ts
+7
-3
@@ -144,11 +144,15 @@ describe("indentCodeBlock", () => {
144
expect(textOf(editor)).toBe("one\ntwo");
145
});
146
147
- it("keeps the selection across the shifted lines", () => {
148
- const editor = codeEditor("one\ntwo", { from: 0, to: 7 });
147
+ it.each([
148
+ ["one\ntwo", " one\n two", 5],
149
+ ["\none\ntwo", "\n one\n two", 1],
150
+ ])("keeps the selection across the shifted lines in %s", (code, expected, from) => {
151
+ const editor = codeEditor(code, { from: 0, to: code.length });
152
indentCodeBlock(editor.state, "in", (tr) => editor.view.dispatch(tr));
153
indentCodeBlock(editor.state, "in", (tr) => editor.view.dispatch(tr));
151
- expect(textOf(editor)).toBe(" one\n two");
154
+ expect(textOf(editor)).toBe(expected);
155
+ expect(editor.state.selection.from).toBe(from);
156
});
157
158
it("reports handled when outdenting can go no further, so Tab never escapes the editor", () => {
apps/web/src/composer-code-block.ts
+1
-1
@@ -137,7 +137,7 @@ export function indentCodeBlock(
137
return true;
138
}
139
140
- const lineStart = block.text.lastIndexOf("\n", Math.max(0, startOffset - 1)) + 1;
140
+ const lineStart = startOffset === 0 ? 0 : block.text.lastIndexOf("\n", startOffset - 1) + 1;
141
const newlineAfter = block.text.indexOf("\n", Math.max(startOffset, endOffset - 1));
142
const lineEnd = newlineAfter === -1 ? block.text.length : newlineAfter;
143