eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
118 stars 137 forks source link

[GTK3] StyledText reports wrong text typing Chinese letters with Pinyin #1213

Open tmssngr opened 6 months ago

tmssngr commented 6 months ago

Describe the bug If a selection in the StyledText is replaced with a Chinese letter entered using Chinese (Pinyin), no (replaced) text is reported by the SWT.ExtendedModify event.

To Reproduce

public class PinyinTest { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final StyledText st = new StyledText(shell, SWT.BORDER); st.addListener(ST.ExtendedModify, event -> { System.out.printf("%d %d, '%s'(%d)\n", event.start, event.end - event.start, event.text, event.text.length()); });

    shell.setSize(400, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

}

- keep the keyboard layout at *en*
- type `abc`
- select `b`
- type `d` (replacing b)
- you will see on the console
0 1, ''(0)
1 1, ''(0)
2 1, ''(0)
1 1, 'b'(1)
```

Expected behavior Replacing with a Chinese character also should report the replaced character(s).

Environment:

  1. Select the platform(s) on which the behavior is seen:

      • [ ] All OS
      • [ ] Windows
      • [x] Linux
      • [ ] macOS
  2. Additional OS info (e.g. OS version, Linux Desktop, etc) Tried with Ubuntu 22.04 and Manjaro/Gnome (latest)

tmssngr commented 6 months ago

Even worse: at the time when the first edit related event SWT.Verify occurs, the selected character already has been magically replaced (st.getText() does not contain it any more). This looks like a serious bug of the StyledText control with Chinese (Pinyin) keyboard layout.

tmssngr commented 6 months ago

Workaround: use StyledTextContent's TextChangeListener instead of SWT.Verify, SWT.Modify or SWT.ExtendedModify if you want to get access to the replaced text, e.g. for implementing an undo-feature.