Skip to content

Clarification about markers #3108

@jerch

Description

@jerch

Just tried to use markers for the image addon to get informed, when it is safe to free resources again. I am not quite sure how markers are supposed to be used via API. Is there a reason why onDispose is not exported? Is it unsafe to rely on it?

Due to this I did a quick hack with a marker collector, which checks for isDisposed and line and found that the line is still decrementing after the marker is meant to be disposed:

grafik

(The 'got disposed!' message is from my type overloading with a onDispose callback.)

This somewhat looks like it was not really disposed, as some code from xterm.js internals updates the now illegal line index (thus still holds a ref somehow)? Imho related code would be here:

public addMarker(y: number): Marker {
const marker = new Marker(y);
this.markers.push(marker);
marker.register(this.lines.onTrim(amount => {
marker.line -= amount;
// The marker should be disposed when the line is trimmed from the buffer
if (marker.line < 0) {
marker.dispose();
}
}));
marker.register(this.lines.onInsert(event => {
if (marker.line >= event.index) {
marker.line += event.amount;
}
}));
marker.register(this.lines.onDelete(event => {
// Delete the marker if it's within the range
if (marker.line >= event.index && marker.line < event.index + event.amount) {
marker.dispose();
}
// Shift the marker if it's after the deleted range
if (marker.line > event.index) {
marker.line -= event.amount;
}
}));
marker.register(marker.onDispose(() => this._removeMarker(marker)));
return marker;
}
private _removeMarker(marker: Marker): void {
this.markers.splice(this.markers.indexOf(marker), 1);
}

@Tyriar Does this work as intended (bear with me, there is a high chance I simply dont get it 😸)

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething is misbehaving

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions