Skip to content

feat(native): expose programmatic text selection - #430

Closed
tiensonqin wants to merge 2 commits into
native-parity-0.1-backportsfrom
devin/1788888888-native-set-selection
Closed

tiensonqin wants to merge 2 commits into
native-parity-0.1-backportsfrom
devin/1788888888-native-set-selection

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Lui_window.Ui.set_selection ui store id ~anchor ~caret — the native counterpart of the DOM's setSelectionRange. Until now the interaction machines exposed no way to place the editable selection programmatically, so hosts emulated select-all by synthesizing a primary-modifier+A keydown and could not represent any other range.

  • Focuses id when it is not focused (reusing the ordinary focus_move attach path), then sets the session selection to [min anchor caret .. max anchor caret) via the existing Lui_text_input.set_caret machinery.
  • Offsets are byte positions into the node's text, clamped to the text length and rounded back to UTF-8 sequence starts through Lui_query.clamp_boundary — the browser's clamping semantics applied to UTF-8 storage.
  • No-op for node 0 or unknown nodes; keyboard/pointer selection behavior is unchanged.

Recorded in docs/api-migrations.md. Regression coverage: programmatic set_selection in lui_window_test verifies mid-range replacement typing, out-of-range clamping and UTF-8 boundary rounding without mocks.

Ui.set_selection ui store id ~anchor:2 ~caret:4

Link to Devin session: https://app.devin.ai/sessions/c5d7e54b078e47e28153404536bb3def
Open in Devin Desktop: https://app.devin.ai/desktop/session/c5d7e54b078e47e28153404536bb3def?variant=devin
Requested by: @tiensonqin


🟢 Devin fixed all 2 findings · Follow Devin's work

Devin Review

Lui_window.Ui.set_selection focuses a node when needed and places the
editable selection at byte offsets, the native counterpart of the DOM's
setSelectionRange, so hosts no longer need to emulate select-all through
the primary-modifier+A accelerator. Offsets clamp to the text length and
round back to UTF-8 sequence starts.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

set_selection now returns actions carrying Focus_changed when it
focuses the node, so drivers start text input and update accessibility
focus; the interface documents that hosts should sync the store first,
and the migration guide gains a concrete select-all example.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Selection focus bypasses native text input — Fixed in 6b657b2: set_selection now returns actions carrying Focus_changed when the focus moves, so drivers start text input and update accessibility focus exactly like keyboard/pointer focus paths.
  • Missing select-all migration example — Fixed in 6b657b2: docs/api-migrations.md now includes a concrete select-all migration example replacing the accelerator hack.

View findings in Devin Review · Follow Devin's work

Devin Review

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