mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Feature: change font family of inline completions (#202671)
Feature: change font family of inline completions --------- Co-authored-by: Henning Dieterichs <notify.henning.dieterichs@live.de>
This commit is contained in:
committed by
GitHub
parent
04f554b0af
commit
284417d02a
@@ -927,6 +927,38 @@ export function isGlobalStylesheet(node: Node): boolean {
|
||||
return globalStylesheets.has(node as HTMLStyleElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* A version of createStyleSheet which has a unified API to initialize/set the style content.
|
||||
*/
|
||||
export function createStyleSheet2(): WrappedStyleElement {
|
||||
return new WrappedStyleElement();
|
||||
}
|
||||
|
||||
class WrappedStyleElement {
|
||||
private _currentCssStyle = '';
|
||||
private _styleSheet: HTMLStyleElement | undefined = undefined;
|
||||
|
||||
public setStyle(cssStyle: string): void {
|
||||
if (cssStyle !== this._currentCssStyle) {
|
||||
return;
|
||||
}
|
||||
this._currentCssStyle = cssStyle;
|
||||
|
||||
if (!this._styleSheet) {
|
||||
this._styleSheet = createStyleSheet(mainWindow.document.head, (s) => s.innerText = cssStyle);
|
||||
} else {
|
||||
this._styleSheet.innerText = cssStyle;
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this._styleSheet) {
|
||||
clearNode(this._styleSheet);
|
||||
this._styleSheet = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createStyleSheet(container: HTMLElement = mainWindow.document.head, beforeAppend?: (style: HTMLStyleElement) => void, disposableStore?: DisposableStore): HTMLStyleElement {
|
||||
const style = document.createElement('style');
|
||||
style.type = 'text/css';
|
||||
|
||||
@@ -3993,6 +3993,11 @@ export interface IInlineSuggestOptions {
|
||||
* Does not clear active inline suggestions when the editor loses focus.
|
||||
*/
|
||||
keepOnBlur?: boolean;
|
||||
|
||||
/**
|
||||
* Font family for inline suggestions.
|
||||
*/
|
||||
fontFamily?: string | 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4011,6 +4016,7 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
|
||||
showToolbar: 'onHover',
|
||||
suppressSuggestions: false,
|
||||
keepOnBlur: false,
|
||||
fontFamily: 'default'
|
||||
};
|
||||
|
||||
super(
|
||||
@@ -4037,6 +4043,11 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
|
||||
default: defaults.suppressSuggestions,
|
||||
description: nls.localize('inlineSuggest.suppressSuggestions', "Controls how inline suggestions interact with the suggest widget. If enabled, the suggest widget is not shown automatically when inline suggestions are available.")
|
||||
},
|
||||
'editor.inlineSuggest.fontFamily': {
|
||||
type: 'string',
|
||||
default: defaults.fontFamily,
|
||||
description: nls.localize('inlineSuggest.fontFamily', "Controls the font family of the inline suggestions.")
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -4052,6 +4063,7 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
|
||||
showToolbar: stringSet(input.showToolbar, this.defaultValue.showToolbar, ['always', 'onHover', 'never']),
|
||||
suppressSuggestions: boolean(input.suppressSuggestions, this.defaultValue.suppressSuggestions),
|
||||
keepOnBlur: boolean(input.keepOnBlur, this.defaultValue.keepOnBlur),
|
||||
fontFamily: EditorStringOption.string(input.fontFamily, this.defaultValue.fontFamily)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createStyleSheet2 } from 'vs/base/browser/dom';
|
||||
import { alert } from 'vs/base/browser/ui/aria/aria';
|
||||
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ITransaction, autorun, autorunHandleChanges, constObservable, derived, disposableObservableValue, observableFromEvent, observableSignal, observableValue, transaction } from 'vs/base/common/observable';
|
||||
@@ -52,6 +53,7 @@ export class InlineCompletionsController extends Disposable {
|
||||
}
|
||||
));
|
||||
private readonly _enabled = observableFromEvent(this.editor.onDidChangeConfiguration, () => this.editor.getOption(EditorOption.inlineSuggest).enabled);
|
||||
private readonly _fontFamily = observableFromEvent(this.editor.onDidChangeConfiguration, () => this.editor.getOption(EditorOption.inlineSuggest).fontFamily);
|
||||
|
||||
private _ghostTextWidget = this._register(this._instantiationService.createInstance(GhostTextWidget, this.editor, {
|
||||
ghostText: this.model.map((v, reader) => /** ghostText */ v?.ghostText.read(reader)),
|
||||
@@ -112,6 +114,17 @@ export class InlineCompletionsController extends Disposable {
|
||||
});
|
||||
}));
|
||||
|
||||
const styleElement = this._register(createStyleSheet2());
|
||||
this._register(autorun(reader => {
|
||||
const fontFamily = this._fontFamily.read(reader);
|
||||
styleElement.setStyle(fontFamily === '' || fontFamily === 'default' ? `` : `
|
||||
.monaco-editor .ghost-text-decoration,
|
||||
.monaco-editor .ghost-text-decoration-preview,
|
||||
.monaco-editor .ghost-text {
|
||||
font-family: ${fontFamily};
|
||||
}`);
|
||||
}));
|
||||
|
||||
const getReason = (e: IModelContentChangedEvent): VersionIdChangeReason => {
|
||||
if (e.isUndoing) { return VersionIdChangeReason.Undo; }
|
||||
if (e.isRedoing) { return VersionIdChangeReason.Redo; }
|
||||
|
||||
Vendored
+4
@@ -4502,6 +4502,10 @@ declare namespace monaco.editor {
|
||||
* Does not clear active inline suggestions when the editor loses focus.
|
||||
*/
|
||||
keepOnBlur?: boolean;
|
||||
/**
|
||||
* Font family for inline suggestions.
|
||||
*/
|
||||
fontFamily?: string | 'default';
|
||||
}
|
||||
|
||||
export interface IBracketPairColorizationOptions {
|
||||
|
||||
Reference in New Issue
Block a user