IClipboardHandler

interface

Abstracts clipboard access so DocumentController remains platform-independent. In Avalonia applications, AvaloniaClipboardHandler (from the Avalonia project) implements this.

MethodReturn TypeDescription
GetTextAsync()Task<string?>Returns the current clipboard text, or null if empty.
SetTextAsync(string text)TaskPlaces text onto the clipboard.
GetImageDataAsync()Task<byte[]?>Returns raw bitmap bytes if an image is on the clipboard, or null.

KeyInfo

struct

A platform-agnostic description of a single key event. Construct it in your platform key handler and pass it to DocumentController.OnKeyEvent().

MemberTypeDescription
KeyCodeKeyCodeThe virtual key code (A–Z, D0–D9, F1–F24, arrows, etc.)
ShiftboolShift modifier held
ControlboolControl modifier held
AltboolAlt modifier held
Characterchar?Mapped printable character, or null if the key has no character (e.g., arrow keys) or if Control/Alt is held
HasCommandModifiersboolControl || Alt
HasModifiersboolShift || Control || Alt
IsPrintableCharacterboolTrue when Character has a non-null printable value
AsShortcut()ShortcutConvert to a Shortcut for lookup in the ShortcutHandler
// Avalonia OnKeyDown example
protected override async void OnKeyDown(KeyEventArgs e)
{
    var key = new KeyInfo(
        keyCode:  e.Key.ToKeyCode(),    // AvaloniaExtensions helper
        shift:    e.KeyModifiers.HasFlag(KeyModifiers.Shift),
        control:  e.KeyModifiers.HasFlag(KeyModifiers.Control),
        alt:      e.KeyModifiers.HasFlag(KeyModifiers.Alt)
    );
    bool consumed = await controller.OnKeyEvent(key);
    if (consumed) e.Handled = true;
}

Shortcut

struct

A key combination descriptor. Use KeyInfo.AsShortcut() or construct directly.

MemberTypeDescription
BaseKeyKeyCodeThe primary key
ControlKeyboolCtrl modifier required
ShiftKeyboolShift modifier required
AltKeyboolAlt modifier required
Shortcut(KeyCode, bool shift, bool control, bool alt)ctorConstruct explicitly

ShortcutHandler

class

Maps Shortcut values to async actions and dispatches key events. Access it via DocumentController.Shortcuts.

MethodDescription
Map(Shortcut, Func<Task> action)Register a custom shortcut. Overwrites any existing mapping for that combination.
Execute(Shortcut) → Task<bool>Invoke the action mapped to a shortcut. Returns true if a mapping was found. Called internally by OnKeyEvent().
// Add a custom Ctrl+Shift+H shortcut to insert a horizontal rule
controller.Shortcuts.Map(
    new Shortcut(KeyCode.H, shift: true, control: true),
    async () => { await controller.Insert("──────────"); }
);

// Remap Ctrl+B to apply a custom style instead of bold
controller.Shortcuts.Map(
    new Shortcut(KeyCode.B, control: true),
    async () => { await controller.ApplyStyle(myHeadingStyle); }
);

KeyMap (Static Utility)

class · static

Helpers for key classification and character mapping.

MethodReturnDescription
IsPrintableCharacter(KeyCode code, bool shiftModifier = false)boolTrue if the key produces a printable character.
GetCharacter(KeyCode, bool shift, bool capsLock = false)char?Returns the character for a key code + modifier combination, or null if not applicable.
IsModifierKey(KeyCode key)boolTrue for Shift, Control, Alt, Win/Meta, CapsLock, etc.

Built-in Default Shortcuts

ShortcutAction
Ctrl+BToggle bold
Ctrl+IToggle italic
Ctrl+UToggle underline
Ctrl+ZUndo
Ctrl+YRedo
Ctrl+ASelect all
Ctrl+CCopy
Ctrl+XCut
Ctrl+VPaste
Tab (in list)Increase list nesting level
Shift+Tab (in list)Decrease list nesting level
Enter (on empty list item)Exit list
BackspaceDelete character before caret / delete selection
DeleteDelete character after caret / delete selection
Arrow keysNavigate caret
Shift+ArrowExtend selection
Home / EndMove to line start/end
Ctrl+Home / Ctrl+EndMove to document start/end