# Native input Status: design; nothing is built. Lands as the stacked series in Order, with `HostRequest` (#184) as a sibling that the last step needs. **Decided** marks what the design settled; **Proposed** marks recommendations that still need a decision; **Open** marks questions without a decision yet. ## Why Four things stand between the engine and a text input: - the boundary between native and the engine, which must go one way and must not lose input; - the native input event types, which are macOS-shaped today; - how the defaults decide what a key does, which is a `match` on key strings today; - an input element built on those three. Where each stands today, with paths under `crates/`: 1. **The boundary** is `ApplicationHandler::window_event(WindowId, WindowEvent)`. One enum carries window lifecycle and input alike. The host (`burokku/src/ui/host/events.rs`) hit-tests input against the presented frame, converts it to client coordinates, and `try_enqueue`s each event as a JavaScript macrotask of its own. A full queue drops the event with a warning. The one policy is a special case: a dropped primary release becomes a pointer cancel; a dropped key is lost. 2. **The input types** (`native/src/event.rs`) are AppKit's. `KeyEvent` carries a platform `key_code: u16`, `text` from `characters()`, and `logical_text` from `charactersIgnoringModifiers()`. Arrows arrive as private-use characters in the `U+F700` range, which `keyboard_key` in the host decodes: platform knowledge inside `burokku`, which the repository guidelines forbid. Modifier keys are synthesized from `flagsChanged:` as key events with no text. There is no text input event, no composition event, no physical `code`, and `characters()` bypasses the IME and dead keys. 3. **The defaults** are one `match` in `burokku/src/ui/js_bindings/events/pipeline.rs`: Tab, Command or Control with A and with C, and the primary press. Each checks `key` strings and modifier booleans itself. Nothing an element type declares takes part, which `feature-slot-events.md` leaves open as "element types in the pipeline". 4. **Engine to host** is `HostRequest` (#184), decided and not built. The input element needs it: the IME must learn the caret rectangle and the selection from the engine. ## Decided Settled on 2026-10-21. 1. **The boundary goes one way, and IME is no exception.** Native never asks the engine anything. What the platform's text system asks synchronously, the selected range, the marked range, the caret rectangle, and the text around the caret, native answers from a mirror the engine sent it; see The mirror. 2. **The mirror is a snapshot, at most one turn old.** The engine sends a new `TextInputContext` through `HostRequest` whenever any of it changes, and native keeps the last one in a `Cell>` slot taken out for one answer and put back. Its text is bounded, the text around the caret rather than the whole value, and its ranges are UTF-16 units, since `NSRange` is, so native does no text indexing. 3. **The input types speak DOM.** `KeyEvent` gets `key` and `code` in DOM vocabulary, made in `native/src/platform/`, and loses `text` and `logical_text`. Text arrives as `InputEvent::TextInput`, a composition's changes as `InputEvent::Composition`, and a bound key's meaning as `InputEvent::Command`. `keyboard_key` leaves the host for `platform/macos.rs`. 4. **The platform binds keys; Burokku keeps no key table.** `EditCommand` is a closed enum named after `beforeinput`'s input types where one exists. On macOS it has two sources: the key-binding dictionary, through `interpretKeyEvents:` and `doCommandBySelector:`, and the Edit menu, whose actions reach the first responder. Users change either in System Settings, and Burokku never second-guesses them. A platform maps what it has onto `EditCommand` and drops the rest. 5. **Burokku installs a standard Edit menu on macOS.** Undo, Redo, Cut, Copy, Paste, and Select All, with their standard key equivalents. On macOS these shortcuts are the menu's, not the dictionary's, so without the menu there is no Command+C. 6. **`keydown` fires for menu key equivalents too.** AppKit never calls `keyDown:` for a key the menu takes, so the view sends the key from `performKeyEquivalent:` and remembers it, so that `keyDown:` does not send it twice when the menu declines. Browsers fire `keydown` for Command+C, and so does Burokku. 7. **The engine's fixed defaults shrink to three commands:** `FocusNext`, `SelectAll`, and `Copy`. Keys themselves have no defaults any more: what a key does arrived as the command behind it. Every other command is the focused element's default action, which script hears first as one cancelable DOM-shaped event: `beforeinput` for the editing commands, `copy`, `cut`, and `paste` for the clipboard ones. `SelectAll` and `FocusNext` fire nothing beyond the `keydown` that made them. 8. **Nothing native sends is dropped by Burokku.** One `InputQueue` on the engine side stands in front of the JavaScript task queue, and the rule for two of a kind in one turn is written on each `Input` variant, as `HostRequest` writes its merge rules: two moves with the same buttons held replace, two wheels in the same gesture phase add their deltas, everything else queues. A full task queue is waited on, as `queue_script_requests` already waits, never failed. The release-to-cancel special case goes, because the case cannot happen. 9. **A key owns what the platform made of it.** `Input::Key { event, follows }` carries the text, composition change, or command that arrived in the key's own native callback. Script hears `keydown` first; if a listener cancels it, the text and the command are dropped and the composition is not, as in browsers, where canceling `keydown` never stops an IME. No state crosses tasks to make this happen. 10. **One drain task at a time.** The task runs the oldest input and queues itself again while more wait, so input keeps the per-event granularity it has today against timers and promises. 11. **The queue lives on `UITreeBindingState`,** beside `script_requests`, whose shape it copies. The same answer is proposed for where `HostRequest`'s queue lives, which #184 leaves open. 12. **There is one text selection.** The input element uses `SelectionState` and keeps none of its own: its text is a `user-select: contain` region with the input as the container, so `selection_container` already keeps a selection inside it and the document's out. The instance owns the value; the engine owns the selection, as `engine_state.md` already says of selection and focus. `selectionStart` and `selectionEnd` are views on the one selection while it is inside that input, as `getSelection()` is. This is how Blink works, where an ``'s text is a shadow tree and its selection is the frame's; the split in the DOM API is spelling, not mechanism. (See Rejected, 2.) 13. **`SelectionState` grows and is not rewritten.** It gains a caret, a collapsed selection that paints and blinks inside an editable container; `SelectAction::Move { unit, direction, extend }`, which `EditCommand::Move` asks for, and which gives a non-editable `contain` region Shift+arrow extension for free; and re-anchoring, so that an edit under the selection moves its positions with the text in the same `give`. The pointer defaults, the script surface, and the cursor stay as they are. 14. **The mirror is built from the one selection.** The input's instance converts `Interaction.selection` to UTF-16 offsets in its value when it builds `TextInputContext`. 15. **#184 is fourth, not first.** It touches the drain in `prepare_to_wait`; the series touches the push side and the pipeline. It can run beside the series on its own branch and blocks only the input element; see Order. 16. **The memory backend binds no keys.** A test sends the key and then the command the platform would have bound, explicitly. That keeps the backend small and makes each test state the contract it relies on. 17. **Queue order holds across a cancel.** A press queued before a `PointerCancel` still dispatches, then the cancel, as browsers deliver input in the order it came. Discarding the press would make the queue decide what a cancel cancels, which is pipeline knowledge, not the queue's: today it only merges adjacent inputs of one kind. And the press may already be out of the queue when the cancel arrives, so discarding would change only the case where script was slow, and the app would see two behaviors for one gesture. Kept in order, every press ends with exactly one release or cancel, and the pinned event-order tests hold. Settled on 2026-10-21, the first of the Open questions answered by the rule there. 18. **Key repeats never merge.** A held key auto-repeats, and when script is busy several repeats wait in the queue. Each is dispatched as its own `keydown` with `repeat` set, with its own command behind it, as browsers do. Merging them as moves merge would be worse: a repeat does work, one deletion or one caret move each, so ten merged into one would delete one character instead of ten, and what holding a key does would depend on how busy script was. Two moves say "the pointer is here now" and the older is worthless; two repeats say "do it again" and neither is. Editors and games count repeats per event. So the queue merges nothing but adjacent moves and wheels (Decided 8). Settled on 2026-10-21. 19. **The mirror carries the composition's character bounds.** While an IME has a composition open, say an underlined 比較 not yet confirmed, the system asks the view two things synchronously: where a range of the composition is on screen, to place the candidate window under it, and which character of the composition a click landed on, so that the IME can move its own selection there and offer candidates for that character. Both are "tell the system which character is where". `TextInputContext` therefore carries `marked_bounds`, one rectangle per UTF-16 unit of `marked`, from the same line geometry the caret comes from, and native answers both questions by looking up those rectangles. A click outside the composition answers not found, and no IME is known to need more. No event reaches the engine in any of this, and no event leaves it: the IME's own selection is the IME's, and only `setMarkedText:` and `insertText:` come back, as `Composition` and `TextInput`. Chrome is remembered to keep the same per-character cache in its browser process, which is to be checked, but the decision stands on its own. Settled on 2026-10-22. 20. **`WindowEvent` splits into `WindowEvent` and `InputEvent`.** The browsers rule gives no answer here, since nothing script can see turns on it; it is settled on what reads cleaner once this series is built. Lifecycle events, `CloseRequested`, `Resized`, `ScaleFactorChanged`, `RedrawRequested`, `Focused`, and `Occluded`, are handled by the host on the spot: layout, redraw, close. Input events, the keyboard, the pointer, the wheel, `ModifiersChanged`, and the new `Command`, `TextInput`, and `Composition`, all do one thing: a hit test and `push_input`. Split, the boundary this plan is named for has a type, `InputEvent` is everything native sends the engine, and the host's `match` on it is one line per arm. `ApplicationHandler` gets an `input_event` method beside `window_event`, the host's `handle_window_event` becomes two functions, and the test entry `send_window_event` gets `send_input_event` beside it, so a test says which it is sending. Checked on 2026-10-22: `DispatchStep` imports nothing from `native`, the pipeline's `Input` is the host's own translation, and the only native types inside the engine are the leaf values `Modifiers` and `WheelPhase`, and `EditCommand` after this plan; so the chain changes by nothing. Lands in PR 1, which touches every `KeyEvent` test already. Settled on 2026-10-22. 21. **`surrounding` is 100 UTF-16 units on each side of the selection.** The text system asks for text as well as positions, through `attributedSubstringForProposedRange:`, for reconversion of confirmed text back into a composition and for ranking candidates by context. The whole value would be resent every turn and is more than any IME reads; nothing would lose reconversion. A fixed window around the selection is what browsers keep, Chrome's remembered as 100 each side, and a number of our own would be no better. It is one constant where the input element fills the mirror, such as `SURROUNDING_UNITS`, with `surrounding_start` saying where the window begins; a range the IME asks for beyond it is answered with the part that is there, through `actualRange`. The constant is not part of any type: native gets a string and its start and cannot tell how it was cut, so changing it later changes one line. Settled on 2026-10-22. 22. **Other platforms fit the same two halves.** Text and composition look alike on all three: macOS has `insertText:`, `setMarkedText:`, and `attributedSubstringForProposedRange:`; GTK's `GtkIMContext` has `commit`, `preedit-changed`, and `retrieve-surrounding`; Windows' TSF has `SetText`, the composition range, and `GetText`. Each is a commit, a composition, and a read of the surrounding text, so `TextInput`, `Composition`, and the mirror can be filled on every platform. Key bindings differ: macOS has a system dictionary, GTK has bindings in its text widgets that follow the user's key theme, Emacs included, and Windows has no table to read, only fixed conventions. So, as Chrome is remembered to do, GTK binds keys through GTK itself, by handing the key to a hidden `GtkTextView` and reading the editing action it would take, which keeps Decided 4's "the platform binds keys"; Windows uses a fixed table of its conventions, as a table of our own would be the same thing. Only the direction is settled: neither backend is written, the details are matched when it is, and #119's question of whether IME belongs to the window or the app comes first. Settled on 2026-10-22. ## The boundary ### The mirror In `native/src/event.rs`, and sent through `Window` as `CursorIcon` is: ```rust /// What the focused text input shows the platform's text system, so that /// it can place a candidate window and read the text around the caret. /// The engine sends a new one whenever any of it changes; the platform /// answers its own synchronous questions from the last one it got, and /// never asks the engine. #[derive(Clone, Debug, Default, PartialEq)] pub struct TextInputContext { /// Text around the caret, bounded by the engine, not the whole value. pub surrounding: String, /// Offset of `surrounding` in the whole value, in UTF-16 units. pub surrounding_start: usize, /// The selection, in UTF-16 units of the whole value; empty at the caret. pub selection: Range, /// The composition the IME is editing, if one is open. pub marked: Option>, /// One rectangle per UTF-16 unit of `marked`, in physical pixels of /// the window, so that the platform can place its candidate window /// under any part of the composition and tell which character a /// click inside it landed on. Empty when `marked` is `None`. pub marked_bounds: Vec>, /// Where the caret or selection is drawn, in physical pixels of the /// window, for the candidate window. pub caret: PhysicalRect, } ``` The setter joins `set_cursor` on `WindowBackend`, with a default that does nothing, which the memory backend keeps: ```rust /// Tells the platform's text system about the focused text input, or /// `None` when none has focus, so that it can open and place an IME /// composition. The platform keeps it until the next call and answers /// its own questions from it; it never asks the engine. fn set_text_input_context(&self, context: Option) { let _ = context; } ``` On the engine side it is one `HostRequest` variant, `SetTextInputContext (Option)`, same turn twice: last wins. The input element's instance pushes a fresh snapshot from its `give` after any turn that moved its caret, changed its value, or gained focus, and the focus chain pushes `None` when focus leaves it. What this costs: a click outside the composition finds no character, since `marked_bounds` covers the composition alone, and a fast typist refreshes the mirror every turn, which with `surrounding` at 100 units each side (Decided 21) and a few rectangles while a composition is open is a few hundred bytes and not worth diffing. ### What comes back Next to `KeyboardInput` in `InputEvent`: ```rust /// What the platform bound the key that preceded it to. Always follows /// the `KeyboardInput` that made it, in the same native callback. Command(EditCommand), /// Text the platform's text system committed, after the key that made /// it and any composition it ends. `replace` is the range it replaces, /// in UTF-16 units of the value, or the selection when `None`. TextInput { text: String, replace: Option> }, /// The IME changed the open composition: `text` is what it shows, /// `selection` is the caret inside it. Empty `text` closes it. Composition { text: String, selection: Range, replace: Option> }, ``` A command can arrive with no key, from a menu item clicked with the pointer; text and a composition change can too, when an IME commits a candidate the user clicked. ## The input types `KeyEvent` becomes: ```rust pub struct KeyEvent { /// The DOM `key` value: the character the key makes with the layout /// and modifiers applied, or a named key such as `ArrowLeft`. pub key: String, /// The DOM `code` value: the physical key, such as `KeyA`. pub code: String, /// The platform's numeric virtual key code, for what `code` cannot say. pub key_code: u16, pub state: ElementState, pub repeat: bool, pub modifiers: Modifiers, } ``` `EditCommand` is closed, and named after `beforeinput`'s input types where one exists, so each maps to one script event: ```rust pub enum EditCommand { // caret and selection Move { unit: TextUnit, direction: Direction, extend: bool }, SelectAll, // deletion DeleteBackward(TextUnit), DeleteForward(TextUnit), // structure InsertLineBreak, InsertParagraph, // clipboard and history Copy, Cut, Paste, Undo, Redo, // focus FocusNext { backwards: bool }, } pub enum TextUnit { Character, Word, Line, Paragraph, Document } pub enum Direction { Backward, Forward, Up, Down } ``` `WindowEvent` keeps the lifecycle alone, and `InputEvent` carries the keyboard, the pointer, the wheel, `ModifiersChanged`, and the three new variants (Decided 20). `ApplicationHandler::input_event` delivers it. ## macOS All of this is in `native/src/platform/macos.rs`, and none of it reaches `burokku`. ### The dictionary `keyDown:` sends the key, then hands the event to the text system, always, not only while a text input has focus: Tab and the arrows come from the dictionary whether or not anything is editable. The system runs its key-binding dictionary synchronously and calls back into `insertText:`, `setMarkedText:`, or `doCommandBySelector:` before `interpretKeyEvents:` returns, which is what lets the host group them under the key (Decided 9). ```rust #[unsafe(method(keyDown:))] fn key_down(&self, event: &NSEvent) { if self.ivars().key_sent.take() != Some(event.timestamp()) { self.send_key_input(event, ElementState::Pressed); } self.interpretKeyEvents(&NSArray::from_slice(&[event])); } #[unsafe(method(doCommandBySelector:))] fn do_command(&self, selector: Sel) { if let Some(command) = edit_command(selector) { self.send(InputEvent::Command(command)); } // Unbound selectors, and `noop:`, are the application's: script // heard the keydown and that is all. } #[unsafe(method(insertText:replacementRange:))] fn insert_text(&self, text: &AnyObject, replacement: NSRange) { // Sent whatever the mirror says has focus: this runs inside the key's // own `keyDown:`, before script heard the key, and a `keydown` // listener may focus an input the text then goes to. The engine // drops it when nothing editable has focus. self.send(InputEvent::TextInput { .. }); } ``` `edit_command` maps the dictionary's selectors, `moveLeft:`, `moveWordLeftAndModifySelection:`, `deleteBackward:`, `insertNewline:`, `insertTab:`, `insertBacktab:`, and the rest of the move and delete families, onto `EditCommand`, and returns `None` for everything else. That reproduces today's Tab rule from the platform's own table: Control+Tab and Option+Tab are not bound to `insertTab:`, so no command follows them and script alone hears the key. ### The menu `MacosEventLoop::new` installs the Edit menu once. Its items carry the shortcuts, which users see and can rebind, and AppKit routes each to the first responder as an action the view implements: ```rust #[unsafe(method(copy:))] fn copy(&self, _sender: Option<&AnyObject>) { self.send(InputEvent::Command(EditCommand::Copy)); } // selectAll:, cut:, paste:, undo:, redo: the same way ``` When the menu takes a key equivalent, AppKit never calls `keyDown:`. The view sends the key from `performKeyEquivalent:` instead, returns `false` so the menu binds it, and remembers the event's timestamp in a `Cell` so that `keyDown:` skips it when the menu declined (Decided 6). AppKit offers a key equivalent to the whole view hierarchy, whichever view is first responder, so the view first offers it to the native views inside it, such as a native overlay's, through `super`. One that takes it keeps it, and the engine hears nothing. The view sends the key only while it is the window's first responder: keys typed into a native view that has keyboard focus are that view's. ### Answering the text system The view keeps the mirror in `text_input: Cell>`, and answers each question through one helper that takes the slot out and puts it back. No answer calls back into AppKit, so nothing nests, and if one ever did it would find the slot empty and answer "no context", which is safe. ```rust fn with_text_input(&self, answer: impl FnOnce(Option<&TextInputContext>) -> R) -> R { let context = self.ivars().text_input.take(); let result = answer(context.as_ref()); self.ivars().text_input.set(context); result } ``` `hasMarkedText`, `markedRange`, `selectedRange`, and `firstRectForCharacterRange:actualRange:` read the mirror's fields; `attributedSubstringForProposedRange:actualRange:` slices `surrounding` and reports the range it could serve; `firstRectForCharacterRange:` uses `marked_bounds` for a range inside the composition, only the units on the range's first line, and reports those as the actual range, and `caret` otherwise; `characterIndexForPoint:` finds the unit of `marked_bounds` holding the point, and answers not found outside the composition; `validAttributesForMarkedText` is empty. `setMarkedText:` and `unmarkText` send `Composition`; `insertText:` sends `TextInput`. While a text input is focused, the mouse handlers hand each press, release, and drag to the view's input context first (`handleEvent:`), as NSTextView does, which asks `characterIndexForPoint:`; an event the input method takes goes no further. The setter uses `Cell::replace`, so the old and the new context are both in hand with no borrow. When the old one had a composition open and the new one has none, focus moved mid-composition, and the view calls `discardMarkedText` on its input context so the IME's next `setMarkedText:` cannot land in the wrong element. ## The input queue In `burokku/src/ui/js_bindings/events/pipeline.rs`, `Input` becomes: ```rust /// Native input, one per pipeline chain. The rule for two of a kind queued /// in one turn is written on each variant; `InputQueue::push` applies it. pub(crate) enum Input { /// The pointer moved or the wheel turned. Two moves in a row with the /// same buttons held: the newer replaces the older, with its hit test. /// Two wheels in the same gesture phase: their deltas add. A phase /// change, a button change, or anything between them keeps both. Mouse(NativeMouseInput), /// The press under way was canceled. Never merged, never dropped. PointerCancel, /// A key changed, with what the platform made of it in the same native /// callback: the text it inserted, the composition it changed, or the /// command it was bound to. Never merged, never dropped. Script hears /// `keydown` first; if a listener cancels it, the text and the command /// are dropped, and the composition is not, as in browsers, where /// canceling `keydown` never stops an IME. Key { event: UITreeKeyboardEvent, follows: Vec }, /// A command with no key, from a menu clicked with the pointer. Command(EditCommand), /// Text or a composition change with no key, as when an IME commits a /// candidate the user clicked. Never merged, never dropped. Text(TextInput), Composition(CompositionUpdate), } pub(crate) enum KeyFollow { Text(TextInput), Composition(CompositionUpdate), Command(EditCommand), } ``` `InputQueue`, in `js_bindings/events.rs` beside `script_requests`, holds a `VecDeque`, whether the last push was a key that may still take follows, and whether a drain task is queued. `push` appends a follow to an open key, replaces or adds a mouse input where its variant's rule says so, and queues the rest. The host calls `close_key` at the start of its turn, since a key's follows all arrive inside the key's own native callback. A button, a phase edge, `MayBegin`, `Ended`, and `Cancelled` always keep their own entry, since a slot's drag or a stretch depends on seeing each. Draining copies `queue_script_requests`: `push_input` makes sure one task is queued, through `try_enqueue`, or through the awaited `enqueue` on a local task when the queue is full. The task pops one input, runs its chain, and queues itself again while more wait. In the host, `queue_pointer_input`, `queue_keyboard_input`, and `queue_pointer_cancel` become one `push_input` each. The "replacing dropped pointer release with cancellation" branch, `enqueue_pointer_cancel_when_ready`, and the three `enqueue_*` functions go. The hit test against the presented frame stays where it is, at push time, and the pipeline's guard keeps checking the presented revision. ## Defaults The key chain's `give` turns the follows into follow-ups, each a chain of its own after `PointerGrabLost` and the focus events, once the `keydown` outcome is known: ```rust let follows = if outcome.default_prevented { follows.into_iter().filter(|f| matches!(f, KeyFollow::Composition(_))).collect() } else { follows }; ``` The `match` in `defaults` loses its key-string arms and gains one on commands: ```rust Heard::Command(command) => match command { EditCommand::FocusNext { backwards } => Defaults::Run { focus: Some((FocusTo::Next { backwards }, FocusOptions { reveal: true, tell_instance: true })), .. }, EditCommand::SelectAll => Defaults::Run { select: Some(SelectAction::All), .. }, EditCommand::Copy => Defaults::Run { copy: true, .. }, // Every other command is the focused element's default action: its // instance hears it after script, once `beforeinput` was not canceled. other => Defaults::Element(other), }, Heard::Key(_) => Defaults::Run { focus: None, select: None, copy: false, after_pass }, ``` `Defaults::Element` is where the input element plugs in, and the answer to `feature-slot-events.md`'s open "element types in the pipeline" for keyboard input: an instance hears the commands bound to its focused element, after script, through a cancelable event. Pointer input stays as that plan left it. `docs/interaction/interaction.md`'s defaults table changes with this: the Tab, select all, and copy rows become command rows, and a key row says keys have no defaults of their own. ## Selection Decided 12 and 13. What `ui/interaction/selection.rs` gains, each testable on a `user-select: contain` region before any input element exists: - **A caret.** A collapsed selection inside an editable container paints a bar at its position and blinks on the host's frame timer. Outside one it paints nothing, as today. Built with the input element in step 6, where an editable container first exists; step 4 gives it `focus_caret`, the caret's box at the selection's focus. - **`SelectAction::Move { unit, direction, extend }`.** Moves the focus position by a character, word, line, paragraph, or to the document's end, and the anchor with it unless `extend`. Line moves keep a goal column across lines, as editors do. Shift+arrows on a non-editable region extend its selection through the same action. - **Re-anchoring.** An edit replaces a range of a paragraph's text; the selection's positions after the range move by the length difference, and positions inside it collapse to its end, in the same `give` as the edit, so the caret lands after what was typed. `pending_copy` and `take_copy_request` leave this file under #184. ## The input element Step 6 of Order, on top of everything above. Built in 6a as follows, with one change from the sketch below: the value is the raw text the input absorbs, as a `text` element's is, and the engine edits it. The instance shows it as a paragraph exactly as `text` does, lending `TextInstance`'s collecting; its type declares `editable`, which makes it focusable, in tab order as a `tabindex` of 0, and the target of the platform's text and editing commands, which the engine applies as default actions after `beforeinput`, then fires `input`. So no element holds a value of its own, no instance edits, and `Decided 12`'s split holds in the form that needed no new state: the tree owns the text, the engine the selection. `value` writes the text through the same path script's `textContent` does. The platform's `Paste` is read by the host, where the clipboard is, and sent as pasted text. 6b added the composition: the engine keeps the IME's marked range with the selection, replaces it on each change, underlines it, sends its range and one box per unit in the mirror, and ends it on a commit, a clear, or focus leaving; on macOS `unmarkText` commits the marked text as it is, built from the mirror, as `TextInput`. The events are `CustomEvent`s with `inputType` and `data` in `detail`, not the DOM's `InputEvent` class, until a reason for the class appears. Line breaks, undo, and redo do nothing yet. The sketch as planned, for what 6b still adds: It is its own selection container. It hears, after script and unless canceled: | Arrives as | Script hears | The instance does | |---|---|---| | `Text` | `beforeinput` with `insertText`, then `input` | replaces the selection with the text, re-anchors | | `Composition` | `compositionstart`, `compositionupdate`, `compositionend` | shows the marked text underlined, moves the caret inside it | | `Command::Move` | nothing new | asks `SelectAction::Move` | | `Command::Delete*` | `beforeinput` with `deleteContentBackward` and the like, then `input` | deletes the unit, re-anchors | | `Command::Cut`, `Paste` | `cut`, `paste` | through `HostRequest::WriteClipboard` and a read the host serves | | `Command::Undo`, `Redo` | `beforeinput` with `historyUndo`, `historyRedo` | its own history | | `Command::InsertLineBreak`, `InsertParagraph` | `beforeinput` | nothing in a single-line input; `change` on Enter is script's | After any of these, and on gaining focus, it pushes `HostRequest::SetTextInputContext` with the selection converted to UTF-16 offsets in its value, 100 units of text on each side of it, the caret rectangle from the paragraph's line geometry, and, while a composition is open, one rectangle per unit of it from the same geometry. The focus chain pushes `None` as focus leaves it. `selectionStart`, `selectionEnd`, and `setSelectionRange` read and write `Interaction.selection` while it is inside this input, and read `null` otherwise, as browsers do for inputs whose type has no selection. Proposed: the step splits in two when it gets there, 6a with the value, text, delete, and the caret, and 6b with `Composition` and the mirror. 6a works on the Edit menu and the dictionary alone, so IME is the only thing 6b has to prove. ## Order Each is one stacked pull request that keeps the tests green. PRs 1 and 2 change `native` only and leave the host ignoring the new variants, so a build of each branch must show the host compiling against them. | # | Pull request | What lands | Depends on | |---|---|---|---| | 0 | this plan, and a phase in `todo.md` | the decisions above | nothing | | 1 | `native`: the input types | `InputEvent` split out of `WindowEvent`, with `ApplicationHandler::input_event` and `send_input_event`; `KeyEvent` with `key` and `code`, without `text` and `logical_text`; `EditCommand`; `InputEvent::{Command, TextInput, Composition}`; `TextInputContext` and `set_text_input_context`. `keyboard_key` moves into `platform/macos.rs`. The host matches the new variants with empty arms. | 0 | | 2 | `native`: macOS binds keys | `interpretKeyEvents:`, `NSTextInputClient` on the `Cell` mirror, `edit_command`, the Edit menu, `performKeyEquivalent:`. Platform only. | 1 | | 3 | `burokku`: the input queue | `InputQueue`, `Input::Key { follows }`, the host's queue functions shrink, the pipeline's key-string defaults become command arms, the tests send key then command. | 1 | | 4 | `burokku`: selection grows | the caret, `SelectAction::Move`, re-anchoring. Shift+arrows on a `user-select: contain` region prove it. | 3 | | 5 | #184 `HostRequest` | as its issue says, plus `SetTextInputContext`, last wins. | 0; independent of 1 to 4 | | 6 | `burokku`: the input element | value in the instance, `beforeinput` and `input`, the commands as its defaults, the mirror from its `give`, `selectionStart` and `selectionEnd`. | 2, 4, 5 | ## Open None. The six questions found while writing were each answered by the rule given on 2026-10-21, follow browsers where an answer of our own would not be better, and each was explained and settled in turn; they are Decided 17 to 22. Where a browser's behavior is cited there from memory it says so, and is to be checked before the step that needs it, but no decision depends on the check. ## Rejected 1. **A key table of Burokku's own.** Growing the pipeline's `match` with Backspace, the arrows, Home, Option+arrow for words, Command+V, and Command+Z. Every binding would be Burokku's guess at a platform's conventions; macOS users with Emacs bindings or custom dictionaries would lose them, and Linux and Windows would want other tables anyway. The platform already has the table, and Decided 4 reads it. 2. **A selection of the input's own.** The DOM spells `selectionStart` apart from `getSelection()`, but an input's selection is the same thing again, anchor and focus in text with the same highlight, extension, word and paragraph clicks, select all, and copy, inside one box. Two states would mean two paints, two copies, and two mirrors. Decided 12 keeps one, as Blink does. 3. **One macrotask per native event, dropped when full.** Today's shape. It cannot merge moves, it loses keys silently, and it needed the release-to-cancel special case. An editor cannot lose characters, and a composition cannot lose a step, so the queue has to be Burokku's own. 4. **Native borrowing the engine for IME queries.** The quickest way to answer `selectedRange`, and the end of the one-way rule. The mirror costs one turn of staleness that a candidate window cannot show.