-
Notifications
You must be signed in to change notification settings - Fork 236
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
fixed IllegalArgumentException on undo #402
Conversation
I think that also adding test case for
would be nice. Hmm, ok, seems that #373 is still not materialized in code... So I don't know if it is currently possible to write any test for that behavior 😞 |
How does your PR fix only the bug without also stopping merges entirely? I don't see how it would do that. |
@kuc One could still write the code that ultimately gets executed: area.replace(0, 0, "a");
area.replace(0, 1, "");
area.undo(); |
For undo/redo to work similar to other text editors merges should only occur when there is a sequence of inserting characters or sequence of removing characters. That is what this fix does - it doesn't stop merges entirely, but only allows merging of 'insert only' changes and 'remove only' changes. |
@grigoriliev Thank you for your work and patience. Please do three things:
There are at least 2 things we'll need to test:
As a starting point for writing a TestFX test, you can copy and paste this code: import javafx.scene.Scene;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;
import org.junit.Test;
import org.testfx.framework.junit.ApplicationTest;
public class TestFX_Test extends ApplicationTest {
private InlineCssTextArea area;
private VirtualizedScrollPane<InlineCssTextArea> vsPane;
@Override
public void start(Stage primaryStage) {
area = new InlineCssTextArea();
vsPane = new VirtualizedScrollPane<>(area);
Scene scene = new Scene(vsPane, 500, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
@Test
public void testSomething() {
// note: when directly accessing the area, you must use `interact(Runnable)` to run that code
// on the JavaFX Application Thread. Otherwise, it will throw an error.
clickOn(area).write("some text");
interact(() -> area.replaceText("Some text here."));
interact(() -> {
assert area.getLength() != 0;
});
}
} |
After looking at @grigoriliev's solution, I cleaned up his code to make it more readable in #458 and added the test above. I didn't see the need for the |
@grigoriliev We decided to revert back to the original merge method in #496. You can still use your version of the merge method by calling |
I changed the TextChange.mergeWith method so that the undo merging mimics the behavior of a regular text editor. This also fixes #322 (java.lang.IllegalArgumentException: Unexpected change received).