Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StyledText: internal error setting text #1085

Open
tmssngr opened this issue Mar 5, 2024 · 2 comments
Open

StyledText: internal error setting text #1085

tmssngr opened this issue Mar 5, 2024 · 2 comments
Labels
bug Something isn't working macOS happens on macOS

Comments

@tmssngr
Copy link
Contributor

tmssngr commented Mar 5, 2024

Describe the bug
On macOS select the US International keyboard layout, run the below snippet and type a quote. It will remain in some intermediate state. Now click a button that clears the text of the StyledText control. You will get following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4899)
	at org.eclipse.swt.SWT.error(SWT.java:4833)
	at org.eclipse.swt.SWT.error(SWT.java:4804)
	at org.eclipse.swt.custom.DefaultContent.error(DefaultContent.java:691)
	at org.eclipse.swt.custom.DefaultContent.getLineAtOffset(DefaultContent.java:584)
	at org.eclipse.swt.custom.StyledTextRenderer.getTextLayout(StyledTextRenderer.java:1225)
	at org.eclipse.swt.custom.StyledTextRenderer.getTextLayout(StyledTextRenderer.java:911)
	at org.eclipse.swt.custom.StyledTextRenderer.calculate(StyledTextRenderer.java:301)
	at org.eclipse.swt.custom.StyledTextRenderer.calculateClientArea(StyledTextRenderer.java:331)
	at org.eclipse.swt.custom.StyledText.resetCache(StyledText.java:7831)
	at org.eclipse.swt.custom.StyledText.reset(StyledText.java:7800)
	at org.eclipse.swt.custom.StyledText.handleTextSet(StyledText.java:6153)
	at org.eclipse.swt.custom.StyledText$5.textSet(StyledText.java:5410)
	at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:84)
	at org.eclipse.swt.custom.DefaultContent.sendTextEvent(DefaultContent.java:819)
	at org.eclipse.swt.custom.DefaultContent.setText(DefaultContent.java:839)
	at org.eclipse.swt.custom.StyledText.setText(StyledText.java:10477)
	at StyledTextWithQuote.lambda$main$0(StyledTextWithQuote.java:24)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4646)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1547)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1532)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1325)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4413)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3989)
	at StyledTextWithQuote.main(StyledTextWithQuote.java:30)

Snippet

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.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class StyledTextWithQuote {

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

        final StyledText text = new StyledText(shell, SWT.BORDER | SWT.MULTI);
        text.setText("On MacOS select the US-Internation keyboard layout\n- press the ' key\n- click the \"Clear\" button");
        text.setSelection(text.getCharCount());
        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        final Button button = new Button(shell, SWT.PUSH);
        button.setText("Clear");
        button.setLayoutData(new GridData(SWT.END, SWT.END, false, false));
        button.addListener(SWT.Selection, event -> text.setText(""));

        shell.setSize(400, 200);
        shell.open();

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

        display.dispose();
    }
}

Expected behavior
No crash. The StyledText will get out of the intermediate state and clears the text.

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)
  2. Tried on macOS 14.3.1
@tmssngr
Copy link
Contributor Author

tmssngr commented Mar 5, 2024

Screenshot of the intermediate state:
Screenshot 2024-03-05 at 18 01 38
before clicking the Clear button.

@jukzi jukzi added bug Something isn't working macOS happens on macOS labels Mar 5, 2024
@tmssngr tmssngr changed the title [macOS] StyledText: internal error setting text StyledText: internal error setting text Mar 6, 2024
@tmssngr
Copy link
Contributor Author

tmssngr commented Mar 6, 2024

One user reported this bug for Linux, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macOS happens on macOS
Projects
None yet
Development

No branches or pull requests

2 participants