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

Use the editor font size for the breakpoint widget #83153

Merged
merged 2 commits into from
Oct 23, 2019
Merged
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
36 changes: 34 additions & 2 deletions src/vs/workbench/contrib/debug/browser/breakpointWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
import { getSimpleEditorOptions, getSimpleCodeEditorWidgetOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
import { IRange, Range } from 'vs/editor/common/core/range';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions';

const $ = dom.$;
const IPrivateBreakpointWidgetService = createDecorator<IPrivateBreakpointWidgetService>('privateBreakpointWidgetService');
Expand All @@ -48,13 +50,15 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
_serviceBrand: undefined;

private selectContainer!: HTMLElement;
private inputContainer!: HTMLElement;
private input!: IActiveCodeEditor;
private toDispose: lifecycle.IDisposable[];
private conditionInput = '';
private hitCountInput = '';
private logMessageInput = '';
private breakpoint: IBreakpoint | undefined;
private context: Context;
private heightInPx: number;

constructor(editor: ICodeEditor, private lineNumber: number, private column: number | undefined, context: Context | undefined,
@IContextViewService private readonly contextViewService: IContextViewService,
Expand All @@ -64,6 +68,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IModelService private readonly modelService: IModelService,
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super(editor, { showFrame: true, showArrow: false, frameWidth: 1 });

Expand Down Expand Up @@ -141,6 +146,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
fitHeightToContent(): void {
const lineNum = this.input.getModel().getLineCount();
this._relayout(lineNum + 1);
this.centerInputVertically();
anirudhrb marked this conversation as resolved.
Show resolved Hide resolved
}

protected _fillContainer(container: HTMLElement): void {
Expand All @@ -158,7 +164,8 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
this.input.focus();
});

this.createBreakpointInput(dom.append(container, $('.inputContainer')));
this.inputContainer = $('.inputContainer');
this.createBreakpointInput(dom.append(container, this.inputContainer));

this.input.getModel().setValue(this.getInputValue(this.breakpoint));
this.toDispose.push(this.input.getModel().onDidChangeContent(() => {
Expand All @@ -170,7 +177,9 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
}

protected _doLayout(heightInPixel: number, widthInPixel: number): void {
this.heightInPx = heightInPixel;
this.input.layout({ height: heightInPixel, width: widthInPixel - 113 });
this.centerInputVertically();
}

private createBreakpointInput(container: HTMLElement): void {
Expand All @@ -180,7 +189,7 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
const scopedInstatiationService = this.instantiationService.createChild(new ServiceCollection(
[IContextKeyService, scopedContextKeyService], [IPrivateBreakpointWidgetService, this]));

const options = getSimpleEditorOptions();
const options = this.createEditorOptions();
const codeEditorWidgetOptions = getSimpleCodeEditorWidgetOptions();
this.input = <IActiveCodeEditor>scopedInstatiationService.createInstance(CodeEditorWidget, container, options, codeEditorWidgetOptions);
CONTEXT_IN_BREAKPOINT_WIDGET.bindTo(scopedContextKeyService).set(true);
Expand Down Expand Up @@ -227,6 +236,29 @@ export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWi
return suggestionsPromise;
}
}));

this.toDispose.push(this._configurationService.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('editor.fontSize')) {
anirudhrb marked this conversation as resolved.
Show resolved Hide resolved
this.input.updateOptions(this.createEditorOptions());
this.centerInputVertically();
}
}));
}

private createEditorOptions(): IEditorOptions {
const editorConfig = this._configurationService.getValue<IEditorOptions>('editor');
const options = getSimpleEditorOptions();
options.fontSize = editorConfig.fontSize;
return options;
}

private centerInputVertically() {
if (this.container) {
const lineHeight = this.input.getOption(EditorOption.lineHeight);
const lineNum = this.input.getModel().getLineCount();
const newTopMargin = (this.heightInPx - lineNum * lineHeight) / 2;
this.inputContainer.style.marginTop = newTopMargin + 'px';
anirudhrb marked this conversation as resolved.
Show resolved Hide resolved
}
}

private createDecorations(): IDecorationOptions[] {
Expand Down