Scrivr
Engine Internals

Layout Coordinator

Class reference for LayoutCoordinator.

The LayoutCoordinator abstracts pagination mathematics away from the raw Editor state, implementing background idle-chunking (streaming layout data asynchronously to preserve 60fps).


Constructor

new LayoutCoordinator(opts: LayoutCoordinatorOptions)

LayoutCoordinatorOptions

  • pageConfig (PageConfig): Active page boundaries and margins.
  • fontConfig (FontConfig): Typographical rulesets.
  • measurer (TextMeasurer): The engine canvas measurer.
  • fontModifiers (Map): Extension-specific modifiers.
  • getDoc () => Node: Eager callback resolving the latest EditorState.doc.
  • getHead () => number: Eager callback resolving the absolute cursor doc-position.
  • onUpdate () => void: Callback fired after idle layout finishes, triggering a React UI repaint.

Properties

charMap

readonly charMap: CharacterMap

The spatial index mapping document coordinates against world-space layout rectangles.

current

get current(): DocumentLayout

Returns the active structure containing the array of LayoutPages, lines, and bounding boxes.

cursorPage

get cursorPage(): number

The 1-based page number tracking exactly which physical printed page the cursor currently resides on.

isReady

get isReady(): boolean

false if layout processing is actively paused/suppressed by startReady rules via collaborative websockets.

loadingState

get loadingState(): "syncing" | "rendering" | "ready"

The three-phase status: Waiting on network (syncing), churning idle blocks in the background (rendering), or 100% computed (ready).


Methods

invalidate()

invalidate(): void

Marks the layout as stale. Called immediately on every keystroke, forcing ensureLayout to recalculate the block differentials.

ensureLayout()

ensureLayout(): void

Synchronously forces the Layout tree to recompute if invalidate() was triggered. Runs prior to any visual drawing step.

ensurePagePopulated()

ensurePagePopulated(pageNumber: number): void

Lazily and eagerly populates the CharacterMap hit-test zones specifically for a single page, avoiding O(N) spatial mapping constraints for off-screen pages.

After registering inline glyphs for every block on the page, it also stamps the real (x, y, width, height) objectRects for any floating images whose anchor paragraph is on that page. This is important because float objectRects are only written to the charMap by drawFloat during the TileManager paint (RAF-B), but notifyListeners fires one frame earlier (RAF-A) — getNodeViewportRect would otherwise read the zero-width inline anchor entry and position the ImageMenu popover at the wrong location.

Called automatically for cursorPage ± 1 after every ensureLayout() pass, and on demand by TileManager before painting each visible tile.

setReady()

setReady(ready: boolean): void

Used by remote synchronization APIs to temporarily pause requestIdleCallback loop calculations until the first bulk Y.js payload cleanly resolves.

destroy()

destroy(): void

Immediately terminates any actively running idle computations.

On this page