8000 Text input by IcedDog · Pull Request #1 · void-cat-0/miniquad · GitHub
[go: up one dir, main page]

Skip to content

Text input - #1

Open
IcedDog wants to merge 18 commits into
mainfrom
text-input
Open

IcedDog wants to merge 18 commits into
mainfrom
text-input

Conversation

@IcedDog
@IcedDog IcedDog commented Nov 26, 2026
Copy link
Copy Markdown
Collaborator

No description provided.

IcedDog and others added 18 commits November 26, 2026 08:11
A platform-neutral text input protocol modeled on Flutter's text input
channel (see the text_input module docs):

- window::start_text_input(TextInputConfig) / stop_text_input() begin and
  end a session; the config selects the keyboard kind, action key,
  autocorrect, capitalization, and read-only mode.
- window::set_text_input_state(&TextInputState) sends the field's text,
  selection, and composing range (UTF-16) after local edits.
- window::set_text_input_rect(x, y, w, h) reports the caret rectangle.
- window::text_input_mirrors_state() tells whether the platform reports
  whole editing states (Android, iOS, web) or composition and commit
  events (desktop).
- EventHandler::text_input_action_event and soft_keyboard_event.

set_ime_position, set_ime_enabled, and update_text_input_state remain as
deprecated wrappers. Backends receive the new requests; their existing
behavior is mapped onto them unchanged, and each backend is completed in
its own commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The input method is associated with the window only during a session,
  and never for password or read-only fields, so game keys reach the
  application directly elsewhere. Users can switch IME modes freely: the
  window no longer forces the IME open.
- The caret rectangle positions the composition point and opens the
  candidate list beside the caret with CFS_EXCLUDE.
- During a session the IME's own composition window is hidden; the
  application draws the preedit inline.
- A result and the next composition in one WM_IME_COMPOSITION arrive in
  that order. Ending a session cancels the composition.
- WM_CHAR joins UTF-16 surrogate pairs, so emoji typed or pasted from the
  emoji panel reach char_event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- firstRectForCharacterRange returns the reported caret rectangle (size
  and position, flipped into view coordinates), so candidate windows
  open beside the caret.
- Password and read-only sessions deactivate the input context; stopping
  a session discards the marked text and clears the preedit.
- selectedRange reports the selection inside the marked text.
- doCommandBySelector: is implemented as a no-op (editing keys already
  arrive as key_down), so Backspace, Enter, and arrows no longer beep;
  characterIndexForPoint: is implemented as required by the protocol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- init_xim runs after the window is created; it was never called, so X11
  had no composition at all. Only LC_CTYPE is taken from the
  environment.
- The input context gets focus only during a session (not for password
  or read-only fields) and when the window regains focus within one;
  stopping a session resets the context, dropping any composition.
- The caret rectangle sets the spot location at its baseline.
- Preedit carets are converted from characters to UTF-16 units, and
  session checks no longer lock the display, which dropped events when
  the lock was busy. A cleared preedit is delivered after the session
  ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- preedit_string and commit_string are buffered and applied on done, in
  protocol order (commit, then the new preedit; a batch without preedit
  clears it). done is no longer answered with commit, which the protocol
  does not expect.
- Preedit carets are converted from UTF-8 bytes to UTF-16 units; a hidden
  caret goes to the end.
- Sessions enable the input method with a content type (purpose and hints
  from the kind, autocorrect, and capitalization; password fields are
  hidden, sensitive text) and a caret rectangle in surface-local logical
  pixels. The state is sent again when the surface regains text input
  focus.
- Characters from keys the input method passes through are generated
  again; only keys during a composition are skipped (they used to be
  skipped forever after the first IME use).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- startTextInput configures the hidden EditText from the session: input
  type from the kind (text, password, number, decimal, phone, email, URL,
  search, multiline) with autocorrect and capitalization flags, the IME
  action, no fullscreen editor, and no personalized learning for
  passwords. Read-only sessions keep the keyboard hidden. stopTextInput
  finishes the composition and hides the keyboard.
- setTextInputState updates the same Editable the input method edits and
  restarts input only when the text or composition changed under it;
  selection-only changes use updateSelection.
- Editor actions are reported as text_input_action_event (instead of a
  synthetic Enter key) and consumed in single-line fields; Enter in a
  multiline field still inserts a newline.
- The insets listener reports the keyboard frame as soft_keyboard_event,
  on API 30+ from the IME insets and before that from the bottom system
  inset.
- Strings cross JNI as UTF-16 (GetStringChars/NewString), so emoji and
  other non-BMP text survive in editing state and the clipboard.
- Touch events pass the event time the Rust side already expected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The backend stopped compiling when touch timestamps were added and stayed
broken through the IME rework:

- touch events carry UITouch.timestamp in the message instead of reading
  an out-of-scope touch later;
- the request and message receivers and the blocking-loop flag are
  stored in the display payload the frame callbacks drain them from;
- the unused performSelector-based processMessage path and its message
  slot are removed (messages are dispatched from the channel each frame);
