Skip to content

Studio: stop the macOS desktop app typing stray control characters for unhandled keys - #14815

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
debojyoti-dev:fix/macos-composer-arrow-keys-14764
Oct 23, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
debojyoti-dev:fix/macos-composer-arrow-keys-14764

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14764

Before: in the macOS desktop app, pressing the left arrow at the start of the chat box (or the right arrow at its end, or Home / End) typed a stray, invisible control character into the message. Windows and the web UI did nothing, as expected.

After: those keys leave the field unchanged on macOS too. Every key keeps its normal behaviour, and typing, paste, IME, tabs and line breaks are untouched.

Why: the desktop app's webview is a child view (Tauri's unstable feature, tauri-apps/tauri#10194). When the page leaves a key unhandled, macOS hands it back to the window, whose text input inserts the key's classic control character into the focused field: U+001C for left, U+001D for right, U+0001 for Home, U+0004 for End. A plain (non-child) webview does not do this.

How: src/lib/mac-stray-key-text.ts adds one capture-phase beforeinput listener on the window, installed from main.tsx only in the Tauri app on macOS. It cancels an insertText whose data is only C0 control characters or DEL (tab, line feed and carriage return excluded). No key types those on purpose, so nothing else is filtered, and no keydown handling changes.

Verified on real macOS 15, macOS 26 and macOS 27.0.1 (26A434, the reporter's version, via the xcode-27 image) runners with a wry 0.57.0 / tao 0.37.1 app (the versions Studio's Cargo.lock pins), keys sent as real CGEvents:

Key Child webview, before Child webview, this PR Plain webview (control)
Left at start (textarea, input, empty field) inserts U+001C unchanged unchanged
Right at end (textarea, input) inserts U+001D unchanged unchanged
Home at start inserts U+0001 unchanged unchanged
End at end inserts U+0004 unchanged unchanged
Left mid-text, Up/Down, Shift/Option+Left, Page Up/Down, Escape caret moves or nothing same same
Typing x inserts x inserts x inserts x

A keydown guard that only cancels arrows at the caret's ends fixed the arrow rows but still let Home and End through, which is why this filters the insertion instead.

Tests: tests/mac-stray-key-text.test.ts covers the stray characters, kept text (letters, accents, tabs, line breaks, mixed text), other input types (paste, drop, autocorrect, composition, deletion), the capture-phase listener, and the install being limited to the macOS desktop app.

Bundle: the guard is eager in main.tsx, +278 B raw / +129 B transfer at startup, so check-bundle-budget.ts is raised by exactly that. Re-measured against 14e0178: +114 B transfer / +278 B raw. Main without this PR measures 2,086,290 B transfer against its own 2,085,990 B budget there, so that step is red on main independently of this change.

Before / after on macOS 26 (child webview, real key events, screenshot after each press)

Left, Right, Home and End at the ends of a field: main types a control character, this PR leaves the field unchanged

Left: main types U+001C / U+001D / U+0001 / U+0004 (drawn as boxes). Right: with this PR the field stays abc.

…d on macOS

In the macOS desktop app, pressing left at the start of the chat box or
right at its end typed a stray character. The arrow could not move the
caret, so the page left the key unhandled, and the native fallback
inserted the key's private-use character (U+F702 and friends).

On the macOS desktop app only, mark an arrow that cannot move the caret
as handled, after the app's own key handlers have had their turn. The
field stays as it was, which is what Windows and Safari already do.
Selections, modified arrows, IME composition and right-to-left fields
behave as before.

Refs unslothai#14764
The stray characters are C0 controls (U+001C left, U+001D right, U+0001 Home,
U+0004 End) inserted through the window's text input after the child webview
leaves the key unhandled, so a caret-boundary keydown guard missed Home and End.
Cancel those insertText beforeinput events instead: every key keeps its own
behaviour and typed text, tabs, line breaks, paste and IME are untouched.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T09:47:09.486230Z 45d28e3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 50bdcb7012

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 045e56e606

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@danielhanchen danielhanchen changed the title Studio: stop arrow keys typing stray characters at the ends of a field on macOS Studio: stop the macOS desktop app typing stray control characters for unhandled keys Oct 23, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 23, 2026
# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 45d28e3001

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 394aff8 into unslothai:main Oct 23, 2026
4 of 38 checks passed
danielhanchen pushed a commit that referenced this pull request Nov 4, 2026
…16583)

In the macOS desktop app, pressing Home or End in a text field of a web
page open in the browser panel types an invisible control character
(U+0001 or U+0004) into the field. Nothing shows on screen, but a search
box or form then sends the query with those characters in it. The same
keys in Studio's own chat box were already fixed in #14815, but browser
panel pages are separate webviews and never got that fix.

Browser panel pages on macOS now drop typed text that is only control
characters, the same filter Studio's own window uses, in every frame of
the page. Normal typing, Enter, Tab, paste and caret movement are
unchanged, and other platforms are not affected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Arrow key problem in MacOS chat window

2 participants