提交 6023aee9 编写于 作者: A Alex Dima

Reduce usages of IModelDecorationsChangedEvent.changedDecorations

上级 d902ab8a
......@@ -108,20 +108,15 @@ class DecorationsManager implements IDisposable {
}
private _onDecorationChanged(event: IModelDecorationsChangedEvent): void {
const changedDecorations = event.changedDecorations,
toRemove: string[] = [];
const toRemove: string[] = [];
for (let i = 0, len = changedDecorations.length; i < len; i++) {
let reference = this._decorations.get(changedDecorations[i]);
if (!reference) {
continue;
}
this._decorations.forEach((reference, decorationId) => {
const newRange = this._editor.getModel().getDecorationRange(decorationId);
const newRange = this._editor.getModel().getDecorationRange(changedDecorations[i]);
let ignore = false;
if (Range.equalsRange(newRange, reference.range)) {
continue;
return;
} else if (Range.spansMultipleLines(newRange)) {
ignore = true;
......@@ -137,11 +132,11 @@ class DecorationsManager implements IDisposable {
if (ignore) {
this._decorationIgnoreSet.add(reference.id);
toRemove.push(changedDecorations[i]);
toRemove.push(decorationId);
} else {
reference.range = newRange;
}
}
});
this._editor.changeDecorations((accessor) => {
for (let i = 0, len = toRemove.length; i < len; i++) {
......
......@@ -21,7 +21,7 @@ interface IDebugEditorModelData {
toDispose: lifecycle.IDisposable[];
breakpointDecorationIds: string[];
breakpointLines: number[];
breakpointDecorationsAsMap: Map<string, boolean>;
breakpointDecorationsAsMap: Map<string, Range>;
currentStackDecorations: string[];
dirty: boolean;
topStackFrameRange: Range;
......@@ -81,11 +81,12 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
const breakpoints = this.debugService.getModel().getBreakpoints().filter(bp => bp.uri.toString() === modelUrlStr);
const currentStackDecorations = model.deltaDecorations([], this.createCallStackDecorations(modelUrlStr));
const breakPointDecorations = model.deltaDecorations([], this.createBreakpointDecorations(breakpoints));
const desiredDecorations = this.createBreakpointDecorations(model, breakpoints);
const breakPointDecorations = model.deltaDecorations([], desiredDecorations);
const toDispose: lifecycle.IDisposable[] = [model.onDidChangeDecorations((e) => this.onModelDecorationsChanged(modelUrlStr, e))];
const breakpointDecorationsAsMap = new Map<string, boolean>();
breakPointDecorations.forEach(bpd => breakpointDecorationsAsMap.set(bpd, true));
const breakpointDecorationsAsMap = new Map<string, Range>();
breakPointDecorations.forEach((decorationId, index) => breakpointDecorationsAsMap.set(decorationId, desiredDecorations[index].range));
this.modelDataMap.set(modelUrlStr, {
model: model,
......@@ -191,7 +192,17 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
// I have no decorations
return;
}
if (!e.changedDecorations.some(decorationId => modelData.breakpointDecorationsAsMap.has(decorationId))) {
let somethingChanged = false;
modelData.breakpointDecorationsAsMap.forEach((breakpointRange, decorationId) => {
if (somethingChanged) {
return;
}
const newBreakpointRange = modelData.model.getDecorationRange(decorationId);
if (newBreakpointRange && !breakpointRange.equalsRange(newBreakpointRange)) {
somethingChanged = true;
}
});
if (!somethingChanged) {
// nothing to do, my decorations did not change.
return;
}
......@@ -254,16 +265,19 @@ export class DebugEditorModelManager implements IWorkbenchContribution {
}
private updateBreakpoints(modelData: IDebugEditorModelData, newBreakpoints: IBreakpoint[]): void {
modelData.breakpointDecorationIds = modelData.model.deltaDecorations(modelData.breakpointDecorationIds, this.createBreakpointDecorations(newBreakpoints));
const desiredDecorations = this.createBreakpointDecorations(modelData.model, newBreakpoints);
modelData.breakpointDecorationIds = modelData.model.deltaDecorations(modelData.breakpointDecorationIds, desiredDecorations);
modelData.breakpointDecorationsAsMap.clear();
modelData.breakpointDecorationIds.forEach(id => modelData.breakpointDecorationsAsMap.set(id, true));
modelData.breakpointDecorationIds.forEach((decorationId, index) => modelData.breakpointDecorationsAsMap.set(decorationId, desiredDecorations[index].range));
modelData.breakpointLines = newBreakpoints.map(bp => bp.lineNumber);
}
private createBreakpointDecorations(breakpoints: IBreakpoint[]): IModelDeltaDecoration[] {
private createBreakpointDecorations(model: IModel, breakpoints: IBreakpoint[]): { range: Range; options: IModelDecorationOptions; }[] {
return breakpoints.map((breakpoint) => {
const range = breakpoint.column ? new Range(breakpoint.lineNumber, breakpoint.column, breakpoint.lineNumber, breakpoint.column + 1)
: new Range(breakpoint.lineNumber, 1, breakpoint.lineNumber, Constants.MAX_SAFE_SMALL_INTEGER); // Decoration has to have a width #20688
const range = model.validateRange(
breakpoint.column ? new Range(breakpoint.lineNumber, breakpoint.column, breakpoint.lineNumber, breakpoint.column + 1)
: new Range(breakpoint.lineNumber, 1, breakpoint.lineNumber, Constants.MAX_SAFE_SMALL_INTEGER) // Decoration has to have a width #20688
);
return {
options: this.getBreakpointDecorationOptions(breakpoint),
range
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册