提交 16bc93d1 编写于 作者: A Alex Dima

Do not leak _resolvedColor

上级 8021f0f4
......@@ -16,7 +16,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import * as strings from 'vs/base/common/strings';
import { CharCode } from 'vs/base/common/charCode';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { ThemeColor, ITheme } from 'vs/platform/theme/common/themeService';
import { IntervalNode, IntervalTree, recomputeMaxEnd, getNodeIsInOverviewRuler } from 'vs/editor/common/model/intervalTree';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { StopWatch } from 'vs/base/common/stopwatch';
......@@ -2784,7 +2784,7 @@ export class ModelDecorationOverviewRulerOptions implements model.IModelDecorati
readonly color: string | ThemeColor;
readonly darkColor: string | ThemeColor;
readonly position: model.OverviewRulerLane;
_resolvedColor: string;
private _resolvedColor: string;
constructor(options: model.IModelDecorationOverviewRulerOptions) {
this.color = strings.empty;
......@@ -2804,7 +2804,29 @@ export class ModelDecorationOverviewRulerOptions implements model.IModelDecorati
if (options && typeof options.position === 'number') {
this.position = options.position;
}
// console.log(this);
}
public getColor(theme: ITheme): string {
if (!this._resolvedColor) {
const color = (theme.type === 'light' ? this.color : this.darkColor);
this._resolvedColor = this._resolveColor(color, theme);
}
return this._resolvedColor;
}
public invalidateCachedColor(): void {
this._resolvedColor = null;
}
private _resolveColor(color: string | ThemeColor, theme: ITheme): string {
if (typeof color === 'string') {
return color;
}
let c = color ? theme.getColor(color.id) : null;
if (!c) {
return strings.empty;
}
return c.toString();
}
}
......
......@@ -12,8 +12,7 @@ import { ViewLineData, ICoordinatesConverter, IOverviewRulerDecorations } from '
import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { WrappingIndent } from 'vs/editor/common/config/editorOptions';
import { ModelDecorationOptions, ModelDecorationOverviewRulerOptions } from 'vs/editor/common/model/textModel';
import { ThemeColor, ITheme } from 'vs/platform/theme/common/themeService';
import { Color } from 'vs/base/common/color';
import { ITheme } from 'vs/platform/theme/common/themeService';
import { IModelDecoration, ITextModel, IModelDeltaDecoration, EndOfLinePreference, IActiveIndentGuideInfo } from 'vs/editor/common/model';
export class OutputPosition {
......@@ -797,7 +796,7 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
if (lane === 0) {
continue;
}
const color = resolveColor(opts, theme);
const color = opts.getColor(theme);
const viewStartLineNumber = this._getViewLineNumberForModelPosition(decoration.range.startLineNumber, decoration.range.startColumn);
const viewEndLineNumber = this._getViewLineNumberForModelPosition(decoration.range.endLineNumber, decoration.range.endColumn);
......@@ -1360,7 +1359,7 @@ export class IdentityLinesCollection implements IViewModelLinesCollection {
if (lane === 0) {
continue;
}
const color = resolveColor(opts, theme);
const color = opts.getColor(theme);
const viewStartLineNumber = decoration.range.startLineNumber;
const viewEndLineNumber = decoration.range.endLineNumber;
......@@ -1402,24 +1401,3 @@ class OverviewRulerDecorations {
}
}
}
function resolveColor(opts: ModelDecorationOverviewRulerOptions, theme: ITheme): string {
if (!opts._resolvedColor) {
const themeType = theme.type;
const color = (themeType === 'light' ? opts.color : opts.darkColor);
opts._resolvedColor = resolveRulerColor(color, theme);
}
return opts._resolvedColor;
}
function resolveRulerColor(color: string | ThemeColor, theme: ITheme): string {
if (typeof color === 'string') {
return color;
}
let c = color ? theme.getColor(color.id) : null;
if (!c) {
c = Color.transparent;
}
return c.toString();
}
......@@ -540,7 +540,7 @@ export class ViewModel extends viewEvents.ViewEventEmitter implements IViewModel
const decoration = decorations[i];
const opts = <ModelDecorationOverviewRulerOptions>decoration.options.overviewRuler;
if (opts) {
opts._resolvedColor = null;
opts.invalidateCachedColor();
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册