File tree Expand file tree Collapse file tree
integrationTest/java/org/fxmisc/richtext/api/selection
main/java/org/fxmisc/richtext Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ public void end_position_is_correct_when_change_occurs_after_position() {
159159 });
160160 }
161161
162+ @ Test
162163 public void deletion_which_includes_selection_and_which_occurs_at_end_of_area_moves_selection_to_new_area_end () {
163164 interact (() -> {
164165 selection .selectRange (area .getLength (), area .getLength ());
@@ -167,4 +168,16 @@ public void deletion_which_includes_selection_and_which_occurs_at_end_of_area_mo
167168 assertEquals (area .getLength (), selection .getEndPosition ());
168169 });
169170 }
171+
172+ @ Test
173+ public void anchor_updates_correctly_with_listener_attached () {
174+ interact (() -> {
175+ area .clear ();
176+ area .anchorProperty ().addListener ( (ob ,ov ,nv ) -> nv ++ );
177+ area .appendText ("asdf" );
178+ area .selectRange (1 ,2 );
179+ assertEquals ("s" ,area .getSelectedText ());
180+ assertEquals (1 ,area .getAnchor ());
181+ });
182+ }
170183}
Original file line number Diff line number Diff line change @@ -431,6 +431,10 @@ public void displaceCaret(int position) {
431431 public void displaceSelection (int startPosition , int endPosition ) {
432432 doUpdate (() -> {
433433 delegateSelection .selectRange (startPosition , endPosition );
434+
435+ if ( startPosition < endPosition && internalStartedByAnchor .getValue () ) {
436+ internalStartedByAnchor .setValue ( false ); // See #874
437+ }
434438 internalStartedByAnchor .setValue (startPosition < endPosition );
435439 });
436440 }
@@ -449,6 +453,10 @@ public void dispose() {
449453 private void doSelect (int startPosition , int endPosition , boolean anchorIsStart ) {
450454 doUpdate (() -> {
451455 delegateSelection .selectRange (startPosition , endPosition );
456+
457+ if ( anchorIsStart && internalStartedByAnchor .getValue () ) {
458+ internalStartedByAnchor .setValue ( false ); // See #874
459+ }
452460 internalStartedByAnchor .setValue (anchorIsStart );
453461
454462 delegateCaret .moveTo (anchorIsStart ? endPosition : startPosition );
You can’t perform that action at this time.
0 commit comments