Type Editor / @type-editor/view / dom-observer/DOMObserver / DOMObserver
Class: DOMObserver
Defined in: dom-observer/DOMObserver.ts:19
Observes DOM changes and selection changes in a ProseMirror editor view. This class bridges between native browser events and ProseMirror's state management, ensuring that external DOM modifications are properly synchronized with the editor state.
Implements
PmDOMObserver
Constructors
Constructor
new DOMObserver(view, handleDOMChange): DOMObserver;Defined in: dom-observer/DOMObserver.ts:53
Creates a new DOM observer.
Parameters
| Parameter | Type | Description |
|---|---|---|
view | EditorView | The editor view to observe |
handleDOMChange | (from, to, typeOver, added) => void | Callback invoked when DOM changes are detected |
Returns
DOMObserver
Accessors
currentSelection
Get Signature
get currentSelection(): SelectionState;Defined in: dom-observer/DOMObserver.ts:92
Gets the current cached selection state.
Returns
The current selection state
Implementation of
PmDOMObserver.currentSelection;flushingSoon
Get Signature
get flushingSoon(): number;Defined in: dom-observer/DOMObserver.ts:76
Gets the timeout ID for pending flush operation.
Returns
number
The timeout ID, or -1 if no flush is scheduled
Implementation of
PmDOMObserver.flushingSoon;lastChangedTextNode
Get Signature
get lastChangedTextNode(): Text;Defined in: dom-observer/DOMObserver.ts:84
Gets the last text node that was modified.
Returns
Text
The last changed text node or null
Implementation of
PmDOMObserver.lastChangedTextNode;requiresGeckoHackNode
Get Signature
get requiresGeckoHackNode(): boolean;Defined in: dom-observer/DOMObserver.ts:96
Returns
boolean
Implementation of
PmDOMObserver.requiresGeckoHackNode;Methods
connectSelection()
connectSelection(): void;Defined in: dom-observer/DOMObserver.ts:203
Starts listening to selection change events.
Returns
void
Implementation of
PmDOMObserver.connectSelection;disconnectSelection()
disconnectSelection(): void;Defined in: dom-observer/DOMObserver.ts:211
Stops listening to selection change events.
Returns
void
Implementation of
PmDOMObserver.disconnectSelection;flush()
flush(): void;Defined in: dom-observer/DOMObserver.ts:256
Processes all pending mutations and synchronizes the editor state. This is the main entry point for DOM change handling.
Returns
void
Implementation of
PmDOMObserver.flush;flushSoon()
flushSoon(): void;Defined in: dom-observer/DOMObserver.ts:104
Schedules a flush operation to process pending mutations after a short delay. This helps batch multiple rapid changes together for better performance.
Returns
void
Implementation of
PmDOMObserver.flushSoon;forceFlush()
forceFlush(): void;Defined in: dom-observer/DOMObserver.ts:118
Cancels any pending flush and immediately processes all mutations.
Returns
void
Implementation of
PmDOMObserver.forceFlush;pendingRecords()
pendingRecords(): MutationRecord[];Defined in: dom-observer/DOMObserver.ts:244
Retrieves all pending mutation records and returns the current queue.
Returns
MutationRecord[]
Array of pending mutation records
Implementation of
PmDOMObserver.pendingRecords;setCurSelection()
setCurSelection(): void;Defined in: dom-observer/DOMObserver.ts:236
Updates the cached current selection from the DOM.
Returns
void
Implementation of
PmDOMObserver.setCurSelection;start()
start(): void;Defined in: dom-observer/DOMObserver.ts:130
Starts observing DOM and selection changes. This should be called when the editor becomes active.
Returns
void
Implementation of
PmDOMObserver.start;stop()
stop(): void;Defined in: dom-observer/DOMObserver.ts:165
Stops observing DOM and selection changes. Any pending mutations are flushed asynchronously.
Returns
void
Implementation of
PmDOMObserver.stop;suppressSelectionUpdates()
suppressSelectionUpdates(): void;Defined in: dom-observer/DOMObserver.ts:220
Temporarily suppresses selection updates for 50ms. This is useful when programmatically changing the selection.
Returns
void
Implementation of
PmDOMObserver.suppressSelectionUpdates;