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

Implement nowrapscan #4028

Merged
merged 4 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class Configuration implements IConfiguration {
wrapKeys = {};

report = 2;
wrapscan = true;

cursorStylePerMode: IModeSpecificStrings<string> = {
normal: undefined,
Expand Down
5 changes: 5 additions & 0 deletions src/configuration/iconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,9 @@ export interface IConfiguration {
* User-defined digraphs
*/
digraphs: { [shortcut: string]: Digraph };

/**
* Searches wrap around the end of the file.
*/
wrapscan: boolean;
}
47 changes: 33 additions & 14 deletions src/state/searchState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
};
}
}
}

Expand Down
46 changes: 46 additions & 0 deletions test/motionLineWrapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
});
});
1 change: 1 addition & 0 deletions test/testConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ export class Configuration implements IConfiguration {
wrapKeys = {};
report = 2;
digraphs: {};
wrapscan = true;
}