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

[pull] main from microsoft:main #420

Merged
merged 5 commits into from
Jan 24, 2025
Merged
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/base/browser/ui/findinput/replaceInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { KeyCode } from '../../../common/keyCodes.js';
import './findInput.css';
import * as nls from '../../../../nls.js';
import { getDefaultHoverDelegate } from '../hover/hoverDelegateFactory.js';
import { IHistory } from '../../../common/history.js';


export interface IReplaceInputOptions {
Expand All @@ -29,7 +30,7 @@ export interface IReplaceInputOptions {
readonly flexibleMaxHeight?: number;

readonly appendPreserveCaseLabel?: string;
readonly history?: string[];
readonly history?: IHistory<string>;
readonly showHistoryHint?: () => boolean;
readonly inputBoxStyles: IInputBoxStyles;
readonly toggleStyles: IToggleStyles;
Expand Down Expand Up @@ -94,7 +95,7 @@ export class ReplaceInput extends Widget {
this.label = options.label || NLS_DEFAULT_LABEL;

const appendPreserveCaseLabel = options.appendPreserveCaseLabel || '';
const history = options.history || [];
const history = options.history || new Set([]);
const flexibleHeight = !!options.flexibleHeight;
const flexibleWidth = !!options.flexibleWidth;
const flexibleMaxHeight = options.flexibleMaxHeight;
Expand All @@ -108,7 +109,7 @@ export class ReplaceInput extends Widget {
validationOptions: {
validation: this.validation
},
history: new Set(history),
history,
showHistoryHint: options.showHistoryHint,
flexibleHeight,
flexibleWidth,
Expand Down
23 changes: 20 additions & 3 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,12 @@ export interface IEditorFindOptions {
* @internal
* Controls how the find widget search history should be stored
*/
history?: 'never' | 'workspace';
findHistory?: 'never' | 'workspace';
/**
* @internal
* Controls how the find widget search history should be stored
*/
replaceHistory?: 'never' | 'workspace';
}

/**
Expand All @@ -1688,7 +1693,8 @@ class EditorFind extends BaseEditorOption<EditorOption.find, IEditorFindOptions,
globalFindClipboard: false,
addExtraSpaceOnTop: true,
loop: true,
history: 'workspace',
findHistory: 'workspace',
replaceHistory: 'workspace',
};
super(
EditorOption.find, 'find', defaults,
Expand Down Expand Up @@ -1745,6 +1751,16 @@ class EditorFind extends BaseEditorOption<EditorOption.find, IEditorFindOptions,
nls.localize('editor.find.history.workspace', 'Store search history across the active workspace'),
],
description: nls.localize('find.history', "Controls how the find widget history should be stored")
},
'editor.replace.history': {
type: 'string',
enum: ['never', 'workspace'],
default: 'workspace',
enumDescriptions: [
nls.localize('editor.replace.history.never', 'Do not store history from the replace widget.'),
nls.localize('editor.replace.history.workspace', 'Store replace history across the active workspace'),
],
description: nls.localize('replace.history', "Controls how the replace widget history should be stored")
}
}
);
Expand All @@ -1766,7 +1782,8 @@ 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),
history: stringSet<'never' | 'workspace'>(input.history, this.defaultValue.history, ['never', 'workspace']),
findHistory: stringSet<'never' | 'workspace'>(input.findHistory, this.defaultValue.findHistory, ['never', 'workspace']),
replaceHistory: stringSet<'never' | 'workspace'>(input.replaceHistory, this.defaultValue.replaceHistory, ['never', 'workspace']),
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/vs/editor/contrib/find/browser/findController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { IThemeService, themeColorFromId } from '../../../../platform/theme/comm
import { Selection } from '../../../common/core/selection.js';
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
import { FindWidgetSearchHistory } from './findWidgetSearchHistory.js';
import { ReplaceWidgetHistory } from './replaceWidgetHistory.js';

const SEARCH_STRING_MAX_LENGTH = 524288;

Expand Down Expand Up @@ -444,6 +445,7 @@ export class FindController extends CommonFindController implements IFindControl
private _widget: FindWidget | null;
private _findOptionsWidget: FindOptionsWidget | null;
private _findWidgetSearchHistory: FindWidgetSearchHistory;
private _replaceWidgetHistory: ReplaceWidgetHistory;

constructor(
editor: ICodeEditor,
Expand All @@ -460,6 +462,7 @@ export class FindController extends CommonFindController implements IFindControl
this._widget = null;
this._findOptionsWidget = null;
this._findWidgetSearchHistory = FindWidgetSearchHistory.getOrCreate(_storageService);
this._replaceWidgetHistory = ReplaceWidgetHistory.getOrCreate(_storageService);
}

protected override async _start(opts: IFindStartOptions, newState?: INewFindReplaceState): Promise<void> {
Expand Down Expand Up @@ -511,7 +514,7 @@ export class FindController extends CommonFindController implements IFindControl
}

private _createFindWidget() {
this._widget = this._register(new FindWidget(this._editor, this, this._state, this._contextViewService, this._keybindingService, this._contextKeyService, this._themeService, this._storageService, this._notificationService, this._hoverService, this._findWidgetSearchHistory));
this._widget = this._register(new FindWidget(this._editor, this, this._state, this._contextViewService, this._keybindingService, this._contextKeyService, this._themeService, this._storageService, this._notificationService, this._hoverService, this._findWidgetSearchHistory, this._replaceWidgetHistory));
this._findOptionsWidget = this._register(new FindOptionsWidget(this._editor, this._state, this._keybindingService));
}

Expand Down
8 changes: 5 additions & 3 deletions src/vs/editor/contrib/find/browser/findWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
notificationService: INotificationService,
private readonly _hoverService: IHoverService,
private readonly _findWidgetSearchHistory: IHistory<string> | undefined,
private readonly _replaceWidgetHistory: IHistory<string> | undefined,
) {
super();
this._codeEditor = codeEditor;
Expand Down Expand Up @@ -941,7 +942,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
const flexibleHeight = true;
const flexibleWidth = true;
// Find input
const findSearchHistoryConfig = this._codeEditor.getOption(EditorOption.find).history;
const findSearchHistoryConfig = this._codeEditor.getOption(EditorOption.find).findHistory;
const replaceHistoryConfig = this._codeEditor.getOption(EditorOption.find).replaceHistory;
this._findInput = this._register(new ContextScopedFindInput(null, this._contextViewProvider, {
width: FIND_INPUT_AREA_WIDTH,
label: NLS_FIND_INPUT_LABEL,
Expand Down Expand Up @@ -1112,13 +1114,13 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
label: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
appendPreserveCaseLabel: this._keybindingLabelFor(FIND_IDS.TogglePreserveCaseCommand),
history: [],
history: replaceHistoryConfig === 'workspace' ? this._replaceWidgetHistory : new Set([]),
flexibleHeight,
flexibleWidth,
flexibleMaxHeight: 118,
showHistoryHint: () => showHistoryKeybindingHint(this._keybindingService),
inputBoxStyles: defaultInputBoxStyles,
toggleStyles: defaultToggleStyles
toggleStyles: defaultToggleStyles,
}, this._contextKeyService, true));
this._replaceInput.setPreserveCase(!!this._state.preserveCase);
this._register(this._replaceInput.onKeyDown((e) => this._onReplaceInputKeyDown(e)));
Expand Down
99 changes: 99 additions & 0 deletions src/vs/editor/contrib/find/browser/replaceWidgetHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Emitter, Event } from '../../../../base/common/event.js';
import { IHistory } from '../../../../base/common/history.js';
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';

export class ReplaceWidgetHistory implements IHistory<string> {
public static readonly FIND_HISTORY_KEY = 'workbench.replace.history';
private inMemoryValues: Set<string> = new Set();
public onDidChange?: Event<string[]>;
private _onDidChangeEmitter: Emitter<string[]>;

private static _instance: ReplaceWidgetHistory | null = null;

static getOrCreate(
storageService: IStorageService,
): ReplaceWidgetHistory {
if (!ReplaceWidgetHistory._instance) {
ReplaceWidgetHistory._instance = new ReplaceWidgetHistory(storageService);
}
return ReplaceWidgetHistory._instance;
}

constructor(
@IStorageService private readonly storageService: IStorageService,
) {
this._onDidChangeEmitter = new Emitter<string[]>();
this.onDidChange = this._onDidChangeEmitter.event;
this.load();
}

delete(t: string): boolean {
const result = this.inMemoryValues.delete(t);
this.save();
return result;
}

add(t: string): this {
this.inMemoryValues.add(t);
this.save();
return this;
}

has(t: string): boolean {
return this.inMemoryValues.has(t);
}

clear(): void {
this.inMemoryValues.clear();
this.save();
}

forEach(callbackfn: (value: string, value2: string, set: Set<string>) => void, thisArg?: any): void {
// fetch latest from storage
this.load();
return this.inMemoryValues.forEach(callbackfn);
}
replace?(t: string[]): void {
this.inMemoryValues = new Set(t);
this.save();
}

load() {
let result: [] | undefined;
const raw = this.storageService.get(
ReplaceWidgetHistory.FIND_HISTORY_KEY,
StorageScope.WORKSPACE
);

if (raw) {
try {
result = JSON.parse(raw);
} catch (e) {
// Invalid data
}
}

this.inMemoryValues = new Set(result || []);
}

// Run saves async
save(): Promise<void> {
const elements: string[] = [];
this.inMemoryValues.forEach(e => elements.push(e));
return new Promise<void>(resolve => {
this.storageService.store(
ReplaceWidgetHistory.FIND_HISTORY_KEY,
JSON.stringify(elements),
StorageScope.WORKSPACE,
StorageTarget.USER,
);
this._onDidChangeEmitter.fire(elements);
resolve();
});
}
}
3 changes: 3 additions & 0 deletions src/vs/workbench/api/browser/mainThreadTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
for (const instance of this._terminalService.instances) {
this._onTerminalOpened(instance);
instance.processReady.then(() => this._onTerminalProcessIdReady(instance));
if (instance.shellType) {
this._proxy.$acceptTerminalShellType(instance.instanceId, instance.shellType);
}
}
const activeInstance = this._terminalService.activeInstance;
if (activeInstance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export abstract class SimpleFindReplaceWidget extends Widget {
this._replaceInput = this._register(new ContextScopedReplaceInput(null, undefined, {
label: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
history: [],
history: new Set([]),
inputBoxStyles: defaultInputBoxStyles,
toggleStyles: defaultToggleStyles
}, contextKeyService, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
display: inline-block;
line-height: 24px;
min-height: 24px;
flex: none;
}

/* Use monospace to display glob patterns in include/exclude widget */
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export class SearchWidget extends Widget {
label: nls.localize('label.Replace', 'Replace: Type replace term and press Enter to preview'),
placeholder: nls.localize('search.replace.placeHolder', "Replace"),
appendPreserveCaseLabel: appendKeyBindingLabel('', this.keybindingService.lookupKeybinding(Constants.SearchCommandIds.TogglePreserveCaseId)),
history: options.replaceHistory,
history: new Set(options.replaceHistory),
showHistoryHint: () => showHistoryKeybindingHint(this.keybindingService),
flexibleHeight: true,
flexibleMaxHeight: SearchWidget.INPUT_MAX_HEIGHT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
const fontInfo: ISimpleSuggestWidgetFontInfo = {
fontFamily: font.fontFamily,
fontSize: font.fontSize,
lineHeight: Math.ceil(1.5 * font.fontSize),
// In the editor's world, lineHeight is the pixels between the baselines of two lines of text
// In the terminal's world, lineHeight is the multiplier of the font size
// 1.5 is needed so that it's taller than a 16px icon
lineHeight: Math.ceil(c.lineHeight * font.fontSize * 1.5),
fontWeight: c.fontWeight.toString(),
letterSpacing: font.letterSpacing
};
Expand Down
11 changes: 8 additions & 3 deletions src/vs/workbench/services/suggest/browser/simpleSuggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { IConfigurationService } from '../../../../platform/configuration/common
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
import { canExpandCompletionItem, SimpleSuggestDetailsOverlay, SimpleSuggestDetailsWidget } from './simpleSuggestWidgetDetails.js';
import { IContextKey, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { TerminalSettingId } from '../../../../platform/terminal/common/terminal.js';

const $ = dom.$;

Expand Down Expand Up @@ -179,7 +180,7 @@ export class SimpleSuggestWidget extends Disposable {
const applyIconStyle = () => this.element.domNode.classList.toggle('no-icons', !_configurationService.getValue('editor.suggest.showIcons'));
applyIconStyle();

const renderer = new SimpleSuggestWidgetItemRenderer(_getFontInfo);
const renderer = new SimpleSuggestWidgetItemRenderer(_getFontInfo, this._configurationService);
this._register(renderer);
this._listElement = dom.append(this.element.domNode, $('.tree'));
this._list = this._register(new List('SuggestWidget', this._listElement, {
Expand Down Expand Up @@ -246,6 +247,10 @@ export class SimpleSuggestWidget extends Disposable {
if (e.affectsConfiguration('editor.suggest.showIcons')) {
applyIconStyle();
}
if (this._completionModel && e.affectsConfiguration(TerminalSettingId.FontSize) || e.affectsConfiguration(TerminalSettingId.LineHeight) || e.affectsConfiguration(TerminalSettingId.FontFamily)) {
this._layout(undefined);
this._list.splice(0, this._list.length, this._completionModel!.items);
}
if (_options.statusBarMenuId && _options.showStatusBarSettingId && e.affectsConfiguration(_options.showStatusBarSettingId)) {
const showStatusBar: boolean = _configurationService.getValue(_options.showStatusBarSettingId);
if (showStatusBar && !this._status) {
Expand Down Expand Up @@ -764,9 +769,9 @@ export class SimpleSuggestWidget extends Disposable {

private _getLayoutInfo() {
const fontInfo = this._getFontInfo();
const itemHeight = clamp(Math.ceil(fontInfo.lineHeight), 8, 1000);
const itemHeight = clamp(fontInfo.lineHeight, 8, 1000);
const statusBarHeight = !this._options.statusBarMenuId || !this._options.showStatusBarSettingId || !this._configurationService.getValue(this._options.showStatusBarSettingId) || this._state === State.Empty || this._state === State.Loading ? 0 : itemHeight;
const borderWidth = 1; //this._details.widget.borderWidth;
const borderWidth = this._details.widget.borderWidth;
const borderHeight = 2 * borderWidth;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Emitter, Event } from '../../../../base/common/event.js';
import { createMatches } from '../../../../base/common/filters.js';
import { DisposableStore } from '../../../../base/common/lifecycle.js';
import { ThemeIcon } from '../../../../base/common/themables.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { TerminalSettingId } from '../../../../platform/terminal/common/terminal.js';

export function getAriaId(index: number): string {
return `simple-suggest-aria-id-${index}`;
Expand Down Expand Up @@ -55,13 +57,16 @@ export class SimpleSuggestWidgetItemRenderer implements IListRenderer<SimpleComp
private readonly _onDidToggleDetails = new Emitter<void>();
readonly onDidToggleDetails: Event<void> = this._onDidToggleDetails.event;

private readonly _disposables = new DisposableStore();

readonly templateId = 'suggestion';

constructor(private readonly _getFontInfo: () => ISimpleSuggestWidgetFontInfo) {
constructor(private readonly _getFontInfo: () => ISimpleSuggestWidgetFontInfo, @IConfigurationService private readonly _configurationService: IConfigurationService) {
}

dispose(): void {
this._onDidToggleDetails.dispose();
this._disposables.dispose();
}

renderTemplate(container: HTMLElement): ISimpleSuggestionTemplateData {
Expand Down Expand Up @@ -111,11 +116,11 @@ export class SimpleSuggestWidgetItemRenderer implements IListRenderer<SimpleComp

configureFont();

// data.disposables.add(this._editor.onDidChangeConfiguration(e => {
// if (e.hasChanged(EditorOption.fontInfo) || e.hasChanged(EditorOption.suggestFontSize) || e.hasChanged(EditorOption.suggestLineHeight)) {
// configureFont();
// }
// }));
this._disposables.add(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(TerminalSettingId.FontSize) || e.affectsConfiguration(TerminalSettingId.FontFamily) || e.affectsConfiguration(TerminalSettingId.FontWeight) || e.affectsConfiguration(TerminalSettingId.LineHeight)) {
configureFont();
}
}));

return { root, left, right, icon, colorspan, iconLabel, iconContainer, parametersLabel, qualifierLabel, detailsLabel, disposables };
}
Expand Down
Loading