提交 4014d838 编写于 作者: A Alex Dima

Fixes #6149: Escape selected text used to seed search input when regex toggle is on

上级 586e60d0
......@@ -13,6 +13,7 @@ import {Range} from 'vs/editor/common/core/range';
import {Selection} from 'vs/editor/common/core/selection';
import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import * as strings from 'vs/base/common/strings';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {FIND_IDS, FindModelBoundToEditorModel} from 'vs/editor/contrib/find/common/findModel';
......@@ -161,7 +162,11 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
if (opts.seedSearchStringFromSelection) {
let selectionSearchString = this.getSelectionSearchString();
if (selectionSearchString) {
stateChanges.searchString = selectionSearchString;
if (this._state.isRegex) {
stateChanges.searchString = strings.escapeRegExpCharacters(selectionSearchString);
} else {
stateChanges.searchString = selectionSearchString;
}
}
}
......
......@@ -7,6 +7,7 @@
import * as assert from 'assert';
import {EditOperation} from 'vs/editor/common/core/editOperation';
import {Position} from 'vs/editor/common/core/position';
import {Selection} from 'vs/editor/common/core/selection';
import {Range} from 'vs/editor/common/core/range';
import {IRange} from 'vs/editor/common/editorCommon';
import {CommonFindController, FindStartFocusAction, IFindStartOptions, NextMatchFindAction, StartFindAction} from 'vs/editor/contrib/find/common/findController';
......@@ -94,7 +95,6 @@ suite('FindController', () => {
'import nls = require(\'vs/nls\');'
], {}, (editor, cursor) => {
// The cursor is at the very top, of the file, at the first ABC
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let nextMatchFindAction = new NextMatchFindAction({id:'',label:''}, editor);
......@@ -113,4 +113,32 @@ suite('FindController', () => {
nextMatchFindAction.dispose();
});
});
test('issue #6149: Auto-escape highlighted text for search and replace regex mode', () => {
withMockCodeEditor([
'var x = (3 * 5)',
'var y = (3 * 5)',
'var z = (3 * 5)',
], {}, (editor, cursor) => {
let findController = editor.registerAndInstantiateContribution<TestFindController>(TestFindController);
let startFindAction = new StartFindAction({id:'',label:''}, editor);
let nextMatchFindAction = new NextMatchFindAction({id:'',label:''}, editor);
editor.setSelection(new Selection(1, 9, 1, 13));
findController.toggleRegex();
startFindAction.run();
nextMatchFindAction.run();
assert.deepEqual(fromRange(editor.getSelection()), [2, 9, 2, 13]);
nextMatchFindAction.run();
assert.deepEqual(fromRange(editor.getSelection()), [1, 9, 1, 13]);
findController.dispose();
startFindAction.dispose();
nextMatchFindAction.dispose();
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册