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

[0.9.2] Replace selected text with pasted text causes exception #788

Closed
xweichen opened this issue Nov 26, 2018 · 5 comments · Fixed by #795
Closed

[0.9.2] Replace selected text with pasted text causes exception #788

xweichen opened this issue Nov 26, 2018 · 5 comments · Fixed by #795
Labels

Comments

@xweichen
Copy link

Replace selected text with pasted text causes exception aslo happen in 0.9.2

test steps:
1、input a\nb\nc
2018-11-26_235755
2、ctrl+a select all and ctrl+c to copy all
3、select from end to start,select c\nb and ctrl+v
2018-11-27_000129
4、ctrl+a select all and ctrl+v

exception like this:

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: [1, 0) is not a valid range within [0, 3)
at org.reactfx.util.Lists.checkRange(Lists.java:128)
at org.reactfx.util.Lists.checkRange(Lists.java:123)
at org.reactfx.util.FingerTree$Branch$1.subList(FingerTree.java:489)
at org.reactfx.collection.MaterializedListModification.lambda$0(MaterializedListModification.java:30)
at org.reactfx.util.Tuple2.map(Tuple2.java:31)
at org.reactfx.collection.MaterializedListModification.trim(MaterializedListModification.java:23)
at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase$ParagraphList.lambda$observeInputs$0(GenericEditableStyledDocumentBase.java:46)
at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$0(NotificationAccumulator.java:134)

@Jugen
Copy link
Collaborator

Jugen commented Nov 27, 2018

@xweichen thanks for reporting.

Observations I've made so far is that the exception only happens under the following conditions:

  1. Two successive pastes with no edits in between
    (if edited then ctrl+z removing the edits restores the exception condition)
  2. The first paste must be at the very end of the document
  3. The second paste must be to replace all text

@Jugen Jugen added the bug label Nov 27, 2018
@Jugen
Copy link
Collaborator

Jugen commented Nov 27, 2018

The following code produces the reported exception:

String test = "a\n";
area.replaceText( test );
area.appendText( test +"d" );
area.replaceText( test +"d" );

or

String test = "a\n";
area.replaceText( test );
area.insertText( 0, test +"d\n" );
area.replaceText( test );

JFormDesigner pushed a commit to JFormDesigner/RichTextFX that referenced this issue Dec 21, 2018
…on (issues FXMisc#777 and FXMisc#788)

(borrowed code from ReactFX, which uses same license as RichTextFX)
Jugen pushed a commit that referenced this issue Feb 20, 2019
* bug: getVisibleParagraph does not work with blank lines
* trim paragraphs using reference instead of object comparison (issues #777 and #788)
@samhutchins
Copy link

samhutchins commented Dec 18, 2019

This is still a problem in 0.10.3

import org.fxmisc.richtext.CodeArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class FooBar
{
    public static void main(String[] args)
    {
        Application.launch(MainWindow.class);
    }

    public static class MainWindow extends Application
    {
        @Override
        public void start(final Stage primaryStage)
        {
            final CodeArea area = new CodeArea();

            final Button button = new Button("Throw exception");
            button.setOnAction(e ->
            {
                String test = "a\n";
                area.replaceText( test );
                area.appendText( test +"d" );
                area.replaceText( test +"d" );
            });


            final BorderPane root = new BorderPane(area);
            root.setBottom(button);
            final Scene scene = new Scene(root, 600, 400);
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
}

If you press the "Throw exception" button, it performs the same steps as outlined by @Jugen here and it throws the same exception. I can also reproduce by hand

@Jugen
Copy link
Collaborator

Jugen commented Dec 24, 2019

I've checked into this with JRE 8 and JRE 11 using your code with 0.10.3 and it unfortunately doesn't throw the exception ? Could you double check that your classpath is indeed using the latest RichTextFX jar and if so then could you please provide additional information that might help.

@samhutchins
Copy link

My apologies, I guess my IDE didn't pickup the change in the pom.xml or something was cached, I can't reproduce with 0.10.3

Jugen added a commit that referenced this issue Mar 23, 2020
* Improved visibleParToAllParIndex, Reverted fix for #795
* Improved method allParToVisibleParIndex
* Added exception trap and test for #788
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants