zed icon indicating copy to clipboard operation
zed copied to clipboard

terminal: Implement basic Japanese IME support on macOS

Open gentamura opened this issue 8 months ago • 8 comments

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)

gentamura avatar May 04 '25 15:05 gentamura

We require contributors to sign our Contributor License Agreement, and we don't have @gentamura on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

cla-bot[bot] avatar May 04 '25 15:05 cla-bot[bot]

We require contributors to sign our Contributor License Agreement, and we don't have @gentamura on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

cla-bot[bot] avatar May 05 '25 07:05 cla-bot[bot]

@cla-bot check

gentamura avatar May 05 '25 07:05 gentamura

The cla-bot has been summoned, and re-checked this pull request!

cla-bot[bot] avatar May 05 '25 07:05 cla-bot[bot]

Hi @maxdeviant, Thank you for updating the PR title — I appreciate your help! Could you also please approve the workflow run for this PR? GitHub is currently blocking it since it's from a first-time contributor. Thanks again!

gentamura avatar May 05 '25 12:05 gentamura

Hi @maxdeviant,

Thank you again for re-running the workflow last time. After the run, the following error occurred in the Windows "Run Clippy" job: https://github.com/zed-industries/zed/actions/runs/14835953636

Since I don’t have permission to re-run the workflow, I tried updating the commit SHA and force-pushing the branch to trigger a new run. However, the workflows are now pending approval again.

If possible, I would greatly appreciate it if you could approve the workflow run for my PR: https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/approving-workflow-runs-from-public-forks

If I’m not following the correct process for contributing to this repository, I’d really appreciate any guidance on the proper procedure going forward.

Thank you for your time and support!

gentamura avatar May 06 '25 08:05 gentamura

@ConradIrwin Thank you for taking over the PR. If you don't have a Japanese IME set up, feel free to reach out to me—I'd be happy to assist with any necessary debugging. Looking forward to working with you.

gentamura avatar May 09 '25 00:05 gentamura

This is excellent, thank you!

I've pushed up a change to tidy a few things up – in particular I didn't want any debug logging on every frame, and (in a follow-up PR) I'll make text layout not return a result so I replaced your error wrapping with an unwrap for now.

I'm a little nervous that we don't implement text_for_range, but this is clearly much better than what we had before, so I think we should wait until we have a reproducible bad case before fixing that.

ConradIrwin avatar May 14 '25 20:05 ConradIrwin

This PR also improved the experience of Chinese input methods in the terminal. Well done, and thank you!

opsnull avatar May 17 '25 01:05 opsnull