Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find widget search history per editor instance #234208

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ export interface IEditorFindOptions {
/**
* Controls how the find widget search history should be stored
*/
findSearchHistory?: 'never' | 'workspace';
findSearchHistory?: 'never' | 'workspace' | 'editor';
}

/**
Expand Down Expand Up @@ -1726,11 +1726,12 @@ class EditorFind extends BaseEditorOption<EditorOption.find, IEditorFindOptions,
},
'editor.find.findSearchHistory': {
type: 'string',
enum: ['never', 'workspace'],
enum: ['never', 'workspace', 'editor'],
default: defaults.findSearchHistory,
enumDescriptions: [
nls.localize('editor.find.findSearchHistory.never', 'Do not store search history from the find widget.'),
nls.localize('editor.find.findSearchHistory.workspace', 'Store search history across the active workspace'),
nls.localize('editor.find.findSearchHistory.editor', 'Store the search history per editor instance'),
],
description: nls.localize('find.findSearchHistory', "Controls how the find widget search history should be stored")
}
Expand All @@ -1754,7 +1755,7 @@ class EditorFind extends BaseEditorOption<EditorOption.find, IEditorFindOptions,
globalFindClipboard: boolean(input.globalFindClipboard, this.defaultValue.globalFindClipboard),
addExtraSpaceOnTop: boolean(input.addExtraSpaceOnTop, this.defaultValue.addExtraSpaceOnTop),
loop: boolean(input.loop, this.defaultValue.loop),
findSearchHistory: stringSet<'never' | 'workspace'>(input.findSearchHistory, this.defaultValue.findSearchHistory, ['never', 'workspace']),
findSearchHistory: stringSet<'never' | 'workspace' | 'editor'>(input.findSearchHistory, this.defaultValue.findSearchHistory, ['never', 'workspace', 'editor']),
};
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/vs/editor/contrib/find/browser/findWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
this._contextKeyService = contextKeyService;
this._storageService = storageService;
this._notificationService = notificationService;
this._findWidgetSearchHistory = new FindWidgetSearchHistory(this._storageService);
const findSearchHistoryConfig = this._codeEditor.getOption(EditorOption.find).findSearchHistory;
this._findWidgetSearchHistory = new FindWidgetSearchHistory(
this._storageService,
findSearchHistoryConfig === 'editor' ? this._codeEditor : undefined
);

this._ctrlEnterReplaceAllWarningPrompted = !!storageService.getBoolean(ctrlEnterReplaceAllWarningPromptedKey, StorageScope.PROFILE);

Expand Down Expand Up @@ -970,7 +974,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
showHistoryHint: () => showHistoryKeybindingHint(this._keybindingService),
inputBoxStyles: defaultInputBoxStyles,
toggleStyles: defaultToggleStyles,
history: findSearchHistoryConfig === 'workspace' ? this._findWidgetSearchHistory : new Set([]),
history: findSearchHistoryConfig === 'never' ? new Set([]) : this._findWidgetSearchHistory,
}, this._contextKeyService));
this._findInput.setRegex(!!this._state.isRegex);
this._findInput.setCaseSensitive(!!this._state.matchCase);
Expand Down
18 changes: 15 additions & 3 deletions src/vs/editor/contrib/find/browser/findWidgetSearchHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@

import { IHistory } from '../../../../base/common/history.js';
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
import { ICodeEditor } from '../../../browser/editorBrowser.js';

export class FindWidgetSearchHistory implements IHistory<string> {
public static readonly FIND_HISTORY_KEY = 'workbench.find.history';
private static readonly FIND_HISTORY_KEY = 'workbench.find.history';
private readonly id: string;
private inMemoryValues: Set<string> = new Set();

constructor(
@IStorageService private readonly storageService: IStorageService,
codeEditor?: ICodeEditor,
) {
this.load();
if (codeEditor) {
this.id = `${FindWidgetSearchHistory.FIND_HISTORY_KEY}.${codeEditor.getId()}`;
// The editor id could be re-used, so we need to clean the storage when it gets disposed
codeEditor.onDidDispose(() => {
this.clear();
});
} else {
this.id = FindWidgetSearchHistory.FIND_HISTORY_KEY;
}
}

delete(t: string): boolean {
Expand Down Expand Up @@ -50,7 +62,7 @@ export class FindWidgetSearchHistory implements IHistory<string> {
load() {
let result: [] | undefined;
const raw = this.storageService.get(
FindWidgetSearchHistory.FIND_HISTORY_KEY,
this.id,
StorageScope.WORKSPACE
);

Expand All @@ -71,7 +83,7 @@ export class FindWidgetSearchHistory implements IHistory<string> {
this.inMemoryValues.forEach(e => elements.push(e));
return new Promise<void>(resolve => {
this.storageService.store(
FindWidgetSearchHistory.FIND_HISTORY_KEY,
this.id,
JSON.stringify(elements),
StorageScope.WORKSPACE,
StorageTarget.USER,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4064,7 +4064,7 @@ declare namespace monaco.editor {
/**
* Controls how the find widget search history should be stored
*/
findSearchHistory?: 'never' | 'workspace';
findSearchHistory?: 'never' | 'workspace' | 'editor';
}

export type GoToLocationValues = 'peek' | 'gotoAndPeek' | 'goto';
Expand Down
Loading