The Wayback Machine - https://web.archive.org/web/20260417091611/https://github.com/microsoft/terminal/pull/20041
Skip to content

Fix Korean IME overlay hiding characters to the right of cursor#20041

Merged
DHowett merged 5 commits intomicrosoft:mainfrom
drvoss:fix/korean-ime-composition-insert-rendering
Apr 17, 2026
Merged

Fix Korean IME overlay hiding characters to the right of cursor#20041
DHowett merged 5 commits intomicrosoft:mainfrom
drvoss:fix/korean-ime-composition-insert-rendering

Conversation

@drvoss
Copy link
Copy Markdown
Contributor

@drvoss drvoss commented Mar 31, 2026

This commit fixes a regression in v1.24, where composing Korean text
in-between existing characters causes text to the right to be hidden.
This is problematic for the Korean IME, because it commonly inserts
the composed syllable between existing characters.

The fix compresses (removes/absorbs) available whitespace to the right
of the composition to make space for any existing text. This means
that a composition now virtually acts in insert mode.

Closes #20040
Refs #19738
Refs #20039

Validation Steps Performed

  1. Korean IME: compose between and → display shows 가ㄷ나, visible.
  2. TUI box (vim prompt with padding): compose inside padded text box → border preserved in place.
  3. Composition at end of line (no chars to right): unaffected.
  4. English and other IME input: not affected (no active composition row).

Co-authored-by: Leonard Hecker lhecker@microsoft.com

drvoss added 3 commits March 30, 2026 17:23
…cursor

When composing a new character between two existing characters, the in-progress
composition text was drawn over the character immediately to the right of the
cursor, visually hiding it during composition. This happened because the
tsfPreview overlay used an overwrite-style render, writing the composition text
at the cursor column without preserving the displaced content.

The fix copies the original characters from that position back into the visual
row at the position just after the composition text ends, changing the
appearance from overwrite to insert. The buffer itself is not modified; the
change is local to the temporary row modification that is restored after each
paint frame.

This regression was introduced by commit a3d508a (Remove
TF_TMAE_UIELEMENTENABLEDONLY, microsoft#19738), which caused the Korean IME to switch
from IMM32 (which renders its own floating composition window) to TSF (which
uses the terminal's inline tsfPreview rendering), exposing this rendering flaw.
Reverts the change that shifted existing characters to the right of the
cursor when rendering an in-progress TSF composition (tsfPreview). The
approach was an unconditional rightward shift of all content from the
cursor position, which caused box-drawing characters in TUI applications
to be displaced and rendered at wrong positions or cut off entirely.

Example of the breakage in a TUI text box:
  Before (correct):  |Hello [ㄷ]     |
  After  (broken):   |Hello [ㄷ]Worl|d  (border shifted off screen)

The correct fix requires consuming an equal amount of whitespace to the
right of the composition before shifting, so that box borders remain at
their original column positions when trailing whitespace is available.
This improved approach will be implemented separately as Fix 2-1.

Reviewer feedback:
  When you're in a TUI application, there may be a box around the text
  field. Shifting text from the cursor to the right means that the right
  border (and anything else in the TUI app) also shifts to the right.
  One solution for this is that we try to remove an equal amount of
  whitespace to the right of the composition.
…cursor

When composing a new Korean character between existing text, the in-progress
composition overlay was drawn using an overwrite-style render that hid any
character immediately to the right of the cursor. This is visually incorrect
for Korean IME, which inserts rather than replaces.

The fix copies original characters from the cursor position back to the right
of the composition text, using a whitespace-absorption algorithm so that TUI
box borders stay at their original column positions when trailing whitespace
is available. Up to W whitespace columns (where W is the composition width)
are consumed silently; remaining non-whitespace content is shifted rightward.
If no whitespace is available, the shift is unavoidable (border may move),
but this is the best achievable behavior for fixed-width lines.

The rendering change is purely visual: the buffer row is restored in full
after each paint frame by the existing wil::scope_exit restore mechanism.

This approach was suggested by a reviewer as a refinement to a prior attempt
that shifted all content unconditionally and broke TUI box borders.

Closes microsoft#20040
@DHowett
Copy link
Copy Markdown
Member

DHowett commented Mar 31, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@DHowett DHowett changed the title Fix Korean IME composition overlay hiding characters to the right of cursor Fix Korean IME overlay hiding characters to the right of cursor Mar 31, 2026
Copy link
Copy Markdown
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compositionRow code is now rather lengthy with this new code. I think it makes sense to hoist it into its own dedicated function if possible. But the changes overall look good to me. 🙂

Let me think about this over the next few days! I'll check this PR out locally.

}

compositionEnd = state.columnEnd;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block above is identical to before.

@lhecker lhecker enabled auto-merge (squash) April 16, 2026 22:53
@DHowett DHowett closed this Apr 16, 2026
auto-merge was automatically disabled April 16, 2026 23:43

Pull request was closed

@DHowett DHowett reopened this Apr 16, 2026
@DHowett DHowett merged commit 7a83c0f into microsoft:main Apr 17, 2026
15 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Korean IME (v1.24+): Composing character visually hides the character to its right

3 participants