Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search with count #4675

Merged
merged 5 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/actions/commands/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,17 @@ class CommandInsertInSearchMode extends BaseCommand {
return vimState;
}

// Move cursor to next match
const nextMatch = searchState.getNextSearchMatchPosition(vimState.cursorStopPosition);
const count = vimState.recordedState.count || 1;
let searchPos = vimState.cursorStopPosition;
let nextMatch: { pos: Position; match: boolean; index: number } | undefined;
for (let i = 0; i < count; i++) {
// Move cursor to next match
nextMatch = searchState.getNextSearchMatchPosition(searchPos);
if (nextMatch === undefined) {
break;
}
searchPos = nextMatch.pos;
}
if (nextMatch === undefined) {
StatusBar.displayError(
vimState,
Expand Down
21 changes: 21 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,27 @@ suite('Mode Normal', () => {
end: ['{hello, |}'],
});

newTest({
title: "Can handle 'd/'",
start: ['one |two three four'],
keysPressed: 'd/four\n',
end: ['one |four'],
});

newTest({
title: "Can handle 'd/' with count ([count]d/[word])",
start: ['one |two two two two'],
keysPressed: '3d/two\n',
end: ['one |two'],
});

newTest({
title: "Can handle 'd/' with count (d[count]/[word])",
start: ['one |two two two two'],
keysPressed: 'd3/two\n',
end: ['one |two'],
});

newTest({
title: "Can handle 'cw'",
start: ['text text tex|t'],
Expand Down
42 changes: 42 additions & 0 deletions test/mode/normalModeTests/motions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ suite('Motions in Normal Mode', () => {
end: ['one two one tw|o'],
});

newTest({
title: 'Can run a forward search with count 1',
start: ['|one two two two'],
keysPressed: '1/tw\n',
end: ['one |two two two'],
});

newTest({
title: 'Can run a forward search with count 3',
start: ['|one two two two'],
keysPressed: '3/tw\n',
end: ['one two two |two'],
});

newTest({
title: 'Can run a forward search with count exceeding max number of matches',
start: ['|one two two two'],
keysPressed: '5/tw\n',
end: ['one two |two two'],
});

// These "remembering history between editor" tests have started
// breaking. Since I don't remember these tests ever breaking for real, and
// because they're the cause of a lot of flaky tests, I'm disabling these for
Expand Down Expand Up @@ -392,6 +413,27 @@ suite('Motions in Normal Mode', () => {
end: ['one |two two three'],
});

newTest({
title: 'Can run a reverse search with count 1',
start: ['one one one |two'],
keysPressed: '1?on\n',
end: ['one one |one two'],
});

newTest({
title: 'Can run a reverse search with count 3',
start: ['one one one |two'],
keysPressed: '3?on\n',
end: ['|one one one two'],
});

newTest({
title: 'Can run a reverse search with count exceeding max number of matches',
start: ['one one one |two'],
keysPressed: '5?on\n',
end: ['one |one one two'],
});

// test('Remembers a reverse search from another editor', async () => {
// // adding another editor
// await setupWorkspace();
Expand Down