- the application delegate keeps its window again, and an extra unused
  UIWindow is no longer created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Sessions configure the hidden UITextView: keyboard type from the kind,
  return key from the action, autocorrection and spell checking,
  capitalization, secure entry for passwords, and editability; traits are
  reloaded on a keyboard that is already up. Read-only sessions keep the
  keyboard hidden; stopping a session ends marked text and hides it.
- set_text_input_state writes the mirror without reporting the change
  back; only input-method edits produce on_ime_state_changed, and the
  marked range travels as the composing range (no separate preedit).
- Return in a single-line field sends text_input_action_event instead of
  inserting a newline.
- Keyboard show, hide, and frame changes send soft_keyboard_event in view
  pixels (the view still shrinks above the keyboard).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- start_text_input creates the hidden <input> or <textarea> for the kind
  (password type, inputmode, enterkeyhint, autocapitalize, autocorrect,
  spellcheck, autocomplete, readonly) and focuses it; stop blurs it.
- Every edit, composition step, and selection change is reported as one
  whole editing state; separate preedit and commit calls are no longer
  sent, so edits are not applied twice.
- set_text_input_state never writes the value during a composition the
  application has not ended, which used to cancel it.
- Enter in a single-line field is text_input_action_event; Tab, Escape,
  and undo/redo keys are forwarded to the application while the mirror
  has focus.
- The caret rectangle moves the mirror, so the browser keeps the field
  in view and places candidate windows beside it.
- The visual viewport reports the soft keyboard as soft_keyboard_event.
- Focus requested outside a user gesture (refused by iOS Safari) is
  retried on the next touch.
- The copy and cut handlers used the global event object; a focused
  mirror now copies its own selection.

The legacy update adapter used during the API transition is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
onBackPressed no longer finishes the activity: the back button (and the
system back gesture) arrives as KeyCode::Back key down and up, so the
application can close an overlay or go back a page. order_quit() now
finishes the activity on Android (it was ignored), which is how an
application exits when it has nothing to go back to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
window::haptic_feedback(HapticFeedback) plays light, medium, heavy,
selection, success, warning, or error feedback: Android
View.performHapticFeedback (CONFIRM/REJECT from API 30), the iOS impact,
selection, and notification feedback generators, and navigator.vibrate on
the web. Desktop platforms ignore it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Migrate with cargo fix for every platform target (Windows, Linux,
Android, web, iOS, macOS): unsafe extern blocks, unsafe attributes, and
explicit unsafe blocks inside unsafe functions. References to static mut
items go through raw pointers.
Fix the warnings clippy reports on every supported target and the
examples: C string literals, explicit unsafe blocks in unsafe fns,
iterator loops, if-let instead of is_some + unwrap, and the new text
input API in the IME example. FFI entry points that take raw pointers
from the platform keep their signatures and allow the lint instead.
The surface used to be padded by the keyboard height, so opening the
keyboard shrank the window: layouts reflowed, scroll positions jumped,
and anything sized from the window (UI scale) changed, which was most
visible in landscape. The content now always lays out behind the system
bars and the keyboard (decor no longer fits system windows on API 30+,
layout flags before it), the layout pads for the system bars only, and
the keyboard is reported as a rectangle over the bottom of the surface.

Full screen now hides the system bars with WindowInsetsController on
API 30+ instead of only extending the layout.
Switching focus between fields with the keyboard open could copy the
previous field's text into the new one. Editing states travel from the
UI thread to the application through a queue, so a report from the old
field could arrive after the application had started the new session,
and the hidden EditText still held the old text while the input method
reconnected.

Every start_text_input now gets a session id. Java tags each state
report and action key with it, and the backend drops reports whose id
is not the current session. Starting a session clears the EditText
before the input method reconnects and stays silent until the field's
own text arrives; stopping clears it too, so no text lingers.
A long press used to open the hidden EditText's context menu after a
fixed timer, wherever the finger was, which looked unlike the floating
toolbar that native fields and Chrome show and ignored what the
application selected.

window::show_text_menu(rect) now opens the floating toolbar
(ActionMode.TYPE_FLOATING) above the selection bounds the application
passes; calling it again moves it, and hide_text_menu, a new touch, or
the end of the session closes it. Cut, Copy, Paste, and Select all
apply to the mirrored selection and reach the application as ordinary
editing-state changes; secure fields offer neither Cut nor Copy, and
read-only fields only Copy and Select all. The surface no longer runs
its own long-press timer, so a long press ends as a normal touch.
Other platforms ignore the request.
Every key press that looked up to characters while a text input session
was active sent an empty preedit, even with no composition. Ctrl+A looks
up to U+0001, so select-all was followed by an empty preedit, which
editors apply by replacing the selection: the field was cleared. The
empty preedit is now sent only to end a real composition, and control
characters from shortcuts are dropped from the looked-up text.
dpi_scale was always 1 on Android, so high_dpi had no effect and one
logical pixel was one physical pixel: interfaces sized in pixels were
tiny on dense phone screens. With high_dpi the backend now reads
DisplayMetrics.density and reports it as dpi_scale, so logical pixels
are density-independent pixels, as in native Android UI.
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

0