Expected Behavior
Calling CodeArea.replaceText() should replace the contents of the CodeArea without throwing any exception.
Actual Behavior
When the CodeArea contains multiple lines, calling CodeArea.replaceText() triggers an exception, show below:
Button pressed
Button pressed
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Visible paragraphs' last index is [-1] but visibleParIndex was [0]
at org.fxmisc.richtext.GenericStyledArea.visibleParToAllParIndex(GenericStyledArea.java:982)
at org.fxmisc.richtext.ViewActions.firstVisibleParToAllParIndex(ViewActions.java:284)
at org.fxmisc.richtext.LineNumberFactory.insertParagraphCheck(LineNumberFactory.java:172)
at org.fxmisc.richtext.LineNumberFactory.lambda$new$2(LineNumberFactory.java:92)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:831)
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Visible paragraphs' last index is [-1] but visibleParIndex was [0]
at org.fxmisc.richtext.GenericStyledArea.visibleParToAllParIndex(GenericStyledArea.java:982)
at org.fxmisc.richtext.ViewActions.firstVisibleParToAllParIndex(ViewActions.java:284)
at org.fxmisc.richtext.LineNumberFactory.deleteParagraphCheck(LineNumberFactory.java:148)
at org.fxmisc.richtext.LineNumberFactory.lambda$new$1(LineNumberFactory.java:91)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:831)
Reproducible Demo
Run this, then press the button twice.
Use the following template to get started.
public class App extends Application {
CodeArea codeArea;
Button button;
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
codeArea = new CodeArea();
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.setWrapText(false);
button = new Button("Press me Twice");
button.setOnAction(actionEvent -> {
actionEvent.consume();
System.out.println("Button pressed");
codeArea.clear();
// Doesn't really matter what is inside codeArea text,
// As long as it span multiple lines, the exception is thrown
codeArea.appendText("Lorem ipsum\n");
// If you remove the \n from above it won't throw an exception anymore
codeArea.replaceText(String.valueOf(Math.random()));
});
Parent root = new StackPane(codeArea, button);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
Environment info:
- RichTextFX Version: 0.10.6 from Maven
- Operating System: Windows 21H1 and ArchLinux
- Java version: 16.0.1 (Microsoft and ArchLinux's OpenJDK builds)
As this bug is reproducible on multiple OSes and JDK builds, I don't think this is platform dependent.
Expected Behavior
Calling CodeArea.replaceText() should replace the contents of the CodeArea without throwing any exception.
Actual Behavior
When the CodeArea contains multiple lines, calling CodeArea.replaceText() triggers an exception, show below:
Reproducible Demo
Run this, then press the button twice.
Use the following template to get started.
Environment info:
As this bug is reproducible on multiple OSes and JDK builds, I don't think this is platform dependent.