squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

Squirrel commits latin letters instead of composing, after latin was typed just before it was selected

Open ShunmeiCho opened this issue 2 months ago • 0 comments

On macOS 27.0 Squirrel intermittently receives keystrokes as committed latin text rather than composing them, while every input-source identity the system exposes correctly names Squirrel. It is reproducible, and the trigger is typing latin in another source immediately before selecting Squirrel — which is what happens every time a user switches from English back to Chinese.

I have not been able to find the cause inside Squirrel, only to narrow down what it is not. The measurements are below in case they save someone time.

Environment

  • macOS 27.0 (build 26A428), Apple Silicon
  • Squirrel bundle version 1.1.2, schema im.rime.inputmethod.Squirrel.Hans
  • ascii_composer/switch_key/Shift_L and Shift_R both set to noop in the user's patch, so Shift is not switching to ASCII mode
  • Other input methods on the same Mac (WeType Pinyin, azooKey, Google Japanese Input) do not show this under the same harness

What happens

  1. Select a latin keyboard layout (com.apple.keylayout.ABC).
  2. Type at least one latin letter into a text client.
  3. Clear it, then select Squirrel via TISSelectInputSource and wait until the system reports it.
  4. Type nihao.

Expected: a composition builds and candidates appear. Observed, intermittently: each letter is committed as plain latin, and the client ends up holding nihao.

If step 2 is skipped — switch away to the latin layout but type nothing — it does not reproduce (6 of 6 passes in that variant). Typing a single latin letter first brings the failures back.

Rates measured

harness attempts failed
background process selects, separate process owns the text view 40 21
switch through a hotkey utility, typing into TextEdit 8 6
same, a later session 14 14

Failures arrive in blocks rather than singly, so short runs disagree with each other.

What the text client sees

A probe with its own NSTextView recorded every insertText / setMarkedText callback together with three identities per snapshot: the system's current source, NSTextInputContext.current? .selectedKeyboardInputSource, and the text view's own inputContext.selectedKeyboardInputSource.

attempts latin committed setMarkedText insertText
all 40 21 95 145
failing attempts 21 21 0 126
passing attempts 19 0 95 19

A failing attempt produces no composition callback at all; each letter arrives as committed text, exactly as a keyboard layout would deliver it. A passing attempt shows the expected setMarkedText("n") → setMarkedText("ni") → … → insertText("你好").

In all 1440 snapshots the three identities agreed on im.rime.inputmethod.Squirrel.Hans, both input contexts were the same object, and that object's client was the text view being typed into. There is no ABC client, no nil client, and no stale context on a failing attempt.

What this does not establish

selectedKeyboardInputSource is documented to name the selected input source, and nothing more — it is not a receipt that a given key was handled by that input method. So these measurements do not distinguish between:

  • Squirrel is attached and in a latin pass-through state, and
  • the selection is recorded but Squirrel's handling never ran for those keys.

Telling those apart needs telemetry from inside Squirrel, which is why I am reporting the observations rather than a diagnosis.

Ruled out

Each of these was measured, not assumed:

  • Not caused by the hotkey utility I maintain. With it fully quit and the switch made by a plain TISSelectInputSource call, the failure rate was the same or worse (5 of 6 failed).
  • Selecting a second time 150 ms after the switch: still fails (8 of 8).
  • Re-activating the frontmost application after the switch, the approach macism uses: still fails.
  • A warm-up keystroke (Escape) before typing: 6 of 6 once, 4 of 6 on the repeat — noise, not a fix.
  • A warm-up modifier tap: 5 of 6.
  • Selecting through the hotkey versus directly: both fail.

Reproducing it

The text-client probe is a small AppKit program: it owns an NSTextView, a second process performs the TISSelectInputSource call so the selecting process is not the one synthesising keys, and every callback is logged with the three identities above. I am happy to clean it up and attach it, or to run a patched Squirrel build against it and report what the extra logging shows — whichever is more useful.

One caveat on harnesses generally, learned the hard way here: if the process that synthesises the keystrokes is also the one that called TISSelectInputSource, composition breaks for reasons that have nothing to do with Squirrel. Every measurement above keeps those in separate processes.

ShunmeiCho avatar Sep 20 '26 16:09 ShunmeiCho