mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-11-10 10:58:33 +03:00
Merge pull request #1710 from Chillee/1520
Fixes #1520: search in visual/visualLine/visualBlock mode
This commit is contained in:
commit
7b3250f989
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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"]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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"]
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user