Task Delegation
Responsibilities are delegated explicitly based on physical (geometric) vs. logical (structural) boundaries.
Geometry (C# Responsibilities)
C# handles all tasks requiring spatial awareness of pixels, fonts, and bounding boxes.
- Cursor & Hit-Testing: C# calculates X/Y coordinates, hit-tests the active text layout, and computes Up/Down arrow navigation based on physical line breaks.
- Text Selection: C# tracks selection indices, asks Avalonia for the bounding geometry of those characters, and paints the highlight rectangles.
- Layout & Virtualization: C# passes text to Avalonia's
TextLayoutto handle word wrapping based on line limits. It tracks the viewport and only instantiates layout objects for visible paragraphs.
Structure (Nim Responsibilities)
Nim handles the mathematical boundaries, data integrity, and complex business logic.
- Formatting Spans ($Nim \rightarrow C#$): Nim stores the mathematical boundaries of formatting (e.g., "Indices 10-15 are bold"). C# merely applies those styles to the rendering engine.
- Input Rules / Macros ($C# \rightarrow Nim \rightarrow C#$): C# listens for triggers (like typing
/name). It queries Nim. Nim checks its authoritative list of Stand-ins. If matched, Nim commands C# to replace the text with the atomic Stand-in UI element. - Clipboard ($C# \rightarrow Nim$): C# catches the OS paste event and sends the raw bulk text to Nim. Nim parses it into blocks, updates the document state, and sends the structured layout back to C#.