Restore Zhuyin IME candidate marked-text handling

Merged
AU
7mo ago
+349-12

Summary

  • restore active marked-text selection ownership in GhosttyNSView NSTextInputClient
  • return active marked text substrings for IME candidate/composition queries while preserving terminal-selection fallback for dictation/accessibility
  • add CJK/Zhuyin marked-text regression coverage

Verification

  • ./scripts/reload.sh --tag issue-3571-zhuyin-ime-candidate
  • ./scripts/reload.sh --tag issue-3571-zhuyin-ime-candidate after commit

Notes

  • Local XCTest was not run per project testing policy.

Fixes #3571


[!NOTE]
Medium Risk
Changes NSTextInputClient IME composition behavior and key event forwarding, which can regress text input for CJK/other input methods if edge cases are missed. Coverage is improved with new Zhuyin/CJK regression tests, reducing but not eliminating risk.

Overview
Fixes IME marked-text handling in GhosttyNSView during composition by tracking the active marked-text selection, clamping IME range queries to the preedit buffer, and serving attributedSubstring from marked text when present.

Updates keyDown to suppress forwarding a Ghostty key event when interpretKeyEvents only mutates IME composition state (marked text/selection) without committing text, preventing duplicate input (notably for Zhuyin).

Adds CJKIMEMarkedSelectionTests to cover marked selection/substrings and Zhuyin keyDown forwarding behavior, and removes the now-redundant selectedRange test from CJKIMEInputTests.

Reviewed by Cursor Bugbot for commit 50cb0ff6578c40b2ca930a5f9ecd05f7b179579f. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Restores correct marked-text handling during IME composition so Zhuyin/CJK candidate windows get the right selection and substrings, and suppresses duplicate terminal key forwarding when composition changes without commit. Keeps terminal-selection fallback for dictation and accessibility. Fixes #3571.

  • Bug Fixes

    • In GhosttyNSView’s NSTextInputClient, selectedRange() returns the active marked-text selection during composition; falls back to terminal selection only when no marked text exists.
    • attributedSubstring(forProposedRange:) serves substrings from active marked text; ranges are clamped and state resets on unmarkText().
    • Prevent duplicate terminal dispatch by not forwarding keys when interpretKeyEvents mutates marked text or its selection unless insertText committed text.
  • Refactors

    • Moved marked-text range helpers and IME dispatch suppression into GhosttyNSView+IMEComposition.swift.
    • Added CJKIMEMarkedSelectionTests.swift; trimmed CJKIMEInputTests.swift and small compactions/lint fixes to satisfy file-budget rules.

Summary by CodeRabbit

  • Bug Fixes
    • Improved IME composition handling: selection inside composing text is now tracked and preferred, yielding more accurate cursor/selection behavior and substring responses during CJK IME input.
  • Tests
    • Added comprehensive tests covering marked-text selection, substring retrieval, unmarking behavior, and multiple IME scenarios to prevent regressions.