Type Editor / @type-editor/viewdesc / ViewTreeUpdater / ViewTreeUpdater
Class: ViewTreeUpdater
Defined in: ViewTreeUpdater.ts:29
Helper class for incrementally updating a tree of mark descs and the widget and node descs inside of them.
This class maintains a cursor through the existing view desc tree while iterating through the new document content, trying to reuse existing view descs where possible. It handles:
- Nested mark descs (maintains a stack as it enters/exits marks)
- Node and widget descs
- DOM composition protection (won't modify locked nodes)
Constructors
Constructor
new ViewTreeUpdater(
top,
lock,
view): ViewTreeUpdater;Defined in: ViewTreeUpdater.ts:62
Creates a new ViewTreeUpdater.
Parameters
| Parameter | Type | Description |
|---|---|---|
top | NodeViewDesc | The top-level node view description to update |
lock | Node | A DOM node that should not be modified (typically during composition) |
view | PmEditorView | The editor view |
Returns
ViewTreeUpdater
Accessors
changed
Get Signature
get changed(): boolean;Defined in: ViewTreeUpdater.ts:72
Returns
boolean
Methods
addNode()
addNode(
node,
outerDeco,
innerDeco,
pos): void;Defined in: ViewTreeUpdater.ts:281
Insert the node as a newly created node desc.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | Node_2 | The node to add |
outerDeco | readonly PmDecoration[] | Outer decorations for the node |
innerDeco | DecorationSource | Inner decorations for the node |
pos | number | Document position of the node |
Returns
void
addTextblockHacks()
addTextblockHacks(): void;Defined in: ViewTreeUpdater.ts:326
Make sure a textblock looks and behaves correctly in contentEditable.
Adds BR elements to empty blocks or blocks that don't end with newlines, ensuring they display correctly and can accept cursor placement. On some browsers, also adds IMG separators to work around cursor bugs.
Returns
void
destroyRemaining()
destroyRemaining(): void;Defined in: ViewTreeUpdater.ts:79
Destroy all remaining children in this.top from the current index onwards.
Returns
void
findIndexWithChild()
findIndexWithChild(domNode): number;Defined in: ViewTreeUpdater.ts:180
Find the index of the child that contains a given DOM node.
Parameters
| Parameter | Type | Description |
|---|---|---|
domNode | Node | The DOM node to search for |
Returns
number
The child index, or -1 if not found
findNodeMatch()
findNodeMatch(
node,
outerDeco,
innerDeco,
index): boolean;Defined in: ViewTreeUpdater.ts:117
Try to find a node desc matching the given data. Skip over it and return true when successful.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | Node_2 | The node to find a match for |
outerDeco | readonly PmDecoration[] | Outer decorations for the node |
innerDeco | DecorationSource | Inner decorations for the node |
index | number | The index in the parent's child array |
Returns
boolean
True if a match was found and used
placeWidget()
placeWidget(widget, pos): void;Defined in: ViewTreeUpdater.ts:300
Place a widget decoration at the current position. Reuses existing widget if it matches, otherwise creates a new one.
Parameters
| Parameter | Type | Description |
|---|---|---|
widget | PmDecoration | The widget decoration to place |
pos | number | Document position for the widget |
Returns
void
syncToMarks()
syncToMarks(
marks,
inline,
parentIndex): void;Defined in: ViewTreeUpdater.ts:97
Syncs the current stack of mark descs with the given array of marks.
This maintains proper mark nesting by:
- Finding how many marks from the stack can be kept
- Popping marks that don't match
- Pushing new marks or reusing existing ones
The stack stores pairs of [ViewDesc, index], so depth = stack.length / 2
Parameters
| Parameter | Type | Description |
|---|---|---|
marks | readonly Mark[] | The marks to sync to |
inline | boolean | Whether the content is inline |
parentIndex | number | - |
Returns
void
updateNextNode()
updateNextNode(
node,
outerDeco,
innerDeco,
index,
pos): boolean;Defined in: ViewTreeUpdater.ts:213
Try to update the next node, if any, to the given data. Checks pre-matches to avoid overwriting nodes that could still be used.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | Node_2 | The node to update to |
outerDeco | readonly PmDecoration[] | Outer decorations for the node |
innerDeco | DecorationSource | Inner decorations for the node |
index | number | The node's index in its parent |
pos | number | The document position of the node |
Returns
boolean
True if an update was performed
updateNodeAt()
updateNodeAt(
node,
outerDeco,
innerDeco,
index): boolean;Defined in: ViewTreeUpdater.ts:156
Try to update the node view at a specific index.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | Node_2 | The node to update to |
outerDeco | readonly PmDecoration[] | Outer decorations for the node |
innerDeco | DecorationSource | Inner decorations for the node |
index | number | The index in the children array |
Returns
boolean
True if the update succeeded