# terminal: Implement basic Japanese IME support on macOS \(\#29879\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/c7725e31d953c85daf78eaf1590954ddeaecfd63)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: c7725e31d953c85daf78eaf1590954ddeaecfd63

Requested commit: c7725e31d953c85daf78eaf1590954ddeaecfd63

Commit: c7725e31d953c85daf78eaf1590954ddeaecfd63

Tree: b55acc1402f4dfa5dd1dbb283cbde0a0c611e532

Author: Gen Tamura

Committer: GitHub

## Message

```
terminal: Implement basic Japanese IME support on macOS (#29879)

## Description

This PR implements basic support for Japanese Input Method Editors
(IMEs) in the Zed terminal on macOS, addressing issue #9900. Previously,
users had to switch input modes to confirm Japanese text, and pre-edit
(marked) text was not displayed.

With these changes:

- **Marked Text Display:** Pre-edit text (e.g., underlined characters
during Japanese composition) is now rendered directly in the terminal at
the cursor's current position.
- **Composition Confirmation:** Pressing Enter correctly finalizes the
IME composition, clears the marked text, and sends the confirmed string
to the underlying PTY process. This allows for a more natural input flow
similar to other macOS applications like iTerm2.
- **State Management:** IME state (marked text and its selected range
within the marked text) is now managed within the `TerminalView` struct.
- **Input Handling:** `TerminalInputHandler` has been updated to
correctly process IME callbacks (`replace_and_mark_text_in_range`,
`replace_text_in_range`, `unmark_text`, `marked_text_range`) by
interacting with `TerminalView`.
- **Painting Logic:** `TerminalElement::paint` now fetches the marked
text and its range from `TerminalView` and renders it with an underline.
The standard terminal cursor is hidden when marked text is present to
avoid visual clutter.
- **Candidate Window Positioning:**
`TerminalInputHandler::bounds_for_range` now attempts to provide more
accurate bounds for the IME candidate window by using the actual painted
bounds of the pre-edit text, falling back to a cursor-based
approximation if necessary.

This significantly improves the usability of the Zed terminal for users
who need to input Japanese characters, bringing the experience closer to
system-standard IME behavior.

## Movies


https://github.com/user-attachments/assets/be6c7597-7b65-49a6-b376-e1adff6da974

---

Closes #9900

Release Notes:

- **Terminal:** Implemented basic support for Japanese Input Method
Editors (IMEs) on macOS. Users can now see pre-edit (marked) text as
they type Japanese and confirm their input with the Enter key directly
in the terminal. This provides a more natural and efficient experience
for Japanese language input. (Fixes #9900)

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
```

## Parents

- [e26620d1cfbd21c0e405e9469e2a31880859b4f6](https://git.cafe/gitcafe/zed/commit/e26620d1cfbd21c0e405e9469e2a31880859b4f6?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/c7725e31d953c85daf78eaf1590954ddeaecfd63?format=markdown)
