# UnifiedWriter Editor Engine

## dev-5.20.2 model-first rebuild

UnifiedWriter is moving away from browser-DOM-driven editing. The visible editable page DOM is no longer treated as the source of truth for normal typing or paragraph operations. It is a caret and selection surface rendered from the internal DocumentModel.

The target flow is:

```text
InputController
  beforeinput / keydown / paste
  -> operation

DocumentModel
  insertText / splitParagraph / deleteBackward / deleteForward / insertBlocks
  -> block list update

LayoutEngine
  block-flow pagination
  -> pages of layout items

Renderer
  pages -> HTML page DOM

SelectionController
  blockId + offset -> caret restore
```

### Pagination rule

The default pagination rule is paragraph/block based.

- A normal paragraph is kept as one block.
- If it does not fit in the remaining writable area, it moves to the next page.
- Only a paragraph that is taller than one full page is rendered as visual fragments.
- The DocumentModel still keeps that oversized paragraph as one logical paragraph.

### Current scope

This is the first rebuild step. Normal Latin text input, Enter, Backspace, Delete and Paste are now routed through model operations. IME composition still has a guarded synchronization fallback at `compositionend`, and richer inline-format editing will be refined in a later step.


### dev-5.20.2 input surface policy

The visible page DOM is renderer output only. Blocks are not `contenteditable`. A hidden textarea input proxy receives keyboard, IME and paste events. InputController converts those browser events into DocumentModel operations and then invokes the common LayoutEngine/Renderer/SelectionController pipeline.

### dev-5.20.2 input proxy usability correction

The visible page DOM remains non-contenteditable. v5.20.2 improves the first-stage model-first editor by making the input proxy reliable for normal keyboard input and clipboard operations. Single-click places a model caret, drag-selection keeps native rendered-text selection for copy, and Copy/Cut/Paste are bridged back to DocumentModel operations when handled by the editor.


### dev-5.20.4 selection / clipboard notes

The visible page DOM remains renderer output only.  Editing commands now capture rendered DOM ranges and translate them back into `blockId + offset` model selections before applying format operations.  Clipboard HTML preserves whole selected blocks, including `ul` / `ol`, and paste insertion no longer appends trailing paragraph text by flattening list blocks.

### dev-5.20.5 list model notes

List blocks are still represented as one DocumentModel block, but their inner HTML is normalized to <li> children after text operations. Copy/Paste now keeps selected list text as <ul>/<ol> HTML rather than flattening it to paragraphs.



## dev-5.21.0 Editing Controller baseline

The rendered document pages remain non-contenteditable. Keyboard editing is routed through the hidden input proxy and converted to DocumentModel operations. The first editing-controller baseline includes caret navigation, Shift-selection, shortcut dispatch and model-level undo/redo. The current vertical navigation is block-aware rather than exact visual-line-aware; future work should replace it with a layout-coordinate SelectionController that maps x/y positions to model offsets inside rendered line boxes.

## dev-5.24.0 Notes

- List indentation is represented in the DocumentModel as flat list item metadata: `data-unified-writer-list-indent`.
- The renderer may display indented list levels, but the rendered DOM remains an output surface, not the document source of truth.
- Inline formatting operations now operate over normalized ModelSelection ranges and can span multiple blocks.
- Undo coalescing is intentionally limited to continuous typing/backspace/delete. Structural operations remain explicit undo points.



## v5.24.0 comment and import policy

Source comments should explain design intent for non-obvious Model-first behavior. This is especially important for SelectionController, LayoutEngine, list editing, Undo/Redo coalescing, and DOCX import. The DOCX importer must not be treated as a simple HTML conversion feature; the primary path is OOXML parsing and mapping toward the DocumentModel.

## dev-5.27.0 paragraph formatting note

Paragraph alignment, line spacing and indent are stored on model blocks as sanitized style metadata. The renderer applies those styles when creating page DOM, but the page DOM remains disposable. This keeps UnifiedWriter aligned with the Model-first principle and prepares the same operations for DOCX import/export and undo/redo.
