Skip to content

Commit

Permalink
have just one editor config listener #63467
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 22, 2018
1 parent a0a6e48 commit 2448fa4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/vs/editor/contrib/codelens/codelensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
this._disposeAllLenses(null, null);
}
}));

this._localToDispose.push(this._editor.onDidChangeConfiguration(e => {
if (e.fontInfo) {
for (const lens of this._lenses) {
lens.updateHeight();
}
}
}));
scheduler.schedule();
}

Expand Down
20 changes: 11 additions & 9 deletions src/vs/editor/contrib/codelens/codelensWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./codelensWidget';
import * as dom from 'vs/base/browser/dom';
import { coalesce, isFalsyOrEmpty } from 'vs/base/common/arrays';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable } from 'vs/base/common/lifecycle';
import { escape, format } from 'vs/base/common/strings';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { Range } from 'vs/editor/common/core/range';
Expand Down Expand Up @@ -60,7 +60,7 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {

private readonly _id: string;
private readonly _domNode: HTMLElement;
private readonly _disposables: IDisposable[] = [];
private readonly _disposable: IDisposable;
private readonly _editor: editorBrowser.ICodeEditor;

private _widgetPosition: editorBrowser.IContentWidgetPosition;
Expand All @@ -82,11 +82,9 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {
this._domNode.innerHTML = ' ';
dom.addClass(this._domNode, 'codelens-decoration');
dom.addClass(this._domNode, 'invisible-cl');
this._updateHeight();
this.updateHeight();

this._disposables.push(this._editor.onDidChangeConfiguration(e => e.fontInfo && this._updateHeight()));

this._disposables.push(dom.addDisposableListener(this._domNode, 'click', e => {
this._disposable = dom.addDisposableListener(this._domNode, 'click', e => {
let element = <HTMLElement>e.target;
if (element.tagName === 'A' && element.id) {
let command = this._commands[element.id];
Expand All @@ -97,16 +95,16 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {
});
}
}
}));
});

this.updateVisibility();
}

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

private _updateHeight(): void {
updateHeight(): void {
const { fontInfo, lineHeight } = this._editor.getConfiguration();
this._domNode.style.height = `${Math.round(lineHeight * 1.1)}px`;
this._domNode.style.lineHeight = `${lineHeight}px`;
Expand Down Expand Up @@ -302,6 +300,10 @@ export class CodeLens {
this._contentWidget.withCommands(symbols);
}

updateHeight(): void {
this._contentWidget.updateHeight();
}

getLineNumber(): number {
const range = this._editor.getModel().getDecorationRange(this._decorationIds[0]);
if (range) {
Expand Down

0 comments on commit 2448fa4

Please sign in to comment.