Merge branch 'master' into 1684

This commit is contained in:
Horace He 2017-05-18 21:30:54 -04:00 committed by GitHub
commit de49ff5046
5 changed files with 57 additions and 7 deletions

View File

@ -708,7 +708,7 @@ class CommandInsertInSearchMode extends BaseCommand {
if (key === "<BS>" || key === "<shift+BS>") {
searchState.searchString = searchState.searchString.slice(0, -1);
} else if (key === "\n") {
vimState.currentMode = ModeName.Normal;
vimState.currentMode = vimState.globalState.searchState!.previousMode;
// Repeat the previous search if no new string is entered
if (searchState.searchString === "") {
@ -944,7 +944,7 @@ function createSearchStateAndMoveToMatch(args: {
// Start a search for the given term.
vimState.globalState.searchState = new SearchState(
args.direction, vimState.cursorPosition, searchString, { isRegex: isExact }
args.direction, vimState.cursorPosition, searchString, { isRegex: isExact }, vimState.currentMode
);
vimState.cursorPosition = vimState.globalState.searchState.getNextSearchMatchPosition(args.searchStartCursorPosition).pos;
@ -1029,12 +1029,13 @@ class CommandSearchVisualBackward extends BaseCommand {
@RegisterAction
export class CommandSearchForwards extends BaseCommand {
modes = [ModeName.Normal];
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock];
keys = ["/"];
isMotion = true;
public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.globalState.searchState = new SearchState(SearchDirection.Forward, vimState.cursorPosition, "", { isRegex: true });
vimState.globalState.searchState = new SearchState(SearchDirection.Forward,
vimState.cursorPosition, "", { isRegex: true }, vimState.currentMode);
vimState.currentMode = ModeName.SearchInProgressMode;
// Reset search history index
@ -1048,12 +1049,13 @@ export class CommandSearchForwards extends BaseCommand {
@RegisterAction
export class CommandSearchBackwards extends BaseCommand {
modes = [ModeName.Normal];
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock];
keys = ["?"];
isMotion = true;
public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.globalState.searchState = new SearchState(SearchDirection.Backward, vimState.cursorPosition, "", { isRegex: true });
vimState.globalState.searchState = new SearchState(SearchDirection.Backward,
vimState.cursorPosition, "", { isRegex: true }, vimState.currentMode);
vimState.currentMode = ModeName.SearchInProgressMode;
// Reset search history index

View File

@ -586,6 +586,7 @@ abstract class MoveByScreenLine extends BaseMovement {
value: this.value
});
if (vimState.currentMode === ModeName.Normal) {
return Position.FromVSCodePosition(vimState.editor.selection.active);
} else {

View File

@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { Position } from './../common/motion/position';
import { TextEditor } from './../textEditor';
import { Configuration } from '../../src/configuration/configuration';
import { ModeName } from './../mode/mode';
export enum SearchDirection {
Forward = 1,
@ -14,6 +15,7 @@ export enum SearchDirection {
export class SearchState {
private static readonly MAX_SEARCH_RANGES = 1000;
private static specialCharactersRegex: RegExp = /[\-\[\]{}()*+?.,\\\^$|#\s]/g;
public previousMode = ModeName.Normal;
private _matchRanges: vscode.Range[] = [];
@ -194,10 +196,11 @@ export class SearchState {
}
}
constructor(direction: SearchDirection, startPosition: Position, searchString = "", { isRegex = false } = {}) {
constructor(direction: SearchDirection, startPosition: Position, searchString = "", { isRegex = false } = {}, currentMode: ModeName) {
this._searchDirection = direction;
this._searchCursorStartPosition = startPosition;
this.isRegex = isRegex;
this.searchString = searchString;
this.previousMode = currentMode;
}
}

View File

@ -810,4 +810,26 @@ suite("Mode Visual", () => {
});
});
suite("search works in visual mode", () => {
newTest({
title: "Works with /",
start: ["f|oo",
"bar",
"fun",
"baz"],
keysPressed: "v/baz\nx",
end: ["f|az"]
});
newTest({
title: "Works with ?",
start: ["foo",
"bar",
"fun",
"b|az"],
keysPressed: "v?foo\nx",
end: ["|z"]
});
});
});

View File

@ -318,4 +318,26 @@ suite("Mode Visual", () => {
});
});
suite("search works in visual line mode", () => {
newTest({
title: "Works with /",
start: ["f|oo",
"bar",
"fun",
"baz"],
keysPressed: "V/fun\nx",
end: ["|baz"]
});
newTest({
title: "Works with ?",
start: ["foo",
"bar",
"fun",
"b|az"],
keysPressed: "V?bar\nx",
end: ["|foo"]
});
});
});