Files
orca/docs/reference/macos-press-and-hold.md
T
Neilandinnocarpe f400f8fd5f fix(macos): opt out of press-and-hold so held keys repeat (#14746) (#15589)
* fix(macos): opt out of press-and-hold so held keys repeat (#14746)

macOS routes press-and-hold to the accent picker unless an app sets
ApplePressAndHoldEnabled=false for its own bundle, so holding j in vim
inserted one character instead of repeating. Orca never set it.

Written at most once, and never over an explicit value: `defaults read`
is domain-scoped and exits 1 when the key is absent, which is the only
way to tell "unset" from a deliberate false — Electron's
systemPreferences.getUserDefault reports false for both. A recorded
decision in userData keeps a later launch from re-clobbering a user who
deletes the key to get the accent picker back.

* docs(macos): record the revert hazard and CI's macOS test gap

Two things a reader of this module cannot otherwise know.

A revert leaves the key written in every user's domain forever. AppKit reads
the plist, not this file, so removing the code alone keeps press-and-hold
disabled for everyone who ran an affected build. The sibling period-substitution
module carries the same warning because that fix was already lost once this way.

And the real-binary test file that pins the defaults(1) exit-code semantics this
design rests on never runs in CI: the e2e workflow and both unit-test jobs are
ubuntu and windows, and the only macOS runners in the repo are build and
packaging jobs that run no tests. Those six tests plus the real-bundle e2e case
pass on a developer Mac and execute zero times in a green PR, so the comment
should not imply enforcement that is not there.

Refs #14746

* feat(macos): let users turn the accent menu back on (#14746)

Orca disables press-and-hold for its own preferences domain so held keys
repeat. That is the right default, but the way back was a `defaults write`
buried in a source comment: nothing in docs/ or the README mentioned it, and
the preference is per-application, so it silently takes the accent picker
away from the Markdown editor and every other text field too.

Terminal -> Advanced now carries a "Character Accent Menu" switch, macOS and
desktop only. A web client cannot write a macOS preference for the machine the
user is looking at, so the control and its search-index entry are both gated on
that, not on the client's platform alone.

Precedence, which is the part that is easy to get wrong: the setting is
`undefined` until the user touches it, which is what keeps a hand-run `defaults
write` in charge for everyone who never opens the toggle. Once used, Orca owns
the key and writes exactly what the switch asks for -- `ApplePressAndHoldEnabled`
*is* the accent-menu switch, so it maps straight through with no inversion. The
choice is compared against `appliedSetting` in the existing decision record
rather than against the domain, so a `defaults write` made *after* using the
toggle is still the newer choice and survives the next launch. Re-asserting the
value every launch would have reintroduced the clobbering the record exists to
prevent.

The write lands for the next launch, since AppKit reads the preference as the
process starts, so the toggle shows the same restart banner the window-blur
setting uses. That banner is now a shared component, keeping its original
translation keys.

docs/reference/macos-press-and-hold.md records the precedence rules, the
`defaults read` rationale, the revert hazard, and the fact that none of this
executes in CI: every macOS job builds or packages and runs no tests, so the
real-binary and e2e coverage here passes only on a developer Mac.

* docs(macos): stop asserting when AppKit re-reads the press-and-hold key

Five places stated "AppKit reads the preference as the process starts" as
fact. That is the reason given for requiring a relaunch, and it is not
something this change ever measured.

Evidence points the other way: terminal emulators that register this key
after their process has started get key repeat in that same launch, which a
read-once-at-startup model cannot explain.

The relaunch requirement itself still looks right, but for a different and
verifiable reason: the write goes out through a separate `defaults` process,
so this app's own cached copy need not observe it. That is what the comments
now say, with the AppKit question left open rather than answered.

Refs #14746

* docs(macos): correct the startup comment's launch-timing claim

The comment said this call site is "the last point that can still matter for
this launch", which contradicts the rest of the module: the write is assumed
to land for the next launch because it goes out through a separate `defaults`
process. Reported on the PR by @innocarpe, who also supplied the replacement
wording.

Co-authored-by: innocarpe <innocarpe@users.noreply.github.com>

* refactor(macos): probe press-and-hold through the shared spawn chokepoint

`src/shared/child-process/child-process-import-boundary.test.ts` forbids a
direct `node:child_process` import outside its allowlist, and the allowlist only
shrinks — so this module moves to `runProcessSync`, which exists for callers
that genuinely cannot await. This one runs before `app.whenReady()`.

`runProcessSync` returns a non-zero exit instead of throwing it, so the
three-way read decision is re-expressed against `ProcessResult`: exit 0 is an
explicit value, exit 1 is a missing key, and a timeout, a signal kill, any other
exit, or a child that never started all stay 'unknown'. The throw path is now
inside `interpretDefaultsRead` so a spawn failure is reachable from a test
rather than hidden in an untested catch, and the write checks the exit code —
a refused `defaults write` no longer looks like success.

Both boundary-test failures were the same import: with it gone the offender
count returns to 155, so no ratchet baseline is bumped.

* Revert "feat(macos): let users turn the accent menu back on (#14746)"

This reverts commit cc5669f306.

---------

Co-authored-by: innocarpe <innocarpe@users.noreply.github.com>
2026-08-27 13:44:03 -07:00

2.3 KiB

macOS press-and-hold and key repeat

macOS opens the accent picker when a key is held unless an application opts out in its preferences domain. That prevents held keys from repeating in terminal applications such as vim. On the first eligible launch, Orca writes:

defaults write com.stablyai.orca ApplePressAndHoldEnabled -bool false

The write is scoped to Orca's packaged bundle domain. Bare Electron development bundles and non-macOS platforms are left untouched. A fresh write is conservatively treated as taking effect on the next launch.

Precedence and decision record

Orca checks for an explicit domain value before writing. Either true or false is treated as a user choice and preserved. Only an unset key receives the false default.

The decision is stored once in <userData>/macos-press-and-hold-default.json. An applied or kept-user-preference decision prevents future launches from touching the domain again. Probe and write failures remain retryable so a transient failure does not permanently disable the fix.

defaults read <domain> <key> is used instead of systemPreferences.getUserDefault: the Electron API cannot distinguish an unset key from an explicit false. Only the missing-key exit status is interpreted as unset; spawn failures, timeouts, and other exit statuses leave the preference alone.

Restoring the accent picker

Set the preference explicitly, then restart Orca:

defaults write com.stablyai.orca ApplePressAndHoldEnabled -bool true

After Orca has recorded its one-time decision, deleting the key also restores the macOS default without Orca recreating it:

defaults delete com.stablyai.orca ApplePressAndHoldEnabled

Development and prerelease channels may use a channel-suffixed Orca bundle identifier; use that domain instead when applicable.

Reverting

Deleting the startup code is not enough. AppKit reads the persisted preference, so a code revert must also arrange to delete the key for users who ran an affected build.

Test coverage

Unit tests cover platform guards, explicit-value preservation, retry behavior, domain ownership, record persistence, and subprocess exit interpretation on CI. A macOS-only test additionally pins the real defaults(1) behavior, but current PR CI does not execute tests on macOS.