Skip to content

[macOS] StyledText: an arrow key during Korean IME composition discards the composing syllable instead of committing it #3554

Open

Description

@ethznn

Describe the bug

On macOS, an arrow key pressed while the Korean IME is composing discards the composing syllable instead of committing it. The character is lost outright — it never reaches the widget's text, and there is no undo path back to it.

A plain Text in the same application commits it correctly on the same keystrokes, so this is specific to StyledText.

To Reproduce

This snippet puts a StyledText above a Text so the two can be compared in one run. Each readout prints what that widget's own text model holds.

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class StyledTextKoreanArrow {

    public static void main(String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));

        new Label(shell, SWT.NONE).setText("StyledText");
        final StyledText styled = new StyledText(shell, SWT.BORDER);
        styled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        final Label styledReadout = new Label(shell, SWT.NONE);
        styledReadout.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        Runnable refreshStyled =
                () -> styledReadout.setText(describe(styled.getText(), styled.getCaretOffset()));
        refreshStyled.run();
        styled.addModifyListener(e -> refreshStyled.run());
        styled.addCaretListener(e -> refreshStyled.run());

        new Label(shell, SWT.NONE).setText("Text (single line)");
        final Text text = new Text(shell, SWT.BORDER | SWT.SINGLE);
        text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        final Label textReadout = new Label(shell, SWT.NONE);
        textReadout.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        Runnable refreshText =
                () -> textReadout.setText(describe(text.getText(), text.getCaretPosition()));
        refreshText.run();
        text.addModifyListener(e -> refreshText.run());
        text.addListener(SWT.KeyUp, e -> refreshText.run());

        shell.setSize(620, 320);
        shell.setText("SWT " + SWT.getVersion() + " — Korean IME arrow");
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

    private static String describe(String content, int caret) {
        StringBuilder codePoints = new StringBuilder();
        content.codePoints().forEach(cp -> codePoints.append(String.format("U+%04X ", cp)));
        if (codePoints.length() == 0) {
            codePoints.append("(empty)");
        }
        return "text: \"" + content + "\"   caret: " + caret + "   " + codePoints;
    }
}

Select the macOS 2-Set Korean input source, then in each box:

  1. Type 가 나, then begin 다 and stop. It stays underlined — still composing.
  2. Press ← once.

StyledText after the arrow, with the composing syllable gone:

text: "가나"   caret: 2   U+AC00 U+B098

Text, same keystrokes, with it committed before the caret moved:

text: "가나다"   caret: 2   U+AC00 U+B098 U+B2E4

While composing, both widgets read "가나" and draw 다 underlined. That part is expected — the preedit is not in the text yet. The difference is what the arrow does with it: Text commits it, StyledText drops it.

Arrow presses after the first only move the caret, since there is no composition left to lose.

Expected behavior

An arrow key arriving during composition should commit the preedit and then move the caret, which is what Text does here and what native macOS controls do.

Screenshots

The readouts quoted above are the widgets' own getText() output rather than a description of the screen, so they carry the same evidence; happy to attach captures if that is easier to read.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)

macOS 26.6.2, Apple Silicon. Input source: 2-Set Korean (한국어 두벌식).

  1. JRE/JDK version

Temurin 20.0.1 (aarch64).

Version since

Seen on SWT 3.130.0 (SWT.getVersion() reports 4969). Not bisected — downstream reports of the same symptom go back to 2020 (DBeaver 7.3 on macOS 10.14), so it is unlikely to be a recent regression.

Workaround (or) Additional context

No workaround beyond committing the syllable first — press Space and delete it, or switch the input source — before moving the caret.

Possibly the same root as #2412, which reports Backspace deleting one character too many in StyledText while the Korean IME is active: same widget, same platform, same input source, and also a key arriving mid-composition that is not reconciled against the marked text. Filed separately because the visible outcomes differ, but one fix for how StyledText treats a key press during composition may cover both.

Downstream this is dbeaver/dbeaver#10615, open since 2020 and labelled a third-party issue. The tracker linked there, bugs.eclipse.org 371397, no longer leads anywhere actionable — that report sits under the archived z_Archived product against the PDT component and the Carbon platform, so it is not tracking the SWT code this lives in. Raising it here so there is a live report against the right component.

