Skip to content

fix(touch): defer focus, blur, and selection changes to tap-up - #2558

Merged
Hona merged 1 commit into
devfrom
feat/touch-tap-up-focus
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
feat/touch-tap-up-focus

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Refs #2484 (answers question 3 in shared touch input across web, iOS, Android, and touchscreens).

Summary

Touching down on a screen previously ran press_down's focus, blur, and selection logic immediately on TouchPhase::Started, before TOUCH_SLOP (8 pt) could tell a tap apart from a scroll pan, pinch, edge swipe, or long press. Scrolling a list while a text field was focused therefore queued Action::Blur (dismissing the soft keyboard) or focused a scrolled-past field even when the touch turned into a pan.

This change defers touch focus, blur, and text-field caret/selection changes to tap-up in the shared touch input path, matching Chrome, Android, and UIKit:

  • runtime/input/touch_machine.rs: Mode::Pending records tap_focus (false when touch-down was swallowed by an active modal, autoscroll, another held button, or resize edge). step_single_end emits TouchEffect::CommitTap before PointerUp only when lifting within TOUCH_SLOP as a tap (and CommitWindowDragTap for bare titlebar taps). Entering Mode::Drag on non-scrollable content emits BeginTouchSelectionDrag so dragging across non-scrollable selectable text continues to select text.
  • runtime/input/pointer.rs & runtime/selection/click.rs: Extract apply_press_focus and split touch-down on text inputs (input_touch_down) from tap-up focus/caret placement (input_tap_up). Mouse presses (touch == false) are unchanged.
  • runtime/input/touch.rs: Execute CommitTap (focus/blur/selection) immediately before PointerUp so on_press handlers that call tx.focus still win, while pans, pinches, edge swipes, long presses, and cancelled touches leave focus and text selection undisturbed.
  • input/host_events.rs: In web document mode, web_touch_end_activate returns WebActivate::IfFieldFocused when nothing was focused prior to the tap so tapping an unfocused text field activates the DOM input on the first tap after tap-up commits.
  • Changelog: changelog/unreleased/2026-11-27-touch-focus-on-tap-up.md.

Testing

  • cargo test -p rune --lib -- runtime::input::touch input::host_events runtime::input::focus_key runtime::input::field_menu runtime::tests::press_pointer: 83 passed, 0 failed (including 3 new tests covering scroll-keeps-focus, tap-up focus/blur/double-tap, selection preservation on pan, and web document-mode first-tap activation).
  • cargo test -p rune --test integration -- link_drag: 6 passed, 0 failed.
  • cargo check -p rune --target wasm32-unknown-unknown: clean.
  • Not tested on physical Android, iOS, or mobile browser hardware (headless runtime tests and wasm32 compilation only).

@Hona
Hona merged commit c186059 into dev Nov 27, 2026
2 checks passed
@Hona
Hona deleted the feat/touch-tap-up-focus branch November 27, 2026 12:40
pascalandr added a commit to NeuralNomadsAI/rune that referenced this pull request Nov 27, 2026
dev now defers a finger's focus, blur and selection changes to its lift as
a tap for every touch host (anomalyco#2558), as decided on the Android design
question. The fork's own version, behind host.text_menus, goes: touch.rs,
pointer.rs and click.rs are dev's, and the fork's tests for a scroll that
keeps a field's focus, a scroll from a field and a selection kept under a
scroll pass on dev's implementation.

Kept on top of dev's: the system's long-press delay (set_touch_long_press),
whether the last finger panned (the selection toolbar's return), a long
press's cancel_steps and on_text, and a field's tap told to the host
(take_field_tap, from input_tap_up) so the keyboard comes back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant