Skip to content

[Bug] Japanese IME input breaks when typing immediately after a code fence #4851

Closed

Description

@rain2542

Description

When typing Japanese text with an IME immediately after a code fence, the input becomes broken after the first character.

This seems to happen when I start typing Japanese text right after creating a code fence with three backticks and moving to the next input position.

Steps to Reproduce

  1. Make sure Source Code Mode is disabled.
  2. Open MarkText 0.20.0-beta.5.
  3. Create a new document.
  4. Type three backticks to create a code fence.
  5. Press Enter or move the cursor immediately after the code fence.
  6. Try typing Japanese text using a Japanese IME.
    For example, try typing "てすと".

Expected Behavior

Japanese text should be entered normally.

For example, when typing "てすと", it should appear as "てすと" without any broken or unexpected characters.

Actual Behavior

The first character is entered correctly, but the second character becomes broken or unexpected.

For example, when I try to type Japanese text, the result may become "nあ" or "kあ" instead of the expected input.

After that, the third and later characters can usually be typed normally.

In another test with repeated input, the result became something like "かkあかかかかかかかかか".

This issue reliably happens when Source Code Mode is disabled.

I could not reproduce it when Source Code Mode was enabled.

When Typewriter Mode is enabled, the behavior becomes less consistent: sometimes the issue happens on the first character, and sometimes it does not happen.

Screenshots / Logs

Screen recording/GIF:

Screen recording showing the Japanese IME input issue

Operating System

Windows

MarkText Version

v0.19.1

OS Version

Windows 11 25H2, Microsoft Japanese IME

Reproducibility

  • I can reliably reproduce this issue

Activity

  1. Jocs commented on Sep 22, 2026

    @Jocs
    Member

    Reproduced this on 0.20.0-beta.5, and confirmed it is fixed from v0.20.0-rc.2 onwards.

    What was happening

    A code block whose text ends in a newline used to render that newline inside its own <span class="mu-line-end">. With the caret at the end of the block it therefore sat inside the newline's own text node — and Chromium will not sustain an IME composition there. It overwrites the newline and abandons the composition, so the input method loses the first keystroke of the word. That is where the leftover half-width romaji next to the kana came from (nあ, kあ, かkあかかか…).

    Driving a real Chromium composition through CDP Input.imeSetComposition against the beta.5 source — caret at the end of a code block containing abc\n, then typing てすと:

    version result
    0.20.0-beta.5 abctてすと — the newline is eaten and a stray t leaks in as plain text
    0.20.0-rc.2+ abc + newline + てすと — correct

    The fix

    #5286 (19faab16) moved the trailing newline back into the block's main text node and gave the empty last line its line box with a <span class="mu-trailing-break"><br></span> instead. The caret no longer lands inside the newline's own node, so the composition is never interrupted. That change first shipped in v0.20.0-rc.2.

    It was released as a fix for #5114 (caret on a code block's empty last line), so this issue was never linked to it — hence closing it only now.

    Closing as fixed. @rain2542 if you still see this on rc.5 or later, please reopen with the version you tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions