Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aiday-mar committed Jan 9, 2025
1 parent 1d64cc5 commit ed5fbf5
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions src/vs/editor/common/model/textModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ export class TextModel extends Disposable implements model.ITextModel, IDecorati

//#region Decorations

private handleBeforeFireDecorationsChangedEvent(affectedInjectedTextLines: Set<number> | null, specialLineHeights: Set<number> | null): void {
private handleBeforeFireDecorationsChangedEvent(affectedInjectedTextLines: Set<number> | null, specialLineHeights: Set<{ ownerId: number; lineNumber: number }> | null): void {
// This is called before the decoration changed event is fired.

if (affectedInjectedTextLines && affectedInjectedTextLines.size > 0) {
Expand All @@ -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));
}
}
Expand All @@ -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], []);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2446,11 +2446,11 @@ class DidChangeDecorationsEmitter extends Disposable {
private _affectsMinimap: boolean;
private _affectsOverviewRuler: boolean;
private _affectedInjectedTextLines: Set<number> | null = null;
private _specialLineHeights: Set<{ ownerId: number; lineNumber: number }> | null = null;
private _affectsGlyphMargin: boolean;
private _affectsLineNumber: boolean;
private _specialLineHeights: Set<number> | null = null;

constructor(private readonly handleBeforeFire: (affectedInjectedTextLines: Set<number> | null, specialLineHeights: Set<number> | null) => void) {
constructor(private readonly handleBeforeFire: (affectedInjectedTextLines: Set<number> | null, specialLineHeights: Set<{ ownerId: number; lineNumber: number }> | null) => void) {
super();
this._deferredCnt = 0;
this._shouldFireDeferred = false;
Expand All @@ -2477,6 +2477,8 @@ class DidChangeDecorationsEmitter extends Disposable {

this._affectedInjectedTextLines?.clear();
this._affectedInjectedTextLines = null;
this._specialLineHeights?.clear();
this._specialLineHeights = null;
}
}

Expand All @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/vs/editor/common/textModelEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ export class ModelRawLineChanged {
* @internal
*/
export class ModelLineHeightChanged {
/**
* Editor owner ID
*/
public readonly ownerId: number;
/**
* The line that has changed.
*/
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/common/viewLayout/viewLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/vs/editor/common/viewModel/viewModelImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed5fbf5

Please sign in to comment.