Skip to content

Commit

Permalink
Fixes bug #780 After undo (ctrl-Z), text insertion point jumps to the…
Browse files Browse the repository at this point in the history
… start (#785)
  • Loading branch information
Jugen authored Nov 12, 2018
1 parent ff54681 commit cc11721
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(NestedRunner.class)
public class UndoManagerTests {
Expand All @@ -40,6 +41,22 @@ public void incoming_change_is_not_merged_after_period_of_user_inactivity() {
assertEquals("", area.getText());
}

@Test // After undo, text insertion point jumps to the start of the text area #780
public void undo_leaves_correct_insertion_point() {
long periodOfUserInactivity = UndoUtils.DEFAULT_PREVENT_MERGE_DELAY.toMillis() + 300L;

write("abc def ");
sleep(periodOfUserInactivity);

write("xyz");
interact(area::undo);

write('g');

sleep(periodOfUserInactivity);
assertTrue(area.getText().endsWith("g"));
}

@Test
public void testUndoWithWinNewlines() {
String text1 = "abc\r\ndef";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startP
// (prevents a StringIndexOutOfBoundsException because
// end is one char farther than area's length).

if (getLength() < getEndPosition()) {
finalStart = getLength();
finalEnd = getLength();
if (getEndPosition() > 0) {
finalStart = area.getLength();
finalEnd = finalStart;
}
}
}
Expand Down

0 comments on commit cc11721

Please sign in to comment.