From 694d04ed89f0bc1e7858cd589065bd8581010f4e Mon Sep 17 00:00:00 2001 From: grigoriliev Date: Tue, 6 Dec 2016 09:53:19 +0200 Subject: [PATCH] fixed IllegalArgumentException on undo --- .../org/fxmisc/richtext/model/TextChange.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/model/TextChange.java b/richtextfx/src/main/java/org/fxmisc/richtext/model/TextChange.java index 04c00ef8f..61a2ae273 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/model/TextChange.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/model/TextChange.java @@ -42,6 +42,22 @@ public TextChange(int position, S removed, S inserted) { * {@code null} otherwise. */ public Optional mergeWith(Self latter) { + if(this.insertedLength() > 0 && this.removedLength() > 0) { + return Optional.empty(); + } + + if(latter.insertedLength() > 0 && latter.removedLength() > 0) { + return Optional.empty(); + } + + if(this.insertedLength() > 0 && latter.removedLength() > 0) { + return Optional.empty(); + } + + if(this.removedLength() > 0 && latter.insertedLength() > 0) { + return Optional.empty(); + } + if(latter.position == this.position + this.insertedLength()) { S removedText = concat(this.removed, latter.removed); S addedText = concat(this.inserted, latter.inserted);