diff --git a/src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts index add1f8d0515cc..f1089eab59ea1 100644 --- a/src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts @@ -396,7 +396,11 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE } public getId(): string { - return this.getEditorType() + ':' + this._id; + return this.getEditorType() + ':' + this.getIdNumber(); + } + + public getIdNumber(): number { + return this._id; } public getEditorType(): string { diff --git a/src/vs/editor/browser/widget/diffEditor/delegatingEditorImpl.ts b/src/vs/editor/browser/widget/diffEditor/delegatingEditorImpl.ts index 056db97f620d4..a0adb76b4650b 100644 --- a/src/vs/editor/browser/widget/diffEditor/delegatingEditorImpl.ts +++ b/src/vs/editor/browser/widget/diffEditor/delegatingEditorImpl.ts @@ -23,7 +23,9 @@ export abstract class DelegatingEditor extends Disposable implements IEditor { protected abstract get _targetEditor(): CodeEditorWidget; - getId(): string { return this.getEditorType() + ':v2:' + this._id; } + getId(): string { return this.getEditorType() + ':v2:' + this.getIdNumber(); } + + getIdNumber(): number { return this._id; } abstract getEditorType(): string; abstract updateOptions(newOptions: IEditorOptions): void; diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 9cf2cd59a83ca..b9228a43b6504 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -238,6 +238,11 @@ export interface IEditor { */ getId(): string; + /** + * Get the id number for this editor instance. + */ + getIdNumber(): number; + /** * Get the editor type. Please see `EditorType`. * This is to avoid an instanceof check diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index be23660652e82..db45d2bf5bcd3 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -1576,7 +1576,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati //#region Decorations - private handleBeforeFireDecorationsChangedEvent(affectedInjectedTextLines: Set | null, specialLineHeights: Set | null): void { + private handleBeforeFireDecorationsChangedEvent(affectedInjectedTextLines: Set | null, specialLineHeights: Set<{ ownerId: number; lineNumber: number }> | null): void { // This is called before the decoration changed event is fired. if (affectedInjectedTextLines && affectedInjectedTextLines.size > 0) { @@ -1586,7 +1586,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati } if (specialLineHeights && specialLineHeights.size > 0) { const affectedLinesByLineHeightChange = Array.from(specialLineHeights); - const lineHeightChangeEvent = affectedLinesByLineHeightChange.map(lineNumber => new ModelLineHeightChanged(lineNumber, this._getLineHeightForLine(lineNumber))); + const lineHeightChangeEvent = affectedLinesByLineHeightChange.map(specialLineHeightChange => new ModelLineHeightChanged(specialLineHeightChange.ownerId, specialLineHeightChange.lineNumber, this._getLineHeightForLine(specialLineHeightChange.lineNumber))); this._onDidChangeSpecialLineHeight.fire(new ModelLineHeightChangedEvent(lineHeightChangeEvent)); } } @@ -1608,10 +1608,10 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati return this._deltaDecorationsImpl(ownerId, [], [{ range: range, options: options }])[0]; }, changeDecoration: (id: string, newRange: IRange): void => { - this._changeDecorationImpl(id, newRange); + this._changeDecorationImpl(ownerId, id, newRange); }, changeDecorationOptions: (id: string, options: model.IModelDecorationOptions) => { - this._changeDecorationOptionsImpl(id, _normalizeOptions(options)); + this._changeDecorationOptionsImpl(ownerId, id, _normalizeOptions(options)); }, removeDecoration: (id: string): void => { this._deltaDecorationsImpl(ownerId, [id], []); @@ -1797,7 +1797,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati return this._buffer.getRangeAt(start, end - start); } - private _changeDecorationImpl(decorationId: string, _range: IRange): void { + private _changeDecorationImpl(ownerId: number, decorationId: string, _range: IRange): void { const node = this._decorations[decorationId]; if (!node) { return; @@ -1814,7 +1814,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati if (node.options.lineHeight) { const oldRange = this.getDecorationRange(decorationId); for (let lineNumber = oldRange!.startLineNumber; lineNumber <= oldRange!.endLineNumber; lineNumber++) { - this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(lineNumber); + this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(ownerId, lineNumber); } } @@ -1835,12 +1835,12 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati } if (node.options.lineHeight) { for (let lineNumber = range.startLineNumber; lineNumber <= range.endLineNumber; lineNumber++) { - this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(lineNumber); + this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(ownerId, lineNumber); } } } - private _changeDecorationOptionsImpl(decorationId: string, options: ModelDecorationOptions): void { + private _changeDecorationOptionsImpl(ownerId: number, decorationId: string, options: ModelDecorationOptions): void { const node = this._decorations[decorationId]; if (!node) { return; @@ -1863,7 +1863,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati if (node.options.lineHeight) { const nodeRange = this._decorationsTree.getNodeRange(this, node); for (let lineNumber = nodeRange.startLineNumber; lineNumber <= nodeRange.endLineNumber; lineNumber++) { - this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(lineNumber); + this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(ownerId, lineNumber); } } @@ -1913,7 +1913,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati if (node.options.lineHeight) { const nodeRange = this._decorationsTree.getNodeRange(this, node); for (let lineNumber = nodeRange.startLineNumber; lineNumber <= nodeRange.endLineNumber; lineNumber++) { - this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(lineNumber); + this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(ownerId, lineNumber); } } this._decorationsTree.delete(node); @@ -1952,7 +1952,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati } if (node.options.lineHeight) { for (let lineNumber = range.startLineNumber; lineNumber <= range.endLineNumber; lineNumber++) { - this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(lineNumber); + this._onDidChangeDecorations.recordLineAffectedByLineHeightChange(ownerId, lineNumber); } } if (!suppressEvents) { @@ -2446,11 +2446,11 @@ class DidChangeDecorationsEmitter extends Disposable { private _affectsMinimap: boolean; private _affectsOverviewRuler: boolean; private _affectedInjectedTextLines: Set | null = null; + private _specialLineHeights: Set<{ ownerId: number; lineNumber: number }> | null = null; private _affectsGlyphMargin: boolean; private _affectsLineNumber: boolean; - private _specialLineHeights: Set | null = null; - constructor(private readonly handleBeforeFire: (affectedInjectedTextLines: Set | null, specialLineHeights: Set | null) => void) { + constructor(private readonly handleBeforeFire: (affectedInjectedTextLines: Set | null, specialLineHeights: Set<{ ownerId: number; lineNumber: number }> | null) => void) { super(); this._deferredCnt = 0; this._shouldFireDeferred = false; @@ -2477,6 +2477,8 @@ class DidChangeDecorationsEmitter extends Disposable { this._affectedInjectedTextLines?.clear(); this._affectedInjectedTextLines = null; + this._specialLineHeights?.clear(); + this._specialLineHeights = null; } } @@ -2487,11 +2489,11 @@ class DidChangeDecorationsEmitter extends Disposable { this._affectedInjectedTextLines.add(lineNumber); } - public recordLineAffectedByLineHeightChange(lineNumber: number): void { + public recordLineAffectedByLineHeightChange(ownerId: number, lineNumber: number): void { if (!this._specialLineHeights) { this._specialLineHeights = new Set(); } - this._specialLineHeights.add(lineNumber); + this._specialLineHeights.add({ ownerId, lineNumber }); } public checkAffectedAndFire(options: ModelDecorationOptions): void { diff --git a/src/vs/editor/common/textModelEvents.ts b/src/vs/editor/common/textModelEvents.ts index 79b554b1b8980..afdcdd9e24401 100644 --- a/src/vs/editor/common/textModelEvents.ts +++ b/src/vs/editor/common/textModelEvents.ts @@ -240,6 +240,10 @@ export class ModelRawLineChanged { * @internal */ export class ModelLineHeightChanged { + /** + * Editor owner ID + */ + public readonly ownerId: number; /** * The line that has changed. */ @@ -249,7 +253,8 @@ export class ModelLineHeightChanged { */ public readonly lineHeight: number | null; - constructor(lineNumber: number, lineHeight: number | null) { + constructor(ownerId: number, lineNumber: number, lineHeight: number | null) { + this.ownerId = ownerId; this.lineNumber = lineNumber; this.lineHeight = lineHeight; } diff --git a/src/vs/editor/common/viewLayout/viewLayout.ts b/src/vs/editor/common/viewLayout/viewLayout.ts index 7dd5569296adc..f81fa59c637b6 100644 --- a/src/vs/editor/common/viewLayout/viewLayout.ts +++ b/src/vs/editor/common/viewLayout/viewLayout.ts @@ -203,10 +203,12 @@ export class ViewLayout extends Disposable implements IViewLayout { } public addSpecialLineHeight(lineNumber: number, height: number): void { + console.log('addSpecialLineHeight ' + lineNumber + ' ' + height); this._linesLayout.addSpecialLineHeight(lineNumber, height); } public removeSpecialLineHeight(lineNumber: number): void { + console.log('removeSpecialLineHeight ' + lineNumber); this._linesLayout.removeSpecialLineHeight(lineNumber); } diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index 9995449ebbe10..682b31d7a967f 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -139,6 +139,9 @@ export class ViewModel extends Disposable implements IViewModel { this._decorations = new ViewModelDecorations(this._editorId, this.model, this._configuration, this._lines, this.coordinatesConverter); this._register(this.model.onDidChangeSpecialLineHeight((e) => { e.changes.forEach((change) => { + if (change.ownerId !== this._editorId) { + return; + } const lineNumber = change.lineNumber; const lineHeight = change.lineHeight; if (lineHeight !== null) { diff --git a/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts b/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts index cd5a779f16f0f..11ea195846f94 100644 --- a/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts +++ b/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts @@ -135,6 +135,9 @@ export class StickyScrollController extends Disposable implements IEditorContrib if (model) { this._register(model.onDidChangeSpecialLineHeight((e) => { e.changes.forEach((change) => { + if (change.ownerId !== this._editor.getIdNumber()) { + return; + } const lineNumber = change.lineNumber; const lineHeight = change.lineHeight; if (lineHeight !== null) { diff --git a/src/vs/editor/contrib/stickyScroll/browser/stickyScrollProvider.ts b/src/vs/editor/contrib/stickyScroll/browser/stickyScrollProvider.ts index 5281377b4f359..73af0939f330d 100644 --- a/src/vs/editor/contrib/stickyScroll/browser/stickyScrollProvider.ts +++ b/src/vs/editor/contrib/stickyScroll/browser/stickyScrollProvider.ts @@ -72,6 +72,9 @@ export class StickyLineCandidateProvider extends Disposable implements IStickyLi if (model) { this._register(model.onDidChangeSpecialLineHeight((e) => { e.changes.forEach((change) => { + if (change.ownerId !== this._editor.getIdNumber()) { + return; + } const lineNumber = change.lineNumber; const lineHeight = change.lineHeight; if (lineHeight !== null) { diff --git a/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts b/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts index a38f1639eea61..3f313d48ef4dd 100644 --- a/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts +++ b/src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts @@ -17,7 +17,6 @@ import { IPosition, Position } from '../../../common/core/position.js'; import { IRange, Range } from '../../../common/core/range.js'; import { IEditorDecorationsCollection, ScrollType } from '../../../common/editorCommon.js'; import { TrackedRangeStickiness } from '../../../common/model.js'; -import { ModelDecorationOptions } from '../../../common/model/textModel.js'; export interface IOptions { showFrame?: boolean; @@ -319,7 +318,12 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { this._isShowing = true; this._showImpl(range, heightInLines); this._isShowing = false; - this._positionMarkerId.set([{ range, options: ModelDecorationOptions.EMPTY }]); + this._positionMarkerId.set([{ + range, options: { + lineHeight: 100, + description: 'zone-widget-position', + } + }]); } updatePositionAndHeight(rangeOrPos: IRange | IPosition, heightInLines?: number): void { @@ -334,7 +338,10 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider { }); this._positionMarkerId.set([{ range: Range.isIRange(rangeOrPos) ? rangeOrPos : Range.fromPositions(rangeOrPos), - options: ModelDecorationOptions.EMPTY + options: { + lineHeight: 100, + description: 'zone-widget-position', + } }]); this._updateSashEnablement(); } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 7cad5575a7901..23f77fc2d351b 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2615,6 +2615,10 @@ declare namespace monaco.editor { * Get a unique id for this editor instance. */ getId(): string; + /** + * Get the id number for this editor instance. + */ + getIdNumber(): number; /** * Get the editor type. Please see `EditorType`. * This is to avoid an instanceof check