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 all commits
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 @@ -1659,7 +1659,7 @@ export interface IEditorFindOptions {
/**
* Controls how the find widget search history should be stored
*/
findSearchHistory?: 'never' | 'workspace';
findSearchHistory?: 'never' | 'workspace' | 'editorGroup';
}

/**
Expand Down Expand Up @@ -1727,11 +1727,12 @@ class EditorFind extends BaseEditorOption<EditorOption.find, IEditorFindOptions,
},
'editor.find.history': {
type: 'string',
enum: ['never', 'workspace'],
enum: ['never', 'workspace', 'editorGroup'],
default: typeof product.quality === 'string' && product.quality !== 'stable' ? 'workspace' : 'none',
enumDescriptions: [
nls.localize('editor.find.history.never', 'Do not store search history from the find widget.'),
nls.localize('editor.find.history.workspace', 'Store search history across the active workspace'),
nls.localize('editor.find.history.editorGroup', 'Store the search history per editor group'),
],
description: nls.localize('find.history', "Controls how the find widget history should be stored")
}
Expand All @@ -1755,7 +1756,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' | 'editorGroup'>(input.findSearchHistory, this.defaultValue.findSearchHistory, ['never', 'workspace', 'editorGroup']),
};
}
}
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 === 'editorGroup' ? 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' | 'editorGroup';
}

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