Skip to content

Commit

Permalink
Add monaco.editor.remeasureFonts (microsoft/monaco-editor#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Mar 2, 2019
1 parent 5698d79 commit f253672
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/vs/editor/browser/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class CSSBasedConfigurationCache {
}
}

export function clearAllFontInfos(): void {
CSSBasedConfiguration.INSTANCE.clearCache();
}

export function readFontInfo(bareFontInfo: BareFontInfo): FontInfo {
return CSSBasedConfiguration.INSTANCE.readConfiguration(bareFontInfo);
}
Expand Down Expand Up @@ -122,6 +126,11 @@ class CSSBasedConfiguration extends Disposable {
super.dispose();
}

public clearCache(): void {
this._cache = new CSSBasedConfigurationCache();
this._onDidChange.fire();
}

private _writeToCache(item: BareFontInfo, value: FontInfo): void {
this._cache.put(item, value);

Expand Down
9 changes: 9 additions & 0 deletions src/vs/editor/standalone/browser/standaloneEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { IMarker, IMarkerData } from 'vs/platform/markers/common/markers';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { clearAllFontInfos } from 'vs/editor/browser/config/configuration';

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

Expand Down Expand Up @@ -311,6 +312,13 @@ export function setTheme(themeName: string): void {
StaticServices.standaloneThemeService.get().setTheme(themeName);
}

/**
* Clears all cached font measurements and triggers re-measurement.
*/
export function remeasureFonts(): void {
clearAllFontInfos();
}

/**
* @internal
*/
Expand Down Expand Up @@ -340,6 +348,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
tokenize: <any>tokenize,
defineTheme: <any>defineTheme,
setTheme: <any>setTheme,
remeasureFonts: remeasureFonts,

// enums
ScrollbarVisibility: standaloneEnums.ScrollbarVisibility,
Expand Down
5 changes: 5 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ declare namespace monaco.editor {
*/
export function setTheme(themeName: string): void;

/**
* Clears all cached font measurements and triggers re-measurement.
*/
export function remeasureFonts(): void;

export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black';

export interface IStandaloneThemeData {
Expand Down

0 comments on commit f253672

Please sign in to comment.