Skip to content

Commit 231db43

Browse files
authored
Merge pull request #3075 from jramosg/fix/insert-semicolon-sof
Fix insert semicolon when a multi-line form starts at the beginning of the file Fixes #3072
2 parents 537ad1e + 5c617da commit 231db43

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Changes to Calva.
77
- Fix: [Connecting a REPL sequence disconnects the previous prematurely](https://github.com/BetterThanTomorrow/calva/issues/3065)
88
- Fix: [Toggle Line Comment produces incorrect output for multi-line selections](https://github.com/BetterThanTomorrow/calva/issues/3066)
99
- Fix: [Toggle Line Comment loses the selection when you run the command](https://github.com/BetterThanTomorrow/calva/issues/3067)
10+
- Fix: [Insert Semicolon does not work correctly in the first line of a file](https://github.com/BetterThanTomorrow/calva/issues/3072)
1011

1112
## [2.0.554] - 2026-02-17
1213

src/cursor-doc/paredit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,7 +2617,7 @@ export function _semiColonWouldBreakStructureWhere(
26172617

26182618
export async function insertSemiColon(doc: EditableDocument, p = doc.selections[0].active) {
26192619
const wouldBreakWhere = _semiColonWouldBreakStructureWhere(doc, p);
2620-
if (wouldBreakWhere) {
2620+
if (wouldBreakWhere !== false) {
26212621
const cursor = doc.getTokenCursor(p);
26222622
const lineText = doc.model.getLineText(cursor.line);
26232623
const indent = lineText.match(/^\s*/)[0];

src/extension-test/unit/cursor-doc/paredit-test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,6 +3326,12 @@ describe('paredit util', () => {
33263326
await paredit.insertSemiColon(a);
33273327
expect(textAndSelection(a)).toEqual(textAndSelection(b));
33283328
});
3329+
it('inserts a newline to preserve structure at offset 0', async () => {
3330+
const a = docFromTextNotation('|(defn hi []• (prn "hi"))');
3331+
const b = docFromTextNotation(';|•(defn hi []• (prn "hi"))');
3332+
await paredit.insertSemiColon(a);
3333+
expect(textAndSelection(a)).toEqual(textAndSelection(b));
3334+
});
33293335
});
33303336

33313337
describe('_semiColonWouldBreakStructureWhere', () => {
@@ -3412,5 +3418,12 @@ describe('paredit util', () => {
34123418
paredit._semiColonWouldBreakStructureWhere(docFromTextNotation('|a (b {•} c•) d '))
34133419
).toBe(2);
34143420
});
3421+
it('returns 0 when a multi-line form starts at offset 0', () => {
3422+
expect(
3423+
paredit._semiColonWouldBreakStructureWhere(
3424+
docFromTextNotation('|(defn hi []• (prn "hi"))')
3425+
)
3426+
).toBe(0);
3427+
});
34153428
});
34163429
});

0 commit comments

Comments
 (0)