eclipse.platform.swt icon indicating copy to clipboard operation
eclipse.platform.swt copied to clipboard

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

Open tmssngr opened this issue 1 year ago • 2 comments
trafficstars

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

  • install Pinyin keyboard:
    • Ubuntu: sudo apt install ibus-pinyin, Manjaro: sudo pacman -S ibus-pinyin
    • reboot the machine
    • in the GTK preferences, page Keyboard, add the Chinese (Pinyin) keyboard layout
  • Run this snippet:
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

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)
    
  • select d
  • change the keyboard layout to Chinese (Pinyin)
  • type d1 (replacing d)
  • you will see on the console
    0 1, ''(0)
    1 1, ''(0)
    2 1, ''(0)
    1 1, 'b'(1)
    1 1, ''(0)
    

-> although d has been replaced, it was not reported in event.text this time

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
  1. Additional OS info (e.g. OS version, Linux Desktop, etc) Tried with Ubuntu 22.04 and Manjaro/Gnome (latest)

tmssngr avatar May 06 '24 10:05 tmssngr

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 avatar May 06 '24 10:05 tmssngr

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.

tmssngr avatar May 06 '24 11:05 tmssngr