Skip to content

Commit 6e0d024

Browse files
committed
Fix #6158. Persist isRegex, macthCase, wholeWord search settings for workspace
1 parent e0dfe9d commit 6e0d024

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/vs/editor/contrib/find/browser/find.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { FindWidget, IFindController } from 'vs/editor/contrib/find/browser/find
1313
import { FindOptionsWidget } from 'vs/editor/contrib/find/browser/findOptionsWidget';
1414
import { CommonFindController, FindStartFocusAction, IFindStartOptions } from 'vs/editor/contrib/find/common/findController';
1515
import { IThemeService } from 'vs/platform/theme/common/themeService';
16+
import { IStorageService } from 'vs/platform/storage/common/storage';
1617

1718
@editorContribution
1819
export class FindController extends CommonFindController implements IFindController {
@@ -25,9 +26,10 @@ export class FindController extends CommonFindController implements IFindControl
2526
@IContextViewService contextViewService: IContextViewService,
2627
@IContextKeyService contextKeyService: IContextKeyService,
2728
@IKeybindingService keybindingService: IKeybindingService,
28-
@IThemeService themeService: IThemeService
29+
@IThemeService themeService: IThemeService,
30+
@IStorageService storageService: IStorageService
2931
) {
30-
super(editor, contextKeyService);
32+
super(editor, contextKeyService, storageService);
3133

3234
this._widget = this._register(new FindWidget(editor, this, this._state, contextViewService, keybindingService, contextKeyService, themeService));
3335
this._findOptionsWidget = this._register(new FindOptionsWidget(editor, this._state, keybindingService, themeService));

src/vs/editor/contrib/find/browser/findWidget.ts

+3
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ export class FindWidget extends Widget implements IOverlayWidget {
483483
}
484484
}
485485
}));
486+
this._findInput.setRegex(!!this._state.isRegex);
487+
this._findInput.setCaseSensitive(!!this._state.matchCase);
488+
this._findInput.setWholeWords(!!this._state.wholeWord);
486489
this._register(this._findInput.onKeyDown((e) => this._onFindInputKeyDown(e)));
487490
this._register(this._findInput.onInput(() => {
488491
this._state.change({ searchString: this._findInput.getValue() }, true);

src/vs/editor/contrib/find/common/findController.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { DocumentHighlightProviderRegistry } from 'vs/editor/common/modes';
2020
import { RunOnceScheduler, Delayer } from 'vs/base/common/async';
2121
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
2222
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
23+
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
2324

2425
export const enum FindStartFocusAction {
2526
NoFocusChange,
@@ -48,19 +49,22 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
4849
private _currentHistoryNavigator: HistoryNavigator<string>;
4950
protected _updateHistoryDelayer: Delayer<void>;
5051
private _model: FindModelBoundToEditorModel;
52+
private _storageService: IStorageService;
5153

5254
public static get(editor: editorCommon.ICommonCodeEditor): CommonFindController {
5355
return editor.getContribution<CommonFindController>(CommonFindController.ID);
5456
}
5557

56-
constructor(editor: editorCommon.ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService) {
58+
constructor(editor: editorCommon.ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @IStorageService storageService: IStorageService) {
5759
super();
5860
this._editor = editor;
5961
this._findWidgetVisible = CONTEXT_FIND_WIDGET_VISIBLE.bindTo(contextKeyService);
62+
this._storageService = storageService;
6063

6164
this._updateHistoryDelayer = new Delayer<void>(500);
6265
this._currentHistoryNavigator = new HistoryNavigator<string>();
6366
this._state = this._register(new FindReplaceState());
67+
this.loadQueryState();
6468
this._register(this._state.addChangeListener((e) => this._onStateChanged(e)));
6569

6670
this._model = null;
@@ -71,7 +75,10 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
7175
this.disposeModel();
7276

7377
this._state.change({
74-
searchScope: null
78+
searchScope: null,
79+
matchCase: this._storageService.getBoolean('editor.matchCase', StorageScope.WORKSPACE, false),
80+
wholeWord: this._storageService.getBoolean('editor.wholeWord', StorageScope.WORKSPACE, false),
81+
isRegex: this._storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE, false)
7582
}, false);
7683

7784
if (shouldRestartFind) {
@@ -102,6 +109,8 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
102109
}
103110

104111
private _onStateChanged(e: FindReplaceStateChangedEvent): void {
112+
this.saveQueryState(e);
113+
105114
if (e.updateHistory && e.searchString) {
106115
this._delayedUpdateHistory();
107116
}
@@ -115,6 +124,26 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
115124
}
116125
}
117126

127+
private saveQueryState(e: FindReplaceStateChangedEvent) {
128+
if (e.isRegex && typeof this._state.isRegex !== 'undefined') {
129+
this._storageService.store('editor.isRegex', this._state.isRegex, StorageScope.WORKSPACE);
130+
}
131+
if (e.wholeWord && typeof this._state.wholeWord !== 'undefined') {
132+
this._storageService.store('editor.wholeWord', this._state.wholeWord, StorageScope.WORKSPACE);
133+
}
134+
if (e.matchCase && typeof this._state.matchCase !== 'undefined') {
135+
this._storageService.store('editor.matchCase', this._state.matchCase, StorageScope.WORKSPACE);
136+
}
137+
}
138+
139+
private loadQueryState() {
140+
this._state.change({
141+
matchCase: this._storageService.getBoolean('editor.matchCase', StorageScope.WORKSPACE, this._state.matchCase),
142+
wholeWord: this._storageService.getBoolean('editor.wholeWord', StorageScope.WORKSPACE, this._state.wholeWord),
143+
isRegex: this._storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE, this._state.isRegex)
144+
}, false);
145+
}
146+
118147
protected _delayedUpdateHistory() {
119148
this._updateHistoryDelayer.trigger(this._updateHistory.bind(this));
120149
}

src/vs/editor/contrib/find/test/common/findController.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { MockCodeEditor, withMockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
2121
import { HistoryNavigator } from 'vs/base/common/history';
2222
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
23+
import { IStorageService } from 'vs/platform/storage/common/storage';
2324
import { Delayer } from 'vs/base/common/async';
2425

2526
class TestFindController extends CommonFindController {
@@ -30,8 +31,8 @@ class TestFindController extends CommonFindController {
3031

3132
private _delayedUpdateHistoryEvent: Emitter<void> = new Emitter<void>();
3233

33-
constructor(editor: ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService) {
34-
super(editor, contextKeyService);
34+
constructor(editor: ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @IStorageService storageService: IStorageService) {
35+
super(editor, contextKeyService, storageService);
3536
this._updateHistoryDelayer = new Delayer<void>(50);
3637
}
3738

0 commit comments

Comments
 (0)