mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 12:25:59 +03:00
Update sentence definition to allow for closing quotes/parens/squarebrackets (#8400)
Fixes #8390
This commit is contained in:
parent
59d55e1f86
commit
dcbbc4a460
@ -3,7 +3,7 @@ import { TextEditor } from '../textEditor';
|
||||
import { getCurrentParagraphBeginning, getCurrentParagraphEnd } from './paragraph';
|
||||
import { getAllPositions, getAllEndPositions } from './util';
|
||||
|
||||
const sentenceEndRegex = /[\.!\?]{1}([ \n\t]+|$)/g;
|
||||
const sentenceEndRegex = /[\.!\?]["')\]]*?([ \n\t]+|$)/g;
|
||||
|
||||
export function getSentenceBegin(position: Position, args: { forward: boolean }): Position {
|
||||
if (args.forward) {
|
||||
|
@ -492,6 +492,8 @@ suite('sentence motion', () => {
|
||||
' ',
|
||||
'Wow!',
|
||||
'Another sentence inside one paragraph.',
|
||||
'',
|
||||
'"Sentence in quotes." Sentence out of quotes. \'Sentence in singlequotes.\' (Sentence in parens.) [Sentence in square brackets.]',
|
||||
];
|
||||
|
||||
suiteSetup(async () => {
|
||||
@ -515,11 +517,29 @@ suite('sentence motion', () => {
|
||||
assert.strictEqual(motion.character, 0);
|
||||
});
|
||||
|
||||
test('next sentence when paragraph contains a line of whilte spaces', () => {
|
||||
test('next sentence when paragraph contains a line of white spaces', () => {
|
||||
const motion = new Position(6, 2).getSentenceBegin({ forward: true });
|
||||
assert.strictEqual(motion.line, 9);
|
||||
assert.strictEqual(motion.character, 0);
|
||||
});
|
||||
|
||||
test('next sentence when sentences have closing punctuation', () => {
|
||||
let motion = new Position(11, 0).getSentenceBegin({ forward: true });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 22);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: true });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 46);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: true });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 74);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: true });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 96);
|
||||
});
|
||||
});
|
||||
|
||||
suite('sentence backward', () => {
|
||||
@ -529,13 +549,13 @@ suite('sentence motion', () => {
|
||||
assert.strictEqual(motion.character, 35);
|
||||
});
|
||||
|
||||
test('sentence forward when cursor is at the beginning of the second sentence', () => {
|
||||
test('sentence backward when cursor is at the beginning of the second sentence', () => {
|
||||
const motion = new Position(0, 35).getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 0);
|
||||
assert.strictEqual(motion.character, 0);
|
||||
});
|
||||
|
||||
test('current sentence begin with no concrete sentense inside', () => {
|
||||
test('current sentence begin with no concrete sentence inside', () => {
|
||||
const motion = new Position(3, 0).getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 2);
|
||||
assert.strictEqual(motion.character, 0);
|
||||
@ -552,6 +572,28 @@ suite('sentence motion', () => {
|
||||
assert.strictEqual(motion.line, 9);
|
||||
assert.strictEqual(motion.character, 0);
|
||||
});
|
||||
|
||||
test('sentence backward when sentences have closing punctuation', () => {
|
||||
let motion = new Position(11, 125).getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 96);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 74);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 46);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 11);
|
||||
assert.strictEqual(motion.character, 22);
|
||||
|
||||
motion = motion.getSentenceBegin({ forward: false });
|
||||
assert.strictEqual(motion.line, 10);
|
||||
assert.strictEqual(motion.character, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,6 +50,34 @@ suite('sentence motion', () => {
|
||||
end: ['|lorem ipsum.lorem ipsum'],
|
||||
});
|
||||
|
||||
newTest({
|
||||
title: 'move one sentence backward closing quotes',
|
||||
start: ['"lorem ipsum." lorem ipsum|'],
|
||||
keysPressed: '(',
|
||||
end: ['"lorem ipsum." |lorem ipsum'],
|
||||
});
|
||||
|
||||
newTest({
|
||||
title: 'move one sentence backward closing singlequote',
|
||||
start: ["'lorem ipsum.' lorem ipsum|"],
|
||||
keysPressed: '(',
|
||||
end: ["'lorem ipsum.' |lorem ipsum"],
|
||||
});
|
||||
|
||||
newTest({
|
||||
title: 'move one sentence backward closing paren',
|
||||
start: ['(lorem ipsum.) lorem ipsum|'],
|
||||
keysPressed: '(',
|
||||
end: ['(lorem ipsum.) |lorem ipsum'],
|
||||
});
|
||||
|
||||
newTest({
|
||||
title: 'move one sentence backward closing square bracket',
|
||||
start: ['[lorem ipsum.] lorem ipsum|'],
|
||||
keysPressed: '(',
|
||||
end: ['[lorem ipsum.] |lorem ipsum'],
|
||||
});
|
||||
|
||||
newTest({
|
||||
title: 'move one sentence backward - multiline',
|
||||
start: ['lorem ipsum', 'lorem ipsum|'],
|
||||
|
Loading…
Reference in New Issue
Block a user