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);