Skip to content

Commit bfc669b

Browse files
committed
Inherit font from terminal for suggest
Fixes microsoft#210597
1 parent 12f9169 commit bfc669b

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { IPromptInputModel, IPromptInputModelState } from 'vs/platform/term
2121
import { ShellIntegrationOscPs } from 'vs/platform/terminal/common/xterm/shellIntegrationAddon';
2222
import { getListStyles } from 'vs/platform/theme/browser/defaultStyles';
2323
import { activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
24+
import { ITerminalConfigurationService } from 'vs/workbench/contrib/terminal/browser/terminal';
2425
import type { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
2526
import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys';
2627
import { terminalSuggestConfigSection, type ITerminalSuggestConfiguration } from 'vs/workbench/contrib/terminalContrib/suggest/common/terminalSuggestConfiguration';
@@ -140,6 +141,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
140141
private readonly _terminalSuggestWidgetVisibleContextKey: IContextKey<boolean>,
141142
@IConfigurationService private readonly _configurationService: IConfigurationService,
142143
@IInstantiationService private readonly _instantiationService: IInstantiationService,
144+
@ITerminalConfigurationService private readonly _terminalConfigurationService: ITerminalConfigurationService,
143145
) {
144146
super();
145147

@@ -499,6 +501,17 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
499501
SimpleSuggestWidget,
500502
this._panel!,
501503
this._instantiationService.createInstance(PersistedWidgetSize),
504+
() => {
505+
const c = this._terminalConfigurationService.config;
506+
const font = this._terminalConfigurationService.getFont(dom.getActiveWindow());
507+
return {
508+
fontFamily: font.fontFamily,
509+
fontSize: font.fontSize,
510+
lineHeight: Math.ceil(1.5 * font.fontSize),
511+
fontWeight: c.fontWeight.toString(),
512+
letterSpacing: font.letterSpacing
513+
};
514+
},
502515
{}
503516
));
504517
this._suggestWidget.list.style(getListStyles({

src/vs/workbench/services/suggest/browser/simpleSuggestWidget.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class SimpleSuggestWidget extends Disposable {
8484
constructor(
8585
private readonly _container: HTMLElement,
8686
private readonly _persistedSize: IPersistedWidgetSizeDelegate,
87+
private readonly _getFontInfo: () => { fontFamily: string; fontSize: number; lineHeight: number; fontWeight: string; letterSpacing: number },
8788
options: IWorkbenchSuggestWidgetOptions,
8889
@IInstantiationService instantiationService: IInstantiationService
8990
) {
@@ -140,7 +141,7 @@ export class SimpleSuggestWidget extends Disposable {
140141
state = undefined;
141142
}));
142143

143-
const renderer = new SimpleSuggestWidgetItemRenderer();
144+
const renderer = new SimpleSuggestWidgetItemRenderer(_getFontInfo);
144145
this._register(renderer);
145146
this._listElement = dom.append(this.element.domNode, $('.tree'));
146147
this._list = this._register(new List('SuggestWidget', this._listElement, {
@@ -503,11 +504,8 @@ export class SimpleSuggestWidget extends Disposable {
503504
}
504505

505506
private _getLayoutInfo() {
506-
const fontInfo = {
507-
lineHeight: 20,
508-
typicalHalfwidthCharacterWidth: 10
509-
}; //this.editor.getOption(EditorOption.fontInfo);
510-
const itemHeight = clamp(fontInfo.lineHeight, 8, 1000);
507+
const fontInfo = this._getFontInfo();
508+
const itemHeight = clamp(Math.ceil(fontInfo.lineHeight), 8, 1000);
511509
const statusBarHeight = 0; //!this.editor.getOption(EditorOption.suggest).showStatusBar || this._state === State.Empty || this._state === State.Loading ? 0 : itemHeight;
512510
const borderWidth = 1; //this._details.widget.borderWidth;
513511
const borderHeight = 2 * borderWidth;
@@ -517,7 +515,7 @@ export class SimpleSuggestWidget extends Disposable {
517515
statusBarHeight,
518516
borderWidth,
519517
borderHeight,
520-
typicalHalfwidthCharacterWidth: fontInfo.typicalHalfwidthCharacterWidth,
518+
typicalHalfwidthCharacterWidth: 10,
521519
verticalPadding: 22,
522520
horizontalPadding: 14,
523521
defaultSize: new dom.Dimension(430, statusBarHeight + 12 * itemHeight + borderHeight)

src/vs/workbench/services/suggest/browser/simpleSuggestWidgetRenderer.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export class SimpleSuggestWidgetItemRenderer implements IListRenderer<SimpleComp
4949

5050
readonly templateId = 'suggestion';
5151

52+
constructor(private readonly _getFontInfo: () => { fontFamily: string; fontSize: number; lineHeight: number; fontWeight: string; letterSpacing: number }) {
53+
}
54+
5255
dispose(): void {
5356
this._onDidToggleDetails.dispose();
5457
}
@@ -80,15 +83,8 @@ export class SimpleSuggestWidgetItemRenderer implements IListRenderer<SimpleComp
8083
// readMore.title = nls.localize('readMore', "Read More");
8184

8285
const configureFont = () => {
83-
// TODO: Implement
84-
// const options = this._editor.getOptions();
85-
// const fontInfo = options.get(EditorOption.fontInfo);
86-
const fontFamily = 'Hack'; //fontInfo.getMassagedFontFamily();
87-
const fontFeatureSettings = ''; //fontInfo.fontFeatureSettings;
88-
const fontSize = '12'; // = options.get(EditorOption.suggestFontSize) || fontInfo.fontSize;
89-
const lineHeight = '20'; // options.get(EditorOption.suggestLineHeight) || fontInfo.lineHeight;
90-
const fontWeight = 'normal'; //fontInfo.fontWeight;
91-
const letterSpacing = '0'; // fontInfo.letterSpacing;
86+
const fontFeatureSettings = '';
87+
const { fontFamily, fontSize, lineHeight, fontWeight, letterSpacing } = this._getFontInfo();
9288
const fontSizePx = `${fontSize}px`;
9389
const lineHeightPx = `${lineHeight}px`;
9490
const letterSpacingPx = `${letterSpacing}px`;

0 commit comments

Comments
 (0)