GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): keep a leading blank line selected when indenting code (#34… · incognitojam/styal@9a2f1cf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src
    • composer-code-block.test.ts
    • composer-code-block.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/composer-code-block.test.ts‎

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 numberDiff line numberDiff line change
@@ -144,11 +144,15 @@ describe("indentCodeBlock", () => {
144144
expect(textOf(editor)).toBe("one\ntwo");
145145
});
146146

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 });
149152
indentCodeBlock(editor.state, "in", (tr) => editor.view.dispatch(tr));
150153
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);
152156
});
153157

154158
it("reports handled when outdenting can go no further, so Tab never escapes the editor", () => {
Collapse file

‎apps/web/src/composer-code-block.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/composer-code-block.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function indentCodeBlock(
137137
return true;
138138
}
139139

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;
141141
const newlineAfter = block.text.indexOf("\n", Math.max(startOffset, endOffset - 1));
142142
const lineEnd = newlineAfter === -1 ? block.text.length : newlineAfter;
143143

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.