From 6e19dd65dd441ab29cafbdc8c13ffc847d08a30e Mon Sep 17 00:00:00 2001 From: contrib15 Date: Mon, 2 Sep 2019 07:39:03 +0000 Subject: [PATCH 1/2] Fix issue #3155 'Does not support nowrapscan' --- package.json | 5 ++++ src/configuration/configuration.ts | 1 + src/state/searchState.ts | 47 +++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 421a3ede1f3..f6644f3ef0b 100644 --- a/package.json +++ b/package.json @@ -733,6 +733,11 @@ "type": "object", "description": "Custom digraph shortcuts for inserting special characters, expressed as UTF16 code points", "default": {} + }, + "vim.wrapscan": { + "type": "boolean", + "description": "Searches wrap around the end of the file", + "default": true } } } diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index 2b8823c8391..75fc89c51e2 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -307,6 +307,7 @@ class Configuration implements IConfiguration { wrapKeys = {}; report = 2; + wrapscan = true; cursorStylePerMode: IModeSpecificStrings = { normal: undefined, diff --git a/src/state/searchState.ts b/src/state/searchState.ts index d3a4c79e6aa..a62e5b35f01 100644 --- a/src/state/searchState.ts +++ b/src/state/searchState.ts @@ -300,13 +300,22 @@ export class SearchState { // Wrap around // TODO(bell) - const range = this._matchRanges[0]; - return { - start: Position.FromVSCodePosition(range.start), - end: Position.FromVSCodePosition(range.end), - match: true, - index: 0, - }; + if (configuration.wrapscan) { + const range = this._matchRanges[0]; + return { + start: Position.FromVSCodePosition(range.start), + end: Position.FromVSCodePosition(range.end), + match: true, + index: 0, + }; + } else { + return { + start: startPosition, + end: startPosition, + match: true, + index: this._matchRanges.length - 1, + }; + } } else { for (let [index, matchRange] of this._matchRanges .slice(0) @@ -322,14 +331,24 @@ export class SearchState { } } + // Wrap around // TODO(bell) - const range = this._matchRanges[this._matchRanges.length - 1]; - return { - start: Position.FromVSCodePosition(range.start), - end: Position.FromVSCodePosition(range.end), - match: true, - index: this._matchRanges.length - 1, - }; + if (configuration.wrapscan) { + const range = this._matchRanges[this._matchRanges.length - 1]; + return { + start: Position.FromVSCodePosition(range.start), + end: Position.FromVSCodePosition(range.end), + match: true, + index: this._matchRanges.length - 1, + }; + } else { + return { + start: startPosition, + end: startPosition, + match: true, + index: 0, + }; + } } } From 3fef72b3547cc067fefc6b41c18923c06c9a4958 Mon Sep 17 00:00:00 2001 From: contrib15 Date: Mon, 2 Sep 2019 09:07:41 +0000 Subject: [PATCH 2/2] Add a test for wrapscan/nowrapscan feature --- src/configuration/iconfiguration.ts | 5 ++++ test/motionLineWrapping.test.ts | 46 +++++++++++++++++++++++++++++ test/testConfiguration.ts | 1 + 3 files changed, 52 insertions(+) diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index ac5a012044e..2d5cb845e87 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -319,4 +319,9 @@ export interface IConfiguration { * User-defined digraphs */ digraphs: { [shortcut: string]: Digraph }; + + /** + * Searches wrap around the end of the file. + */ + wrapscan: boolean; } diff --git a/test/motionLineWrapping.test.ts b/test/motionLineWrapping.test.ts index 75879e71164..341694595f3 100644 --- a/test/motionLineWrapping.test.ts +++ b/test/motionLineWrapping.test.ts @@ -132,4 +132,50 @@ suite('motion line wrapping', () => { }); }); }); + + suite('wrapscan enabled', () => { + setup(async () => { + let configuration = new Configuration(); + configuration.wrapscan = true; + + await setupWorkspace(configuration); + }); + + newTest({ + title: 'search wraps around the end of the file', + start: ['|line 1', 'line 2'], + keysPressed: '/line\nn', + end: ['|line 1', 'line 2'], + }); + + newTest({ + title: 'search wraps around the start of the file', + start: ['|line 1', 'line 2'], + keysPressed: '/line\nNN', + end: ['line 1', '|line 2'], + }); + }); + + suite('wrapscan disabled', () => { + setup(async () => { + let configuration = new Configuration(); + configuration.wrapscan = false; + + await setupWorkspace(configuration); + }); + + newTest({ + title: 'search stops at the end of the file', + start: ['|line 1', 'line 2'], + keysPressed: '/line\nn', + end: ['line 1', '|line 2'], + }); + + newTest({ + title: 'search stops at the start of the file', + start: ['|line 1', 'line 2'], + keysPressed: '/line\nNN', + end: ['|line 1', 'line 2'], + }); + }); }); diff --git a/test/testConfiguration.ts b/test/testConfiguration.ts index 9bb46f0a852..7e121bf3197 100644 --- a/test/testConfiguration.ts +++ b/test/testConfiguration.ts @@ -104,4 +104,5 @@ export class Configuration implements IConfiguration { wrapKeys = {}; report = 2; digraphs: {}; + wrapscan = true; }