Skip to content

Commit

Permalink
Fixes #7: previous/next empty line move to beginning/end of document …
Browse files Browse the repository at this point in the history
…if no empty lines found.
  • Loading branch information
lukstafi committed Feb 13, 2023
1 parent 412cee7 commit 586242b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,10 @@ export async function goToEmptyLine(textEditor: vscode.TextEditor, select: boole
break;
}
}
if (!targetPos) { return; }
if (!targetPos) {
targetPos = before ? doc.validatePosition(doc.positionAt(0))
: doc.validatePosition(doc.lineAt(doc.lineCount-1).range.end);
}
const anchor = select ? textEditor.selection.anchor : targetPos;
textEditor.selection = new vscode.Selection(anchor, targetPos);
textEditor.revealRange(textEditor.selection);
Expand Down
64 changes: 63 additions & 1 deletion src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getAnnotatedContent(textEditor: vscode.TextEditor, sourcePos: vscode.Po
return content;
}

const isDebugSession = false;
const isDebugSession = true;

function testCase(content: string, command: string, mode: string, language: string, debugThis?: boolean | undefined) {
if ((isDebugSession && !debugThis) || (!isDebugSession && debugThis)) { return; }
Expand All @@ -56,6 +56,10 @@ function testCase(content: string, command: string, mode: string, language: stri
'goPastPreviousWord': () => myExtension.goPastWord(textEditor, false, true),
'selectPastNextWord': () => myExtension.goPastWord(textEditor, true, false),
'selectPastPreviousWord': () => myExtension.goPastWord(textEditor, true, true),
'goToPreviousEmptyLine': () => myExtension.goToEmptyLine(textEditor, false, true),
'goToNextEmptyLine': () => myExtension.goToEmptyLine(textEditor, false, false),
'selectToPreviousEmptyLine': () => myExtension.goToEmptyLine(textEditor, true, true),
'selectToNextEmptyLine': () => myExtension.goToEmptyLine(textEditor, true, false),
}));
// TODO(2): enable symbol providers -- perhaps add mocks.
const modes = new Map([
Expand Down Expand Up @@ -1252,4 +1256,62 @@ word2
'goPastNextWord', mode, 'typescript'
));
}
{
const mode = 'NON/NON';
test('Paragraph navigation: previous empty line', testCase(
`
paragraph1
^
paragraph2@
paragraph3
`,
'goToPreviousEmptyLine', mode, 'text'
));
test('Paragraph navigation: next empty line', testCase(
`
paragraph1
@paragraph2
^
paragraph3
`,
'goToNextEmptyLine', mode, 'text'
));
test('Paragraph navigation: previous empty line 2', testCase(
`
paragraph1
^
paragraph2
paragraph2@
paragraph3
`,
'goToPreviousEmptyLine', mode, 'text'
));
test('Paragraph navigation: next empty line 2', testCase(
`
paragraph1
@paragraph2
paragraph2
^
paragraph3
`,
'goToNextEmptyLine', mode, 'text'
));
test('Tricky paragraph navigation: beginning of document', testCase(
`^paragraph
paragraph@
`,
'goToPreviousEmptyLine', mode, 'text', true
));
test('Tricky paragraph navigation: end of document', testCase(
`
@paragraph
paragraph
paragraph^`,
'goToNextEmptyLine', mode, 'text', true
));
}
});

0 comments on commit 586242b

Please sign in to comment.