From 0c9b2266e5ad16230c51af7363b4c6063cf65398 Mon Sep 17 00:00:00 2001 From: fujimoto kyosuke <31386431+lusingander@users.noreply.github.com> Date: Thu, 26 Mar 2020 23:41:35 +0900 Subject: [PATCH 1/2] Fix search with count (#4675) [count]/[word] (and [count]?[word]) was not working. And d[count]/[word] was not working either. Fixes #4669 Fixes #2464 --- src/actions/commands/commandLine.ts | 13 +++++-- test/mode/modeNormal.test.ts | 21 ++++++++++++ test/mode/normalModeTests/motions.test.ts | 42 +++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/actions/commands/commandLine.ts b/src/actions/commands/commandLine.ts index 3f2dc474ff30..5bc65d405d0e 100644 --- a/src/actions/commands/commandLine.ts +++ b/src/actions/commands/commandLine.ts @@ -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, diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 8853b6341beb..7220ef34f1ba 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -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'], diff --git a/test/mode/normalModeTests/motions.test.ts b/test/mode/normalModeTests/motions.test.ts index eb11f8b7da82..b7f8bf36ad56 100644 --- a/test/mode/normalModeTests/motions.test.ts +++ b/test/mode/normalModeTests/motions.test.ts @@ -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 @@ -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(); From c09b61ac7b4f2fed6724895f0615e002d1377650 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 26 Mar 2020 14:46:27 +0000 Subject: [PATCH 2/2] Update dependency prettier to v2 --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1da2af000813..bb47c7d3df56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4684,9 +4684,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.2.tgz", + "integrity": "sha512-5xJQIPT8BraI7ZnaDwSbu5zLrB6vvi8hVV58yHQ+QK64qrY40dULy0HSRlQ2/2IdzeBpjhDkqdcFBnFeDEMVdg==", "dev": true }, "pretty-hrtime": { diff --git a/package.json b/package.json index 9e415c5f3cab..e80c9d302ba0 100644 --- a/package.json +++ b/package.json @@ -975,7 +975,7 @@ "minimist": "1.2.5", "mocha": "7.1.1", "plugin-error": "1.0.1", - "prettier": "1.19.1", + "prettier": "2.0.2", "sinon": "9.0.1", "ts-loader": "6.2.2", "tslint": "6.1.0",