Skip to content

Commit cc11721

Browse files
authored
Fixes bug #780 After undo (ctrl-Z), text insertion point jumps to the start (#785)
1 parent ff54681 commit cc11721

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/UndoManagerTests.java

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static org.junit.Assert.assertEquals;
1818
import static org.junit.Assert.assertFalse;
19+
import static org.junit.Assert.assertTrue;
1920

2021
@RunWith(NestedRunner.class)
2122
public class UndoManagerTests {
@@ -40,6 +41,22 @@ public void incoming_change_is_not_merged_after_period_of_user_inactivity() {
4041
assertEquals("", area.getText());
4142
}
4243

44+
@Test // After undo, text insertion point jumps to the start of the text area #780
45+
public void undo_leaves_correct_insertion_point() {
46+
long periodOfUserInactivity = UndoUtils.DEFAULT_PREVENT_MERGE_DELAY.toMillis() + 300L;
47+
48+
write("abc def ");
49+
sleep(periodOfUserInactivity);
50+
51+
write("xyz");
52+
interact(area::undo);
53+
54+
write('g');
55+
56+
sleep(periodOfUserInactivity);
57+
assertTrue(area.getText().endsWith("g"));
58+
}
59+
4360
@Test
4461
public void testUndoWithWinNewlines() {
4562
String text1 = "abc\r\ndef";

Diff for: richtextfx/src/main/java/org/fxmisc/richtext/SelectionImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startP
269269
// (prevents a StringIndexOutOfBoundsException because
270270
// end is one char farther than area's length).
271271

272-
if (getLength() < getEndPosition()) {
273-
finalStart = getLength();
274-
finalEnd = getLength();
272+
if (getEndPosition() > 0) {
273+
finalStart = area.getLength();
274+
finalEnd = finalStart;
275275
}
276276
}
277277
}

0 commit comments

Comments
 (0)