Skip to content

Commit

Permalink
Fix #6158. Persist isRegex, macthCase, wholeWord search settings for …
Browse files Browse the repository at this point in the history
…workspace
  • Loading branch information
rebornix committed May 8, 2017
1 parent e0dfe9d commit 6e0d024
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/vs/editor/contrib/find/browser/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FindWidget, IFindController } from 'vs/editor/contrib/find/browser/find
import { FindOptionsWidget } from 'vs/editor/contrib/find/browser/findOptionsWidget';
import { CommonFindController, FindStartFocusAction, IFindStartOptions } from 'vs/editor/contrib/find/common/findController';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IStorageService } from 'vs/platform/storage/common/storage';

@editorContribution
export class FindController extends CommonFindController implements IFindController {
Expand All @@ -25,9 +26,10 @@ export class FindController extends CommonFindController implements IFindControl
@IContextViewService contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
@IKeybindingService keybindingService: IKeybindingService,
@IThemeService themeService: IThemeService
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService
) {
super(editor, contextKeyService);
super(editor, contextKeyService, storageService);

this._widget = this._register(new FindWidget(editor, this, this._state, contextViewService, keybindingService, contextKeyService, themeService));
this._findOptionsWidget = this._register(new FindOptionsWidget(editor, this._state, keybindingService, themeService));
Expand Down
3 changes: 3 additions & 0 deletions src/vs/editor/contrib/find/browser/findWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ export class FindWidget extends Widget implements IOverlayWidget {
}
}
}));
this._findInput.setRegex(!!this._state.isRegex);
this._findInput.setCaseSensitive(!!this._state.matchCase);
this._findInput.setWholeWords(!!this._state.wholeWord);
this._register(this._findInput.onKeyDown((e) => this._onFindInputKeyDown(e)));
this._register(this._findInput.onInput(() => {
this._state.change({ searchString: this._findInput.getValue() }, true);
Expand Down
33 changes: 31 additions & 2 deletions src/vs/editor/contrib/find/common/findController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { DocumentHighlightProviderRegistry } from 'vs/editor/common/modes';
import { RunOnceScheduler, Delayer } from 'vs/base/common/async';
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';

export const enum FindStartFocusAction {
NoFocusChange,
Expand Down Expand Up @@ -48,19 +49,22 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
private _currentHistoryNavigator: HistoryNavigator<string>;
protected _updateHistoryDelayer: Delayer<void>;
private _model: FindModelBoundToEditorModel;
private _storageService: IStorageService;

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

constructor(editor: editorCommon.ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService) {
constructor(editor: editorCommon.ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @IStorageService storageService: IStorageService) {
super();
this._editor = editor;
this._findWidgetVisible = CONTEXT_FIND_WIDGET_VISIBLE.bindTo(contextKeyService);
this._storageService = storageService;

this._updateHistoryDelayer = new Delayer<void>(500);
this._currentHistoryNavigator = new HistoryNavigator<string>();
this._state = this._register(new FindReplaceState());
this.loadQueryState();
this._register(this._state.addChangeListener((e) => this._onStateChanged(e)));

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

this._state.change({
searchScope: null
searchScope: null,
matchCase: this._storageService.getBoolean('editor.matchCase', StorageScope.WORKSPACE, false),
wholeWord: this._storageService.getBoolean('editor.wholeWord', StorageScope.WORKSPACE, false),
isRegex: this._storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE, false)
}, false);

if (shouldRestartFind) {
Expand Down Expand Up @@ -102,6 +109,8 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}

private _onStateChanged(e: FindReplaceStateChangedEvent): void {
this.saveQueryState(e);

if (e.updateHistory && e.searchString) {
this._delayedUpdateHistory();
}
Expand All @@ -115,6 +124,26 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}
}

private saveQueryState(e: FindReplaceStateChangedEvent) {
if (e.isRegex && typeof this._state.isRegex !== 'undefined') {
this._storageService.store('editor.isRegex', this._state.isRegex, StorageScope.WORKSPACE);
}
if (e.wholeWord && typeof this._state.wholeWord !== 'undefined') {
this._storageService.store('editor.wholeWord', this._state.wholeWord, StorageScope.WORKSPACE);
}
if (e.matchCase && typeof this._state.matchCase !== 'undefined') {
this._storageService.store('editor.matchCase', this._state.matchCase, StorageScope.WORKSPACE);
}
}

private loadQueryState() {
this._state.change({
matchCase: this._storageService.getBoolean('editor.matchCase', StorageScope.WORKSPACE, this._state.matchCase),
wholeWord: this._storageService.getBoolean('editor.wholeWord', StorageScope.WORKSPACE, this._state.wholeWord),
isRegex: this._storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE, this._state.isRegex)
}, false);
}

protected _delayedUpdateHistory() {
this._updateHistoryDelayer.trigger(this._updateHistory.bind(this));
}
Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/contrib/find/test/common/findController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { MockCodeEditor, withMockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import { HistoryNavigator } from 'vs/base/common/history';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { Delayer } from 'vs/base/common/async';

class TestFindController extends CommonFindController {
Expand All @@ -30,8 +31,8 @@ class TestFindController extends CommonFindController {

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

constructor(editor: ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService) {
super(editor, contextKeyService);
constructor(editor: ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @IStorageService storageService: IStorageService) {
super(editor, contextKeyService, storageService);
this._updateHistoryDelayer = new Delayer<void>(50);
}

Expand Down

0 comments on commit 6e0d024

Please sign in to comment.