Skip to content

SwiftUI TextField does not accept Vietnamese IME input (accented characters) #39

@quanglx2703

Description

@quanglx2703

Description

Vietnamese input methods (e.g. Unikey, EVKey, macOS built-in Vietnamese Telex/VNI) cannot type accented characters into SwiftUI TextField components in Hermes Desktop. Characters with diacritics (â, ê, ô, ơ, ă, ư, etc.) are either dropped, duplicated, or inserted incorrectly. The input method composition window may flicker or fail to commit characters.

This affects all text fields in the app: New Host form, session search, skill editor, and any other SwiftUI TextField.

Steps to Reproduce

  1. Enable a Vietnamese input method (Unikey, EVKey, or macOS built-in Vietnamese Telex)
  2. Open Hermes Desktop v0.9.0
  3. Navigate to any text field — try New Host dialog (Hermes → New Host)
  4. Type Vietnamese text with accents — e.g. "kết nối" or "quản lý"
  5. Observe: accented characters do not appear correctly or are dropped

Expected Behavior

Vietnamese Unicode characters with diacritics should be entered correctly, exactly as they work in native macOS apps (Notes, Safari, Terminal, Xcode) and AppKit-based text fields.

Actual Behavior

  • Accented characters are dropped or mangled
  • The text field shows only the base character without the diacritic mark
  • In some cases the composition window fails to commit the character
  • Some fields swallow the IME input entirely

Environment

  • App version: 0.9.0 (also reproducible on earlier versions)
  • macOS version: 15.7.5 (Sequoia)
  • Hardware: Apple Silicon Mac
  • Input methods tested:
    • Unikey (via EVKey engine)
    • macOS built-in Vietnamese Telex (Cài đặt → Bàn phím → Phương thức nhập liệu → Tiếng Việt)

Root Cause (analysis)

SwiftUI's TextField on macOS has a known limitation with Input Method Editors (IME). Unlike AppKit's NSTextField/NSTextView, which properly implement the NSTextInputClient protocol, SwiftUI's text fields do not always handle the IME composition → commit lifecycle correctly for East Asian and Southeast Asian scripts (Chinese, Japanese, Korean, Vietnamese).

The terminal component (which uses SwiftTerm, based on AppKit's NSTextView) handles Vietnamese input correctly — suggesting the issue is specific to SwiftUI's own TextField implementation.

Workaround (temporary)

  • Type Vietnamese text in another app (TextEdit, Notes) → copy → paste into Hermes Desktop
  • Use the Terminal tab (SwiftTerm) — IME works correctly there
  • Add text via hermes CLI directly in Terminal

Suggested Fix

  1. Replace critical SwiftUI TextField components with NSViewRepresentable wrapping NSTextField/NSTextView
  2. Or use a custom NSViewRepresentable that explicitly conforms to NSTextInputClient
  3. Or consider using .onReceive with NSControl.textDidChangeNotification to properly handle IME commit events

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions