Skip to content

fix(input): clear composition with Command-Backspace - #1201

Open
riversky0014 wants to merge 1 commit into
rime:masterfrom
riversky0014:codex/cmd-backspace-clear-composition
Open

riversky0014 wants to merge 1 commit into
rime:masterfrom
riversky0014:codex/cmd-backspace-clear-composition

Conversation

@riversky0014

Copy link
Copy Markdown

When a composition is active, Command-Backspace currently bypasses Squirrel and is handed to the client application, so it cannot reliably clear the pending input. This adds a narrow exception: Command-Backspace discards the entire uncommitted composition and refreshes the marked text and candidate UI, including when the caret is in the middle or an earlier segment has already been selected.

On macOS, Command-Backspace is commonly used to delete back to the beginning of a line. Treating the pending input as a single editing unit makes clearing it with the same shortcut a natural extension of that convention. Once there is no composition, the event still belongs to the client app and retains its normal editing behavior.

The handler only consumes plain Command-Backspace while librime reports an active composition. Caps Lock does not disable the shortcut; Shift/Option/Control/Fn combinations, forward Delete, and other Command shortcuts are unchanged. Pending chord releases are cancelled before clearing so a chord timer cannot replay stale input.

Related: #805. This does not enable arbitrary Command key bindings; it handles one composition-editing shortcut when the event is delivered to Squirrel.

Validation:

  • git diff --check, Swift parser check, and repository-wide SwiftLint 0.65.1 passed (SwiftLint reports a complexity warning in the unchanged rimeUpdate method).
  • A standalone Swift harness compiled the exact modified Command-key branch with the repository's key conversion and bridge helpers, real AppKit NSEvent objects, and librime 1.16.0 against an isolated user-data directory. All 21 checks passed: full composition, middle caret, partially selected composition, Caps Lock, repeat events, empty/ASCII state, extra modifiers, other Command shortcuts, key release, and failed status lookup. Clear operations produced no committed text and requested a UI refresh.
  • Full Xcode build and end-to-end tests in client applications have not been run locally: this machine has Command Line Tools but no full Xcode installation. The harness validates the handler/backend boundary, not InputMethodKit event delivery or actual client UI behavior.

@riversky0014
riversky0014 force-pushed the codex/cmd-backspace-clear-composition branch from ba34258 to 0797c14 Compare November 6, 2026 03:19
@lotem

lotem commented Nov 7, 2026

Copy link
Copy Markdown
Member

代碼看着不錯。
但是 Command 組合鍵從沒用過,需要廣泛測試各種應用程序,比如 Finder 改名界面,會不會先把文件刪了?

@riversky0014

Copy link
Copy Markdown
Author

我测试了 Finder, VSCode 与 Photos,只要是在输入框做输入的时候,按 command+backspace 不会出现问题,行为表现与现有的 option+backspace 表现一致。我是用 github actions 在这个分支上编译得到的 Rime MacOS APP,然后在我本地MacOS(15.7)上使用的,已经有使用一段时间了,command+backspace 的行为表现正常。另外其实是我从 搜狗输入法 迁移过来带来的习惯,command+backspace 在搜狗输入法上是删除当前键入框里的全部内容,故而想到给 Rime 增加这个功能

@lotem

lotem commented Nov 9, 2026

Copy link
Copy Markdown
Member

輕信聲張,Finder 重命名文件時測試,⌘+⌫ 直接給文件刪了……

我是不敢用了。系統快捷鍵還是留給系統和應用程序吧。

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.

2 participants