From c994f3ddee471cc369229bfc82b45ab05ac079e1 Mon Sep 17 00:00:00 2001 From: "mgquan@myseneca.ca" Date: Sun, 18 Feb 2018 18:31:43 -0500 Subject: [PATCH 1/3] fixed #38232 --- src/vs/editor/contrib/find/findController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index aea6fb8abbcdb..3adac49aff825 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -538,7 +538,7 @@ export abstract class SelectionMatchFindAction extends EditorAction { if (!this._run(controller)) { controller.start({ forceRevealReplace: false, - seedSearchStringFromSelection: false, + seedSearchStringFromSelection: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection, seedSearchStringFromGlobalClipboard: false, shouldFocus: FindStartFocusAction.NoFocusChange, shouldAnimate: true From 6d3956c5151082973f194e109c5813beb3af803e Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 1 Mar 2018 11:25:29 +0100 Subject: [PATCH 2/3] Fix also the case when the find widget is open --- src/vs/editor/contrib/find/findController.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index 3adac49aff825..6289a33e0ff38 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -228,6 +228,9 @@ export class CommonFindController extends Disposable implements editorCommon.IEd } public setSearchString(searchString: string): void { + if (this._state.isRegex) { + searchString = strings.escapeRegExpCharacters(searchString); + } this._state.change({ searchString: searchString }, false); } From 006ab18f4579409027873fb6d7f982a60a0221f6 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 1 Mar 2018 11:25:37 +0100 Subject: [PATCH 3/3] Add tests --- .../contrib/find/test/findController.test.ts | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/contrib/find/test/findController.test.ts b/src/vs/editor/contrib/find/test/findController.test.ts index f48c33a69778f..54d7299ca3492 100644 --- a/src/vs/editor/contrib/find/test/findController.test.ts +++ b/src/vs/editor/contrib/find/test/findController.test.ts @@ -12,7 +12,7 @@ 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 * as platform from 'vs/base/common/platform'; -import { CommonFindController, FindStartFocusAction, IFindStartOptions, NextMatchFindAction, StartFindAction } from 'vs/editor/contrib/find/findController'; +import { CommonFindController, FindStartFocusAction, IFindStartOptions, NextMatchFindAction, StartFindAction, NextSelectionMatchFindAction } from 'vs/editor/contrib/find/findController'; import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; import { HistoryNavigator } from 'vs/base/common/history'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; @@ -475,6 +475,64 @@ suite('FindController', () => { } return result; } + + test('issue #38232: Find Next Selection, regex enabled', () => { + withTestCodeEditor([ + '([funny]', + '', + '([funny]' + ], { serviceCollection: serviceCollection }, (editor, cursor) => { + clipboardState = ''; + let findController = editor.registerAndInstantiateContribution(TestFindController); + let nextSelectionMatchFindAction = new NextSelectionMatchFindAction(); + + // toggle regex + findController.getState().change({ isRegex: true }, false); + + // change selection + editor.setSelection(new Selection(1, 1, 1, 9)); + + // cmd+f3 + nextSelectionMatchFindAction.run(null, editor); + + assert.deepEqual(editor.getSelections().map(fromRange), [ + [3, 1, 3, 9] + ]); + + findController.dispose(); + }); + }); + + test('issue #38232: Find Next Selection, regex enabled, find widget open', () => { + withTestCodeEditor([ + '([funny]', + '', + '([funny]' + ], { serviceCollection: serviceCollection }, (editor, cursor) => { + clipboardState = ''; + let findController = editor.registerAndInstantiateContribution(TestFindController); + let startFindAction = new StartFindAction(); + let nextSelectionMatchFindAction = new NextSelectionMatchFindAction(); + + // cmd+f - open find widget + startFindAction.run(null, editor); + + // toggle regex + findController.getState().change({ isRegex: true }, false); + + // change selection + editor.setSelection(new Selection(1, 1, 1, 9)); + + // cmd+f3 + nextSelectionMatchFindAction.run(null, editor); + + assert.deepEqual(editor.getSelections().map(fromRange), [ + [3, 1, 3, 9] + ]); + + findController.dispose(); + }); + }); }); suite('FindController query options persistence', () => {