Skip to content

Selection gets out of sync when tapping into text while a toolbar input is focused #343

Description

@johannesmutter

What happens

While the toolbar's URL input is focused, tap into a different node's text — for example from one button's text into another button's text. The caret visibly moves to the new button, but the toolbar still shows the previous button's data (e.g. its link URL). The selection debug panel confirms the model selection still points at the old node.

Why

While an app input has focus, canvas_focused is false and onselectionchange deliberately ignores selection changes (src/lib/Svedit.svelte) — so typing in inputs isn't misread as canvas selections.

On iOS Safari, tapping into text fires selectionchange before the canvas gets its focus event. That one event falls into the ignored window and no further selectionchange comes after focus settles. Result: the visible caret and the model selection are out of sync until the next tap or keystroke.

Suggested fix

When the canvas regains focus (handle_canvas_focus), read the current DOM selection once and map it to the model — the same thing onselectionchange does. That picks up any caret placed during the unfocused window.

Related: #342 (same family — toolbar inputs vs. canvas focus).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions