GeezerVison is showing github.com — fix(web): keep a leading blank line selected when indenting code (#34… · incognitojam/styal@9a2f1cf
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/composer-code-block.test.ts +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,11 +144,15 @@ describe("indentCodeBlock", () => { | 144 | 144 | expect(textOf(editor)).toBe("one\ntwo"); | 145 | 145 | }); | 146 | 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 }); | 149 | 152 | indentCodeBlock(editor.state, "in", (tr) => editor.view.dispatch(tr)); | 150 | 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); | 152 | 156 | }); | 153 | 157 |
| 154 | 158 | it("reports handled when outdenting can go no further, so Tab never escapes the editor", () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/composer-code-block.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -137,7 +137,7 @@ export function indentCodeBlock( | 137 | 137 | return true; | 138 | 138 | } | 139 | 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 | 141 | const newlineAfter = block.text.indexOf("\n", Math.max(startOffset, endOffset - 1)); | 142 | 142 | const lineEnd = newlineAfter === -1 ? block.text.length : newlineAfter; | 143 | 143 |
| |
|