43
this.deleted = false;
44
}
46
>
47
>
/**
48
>
* Manages line heights in the editor with support for custom line heights from decorations.
49
>
*
50
>
* This class maintains an ordered collection of line heights, where each line can have either
51
>
* the default height or a custom height specified by decorations. It supports efficient querying
52
>
* of individual line heights as well as accumulated heights up to a specific line.
53
>
*
54
>
* Line heights are stored in a sorted array for efficient binary search operations. Each line
55
>
* with custom height is represented by a {@link CustomLine} object which tracks its special height,
56
>
* accumulated height prefix sum, and associated decoration ID.
57
>
*
58
>
* The class optimizes performance by:
59
>
* - Using binary search to locate lines in the ordered array
60
>
* - Batching updates through a pending changes mechanism
61
>
* - Computing prefix sums for O(1) accumulated height lookup
62
>
* - Tracking maximum height for lines with multiple decorations
63
>
* - Efficiently handling document changes (line insertions and deletions)
64
>
*
65
>
* When lines are inserted or deleted, the manager updates line numbers and prefix sums
66
>
* for all affected lines. It also handles special cases like decorations that span
67
>
* the insertion/deletion points by re-applying those decorations appropriately.
68
>
*
69
>
* All query operations automatically commit pending changes to ensure consistent results.
70
>
* Clients can modify line heights by adding or removing custom line height decorations,
71
>
* which are tracked by their unique decoration IDs.
72
>
*/
73
>
export class LineHeightsManager {
74
>
75
>
private _decorationIDToCustomLine: ArrayMap<string, CustomLine> = new ArrayMap<string, CustomLine>();
76
>
private _orderedCustomLines: CustomLine[] = [];
77
>
private _pendingChanges: PendingChange[] = [];
78
>
private _invalidIndex: number = Infinity;
79
>
private _defaultLineHeight: number;
80
>
private _hasPending: boolean = false;
81
>
82
>
constructor(defaultLineHeight: number, customLineHeightData: CustomLineHeightData[]) {
83
this._defaultLineHeight = defaultLineHeight;
84
for (const data of customLineHeightData) {