Skip to content

Commit b5a167d

Browse files
Merge pull request #565 from JordanMartinez/fixEitherOpsBug
Fix either ops bug
2 parents 9832e81 + c90cb8c commit b5a167d

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/model/Paragraph.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ public Paragraph<PS, SEG, S> subSequence(int start) {
171171
throw new IllegalArgumentException("start must not be negative (was: " + start + ")");
172172
} else if(start == 0) {
173173
return this;
174-
} else if(start <= length()) {
174+
} else if (start == length()) {
175+
// in case one is using EitherOps<SegmentOps, SegmentOps>, force the empty segment
176+
// to use the left ops' default empty seg, not the right one's empty seg
177+
return new Paragraph<>(paragraphStyle, segmentOps, segmentOps.createEmpty());
178+
} else if(start < length()) {
175179
Position pos = navigator.offsetToPosition(start, Forward);
176180
int segIdx = pos.getMajor();
177181
List<SEG> segs = new ArrayList<>(segments.size() - segIdx);

richtextfx/src/main/java/org/fxmisc/richtext/model/StyledText.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ public String toString() {
143143
public boolean equals(Object obj) {
144144
if(obj instanceof StyledText) {
145145
StyledText<?> that = (StyledText<?>) obj;
146-
return Objects.equals(this.text, that.text)
147-
&& Objects.equals(this.style, that.style);
146+
return (this.text.isEmpty() && that.text.isEmpty())
147+
|| (Objects.equals(this.text, that.text)
148+
&& Objects.equals(this.style, that.style));
148149
} else {
149150
return false;
150151
}

0 commit comments

Comments
 (0)