Skip to content

Type Editor


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

ts
new ViewTreeUpdater(
   top,
   lock,
   view): ViewTreeUpdater;

Defined in: ViewTreeUpdater.ts:62

Creates a new ViewTreeUpdater.

Parameters

ParameterTypeDescription
topNodeViewDescThe top-level node view description to update
lockNodeA DOM node that should not be modified (typically during composition)
viewPmEditorViewThe editor view

Returns

ViewTreeUpdater

Accessors

changed

Get Signature

ts
get changed(): boolean;

Defined in: ViewTreeUpdater.ts:72

Returns

boolean

Methods

addNode()

ts
addNode(
   node,
   outerDeco,
   innerDeco,
   pos): void;

Defined in: ViewTreeUpdater.ts:281

Insert the node as a newly created node desc.

Parameters

ParameterTypeDescription
nodeNode_2The node to add
outerDecoreadonly PmDecoration[]Outer decorations for the node
innerDecoDecorationSourceInner decorations for the node
posnumberDocument position of the node

Returns

void


addTextblockHacks()

ts
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()

ts
destroyRemaining(): void;

Defined in: ViewTreeUpdater.ts:79

Destroy all remaining children in this.top from the current index onwards.

Returns

void


findIndexWithChild()

ts
findIndexWithChild(domNode): number;

Defined in: ViewTreeUpdater.ts:180

Find the index of the child that contains a given DOM node.

Parameters

ParameterTypeDescription
domNodeNodeThe DOM node to search for

Returns

number

The child index, or -1 if not found


findNodeMatch()

ts
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

ParameterTypeDescription
nodeNode_2The node to find a match for
outerDecoreadonly PmDecoration[]Outer decorations for the node
innerDecoDecorationSourceInner decorations for the node
indexnumberThe index in the parent's child array

Returns

boolean

True if a match was found and used


placeWidget()

ts
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

ParameterTypeDescription
widgetPmDecorationThe widget decoration to place
posnumberDocument position for the widget

Returns

void


syncToMarks()

ts
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:

  1. Finding how many marks from the stack can be kept
  2. Popping marks that don't match
  3. Pushing new marks or reusing existing ones

The stack stores pairs of [ViewDesc, index], so depth = stack.length / 2

Parameters

ParameterTypeDescription
marksreadonly Mark[]The marks to sync to
inlinebooleanWhether the content is inline
parentIndexnumber-

Returns

void


updateNextNode()

ts
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

ParameterTypeDescription
nodeNode_2The node to update to
outerDecoreadonly PmDecoration[]Outer decorations for the node
innerDecoDecorationSourceInner decorations for the node
indexnumberThe node's index in its parent
posnumberThe document position of the node

Returns

boolean

True if an update was performed


updateNodeAt()

ts
updateNodeAt(
   node,
   outerDeco,
   innerDeco,
   index): boolean;

Defined in: ViewTreeUpdater.ts:156

Try to update the node view at a specific index.

Parameters

ParameterTypeDescription
nodeNode_2The node to update to
outerDecoreadonly PmDecoration[]Outer decorations for the node
innerDecoDecorationSourceInner decorations for the node
indexnumberThe index in the children array

Returns

boolean

True if the update succeeded