Skip to content

Commit

Permalink
Fix TextFlowExt hit (#992)
Browse files Browse the repository at this point in the history
Fix TextFlowExt hit and added click on padding test
  • Loading branch information
Jugen authored Dec 23, 2020
1 parent 45dc5e2 commit fa17d28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nitorcreations.junit.runners.NestedRunner;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.stage.Stage;
import org.fxmisc.richtext.InlineCssTextAreaAppTest;
import org.junit.Test;
Expand Down Expand Up @@ -117,6 +118,24 @@ public void single_clicking_area_moves_caret_to_that_position()
assertEquals(firstWord.length(), area.getCaretPosition());
}

@Test
public void single_clicking_area_beyond_text_moves_caret_to_end_position()
throws InterruptedException, ExecutionException {

int position = firstParagraph.length() + secondWord.length();
interact( () -> area.getStylesheets ().add("org/fxmisc/richtext/mouse/padtest.css") );
assertEquals(0, area.getCaretPosition());
clickOn( area );

Bounds b = asyncFx(
() -> area.getCharacterBoundsOnScreen(position, position + 1).get())
.get();

moveTo(new Point2D( b.getMaxX(), b.getMaxY()+25 )).clickOn(PRIMARY);

assertEquals(area.getLength(), area.getCaretPosition());
}

@Test
public void double_clicking_text_in_area_selects_closest_word() {
doubleClickOnFirstLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.styled-text-area .paragraph-text
{
-fx-padding: 0 0 50pt 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ CharacterHit hit(double x, double y) {
int charIdx = hit.getCharIndex();
boolean leading = hit.isLeading();

if (y >= span.getBounds().getMaxY()) {
return CharacterHit.insertionAt(charIdx);
}

if ( ! leading && getLineCount() > 1) {
// If this is a wrapped paragraph and hit character is at end of hit line, make sure that the
// "character hit" stays at the end of the hit line (and not at the beginning of the next line).
Expand Down

0 comments on commit fa17d28

Please # to comment.