Activity

  1. ethznn commented on Sep 2, 2026

    @ethznn
    Author

    Traced the event sequence from the Java side, and it narrows further than the report: the syllable is not dropped before it exists — it is composed into the text and then removed again.

    Listeners on SWT.ImeComposition, KeyDown, Verify, Modify and a CaretListener, typing 가 나 then beginning 다, then ←:

    Caret     -> offset=2  text="가나"    [U+AC00 U+B098]
    Caret     -> offset=3  text="가나ㄷ"  [U+AC00 U+B098 U+3137]
    KeyUp     keyCode=12599
    KeyUp     keyCode=12623
    Caret     -> offset=2  text="가나다"  [U+AC00 U+B098 U+B2E4]
    Caret     -> offset=1  text="가나"    [U+AC00 U+B098]
    KeyDown   keyCode=ARROW_LEFT  char=45796  stateMask=0
    KeyUp     keyCode=ARROW_LEFT
    

    Three things fall out of that:

    1. The preedit is carried in the widget's own text while composing — 가나ㄷ holds the compatibility jamo U+3137, and it resolves to 가나다 with U+B2E4 once the syllable completes. This is the inline IME path working as intended.

    2. The removal happens after the syllable is complete. 가나다 → 가나 is the composition being torn down, and it takes the finished character with it. So the loss is not a missed commit; it is a commit that gets reverted.

    3. The ARROW_LEFT KeyDown that follows carries char=45796, which is U+B2E4 — 다. The composed character is still in hand at the point the key is delivered; it has simply been taken out of the text by then.

    Reading IME.setMarkedText_selectedRange in Eclipse SWT/cocoa/.../IME.java, an empty marked string takes this path:

    if (text.length () == 0) {
        Shell s = parent.getShell ();
        s.keyInputHappened = true;
        startOffset = -1;
        resetStyles ();
    }

    The preceding COMPOSITION_CHANGED carries event.text = "", which is what clears the composition range in StyledText — including the completed syllable sitting in it. There is no branch that distinguishes "the input method cancelled this composition" from "the input method ended it because a caret command arrived", and the two want opposite outcomes: Esc should still discard, an arrow should commit.

    For contrast, Text on the same platform is backed by a native NSTextField, where AppKit performs that commit itself, which is why the same keystrokes keep 다 there.

    Snippet used for the trace, if it is useful:

    styled.addListener(SWT.ImeComposition, e -> log("ImeComposition detail=" + e.detail
            + " start=" + e.start + " end=" + e.end + " text=" + e.text));
    styled.addListener(SWT.KeyDown, e -> log("KeyDown keyCode=" + e.keyCode + " char=" + (int) e.character));
    styled.addListener(SWT.Modify, e -> log("Modify -> " + styled.getText()));
    styled.addCaretListener(e -> log("Caret -> offset=" + e.caretOffset + " text=" + styled.getText()));

    Happy to work up a patch if that is welcome — I have the reproduction on hand and can test any change against a real 2-Set Korean input source. Would want a steer first on where the distinction belongs, since IME is shared by every Canvas and not only StyledText.

  2. tmssngr commented on Sep 11, 2026

    @tmssngr
    Contributor

    Thank you very much for the deep analysis. I would really appreciate a fix and it looks like you understand much more of the IME internals as I do (see #2412).

    Regarding Canvas or StyledText - I suggest to first fix it in StyledText as this is the most important keyboard driven Canvas-control right now.

  3. ethznn commented on Sep 21, 2026

    @ethznn
    Author

    Thanks for the steer on StyledText first — and I have to walk back the delivery half of what I offered above.

    I'm not planning to sign the ECA — it asks for a legal name and a postal address, and I move often enough that keeping that current is upkeep I'd rather not take on — so the patch will have to come from someone else. Everything else I offered still stands: the reproduction is on hand, and I can run any candidate change against a real 2-Set Korean input source and report what it does. I did exactly that on #3307 earlier today.

    What the trace above leaves for whoever writes it:

    • The composed syllable is still in hand when the key is delivered — the ARROW_LEFT KeyDown carries char=45796, U+B2E4, 다 — so a fix has the character available and does not have to reconstruct it.
    • The clearing comes from a COMPOSITION_CHANGED whose event.text is empty, which IME.setMarkedText_selectedRange sends for an empty marked string. That same path serves a genuine cancel, so the distinction cannot be read from the event alone; it needs whatever the widget knows about the key that arrived with it.
    • Doing it in StyledText rather than IME keeps every other Canvas on the current behaviour, which is the conservative half of your suggestion and the reason I asked.

    If a change lands on a branch, point me at it and I'll report the measurements.

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