Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test and anchor properties fix #875

Merged
merged 1 commit into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void end_position_is_correct_when_change_occurs_after_position() {
});
}

@Test
public void deletion_which_includes_selection_and_which_occurs_at_end_of_area_moves_selection_to_new_area_end() {
interact(() -> {
selection.selectRange(area.getLength(), area.getLength());
Expand All @@ -167,4 +168,16 @@ public void deletion_which_includes_selection_and_which_occurs_at_end_of_area_mo
assertEquals(area.getLength(), selection.getEndPosition());
});
}

@Test
public void anchor_updates_correctly_with_listener_attached() {
interact(() -> {
area.clear();
area.anchorProperty().addListener( (ob,ov,nv) -> nv++ );
area.appendText("asdf");
area.selectRange(1,2);
assertEquals("s",area.getSelectedText());
assertEquals(1,area.getAnchor());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ public void displaceCaret(int position) {
public void displaceSelection(int startPosition, int endPosition) {
doUpdate(() -> {
delegateSelection.selectRange(startPosition, endPosition);

if ( startPosition < endPosition && internalStartedByAnchor.getValue() ) {
internalStartedByAnchor.setValue( false ); // See #874
}
internalStartedByAnchor.setValue(startPosition < endPosition);
});
}
Expand All @@ -449,6 +453,10 @@ public void dispose() {
private void doSelect(int startPosition, int endPosition, boolean anchorIsStart) {
doUpdate(() -> {
delegateSelection.selectRange(startPosition, endPosition);

if ( anchorIsStart && internalStartedByAnchor.getValue() ) {
internalStartedByAnchor.setValue( false ); // See #874
}
internalStartedByAnchor.setValue(anchorIsStart);

delegateCaret.moveTo(anchorIsStart ? endPosition : startPosition);
Expand Down