package org.fxmisc.richtext.keyboard.navigation;

import javafx.stage.Stage;
import org.fxmisc.richtext.InlineCssTextAreaAppTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

import static javafx.scene.input.KeyCode.DOWN;
import static javafx.scene.input.KeyCode.UP;
import static org.junit.Assert.assertEquals;

public class MultiLineJaggedTextTests extends InlineCssTextAreaAppTest {

    @Rule
    public Timeout globalTimeout = Timeout.seconds(10);

    String threeLinesOfText = "Some long amount of text to take up a lot of space in the given area.";

    @Override
    public void start(Stage stage) throws Exception {
        super.start(stage);
        stage.setWidth(200);
        area.replaceText(threeLinesOfText);
        area.setWrapText(true);
    }

    @Test
    public void pressing_down_moves_caret_to_next_line() {
        area.moveTo(27);

        push(DOWN);

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

    @Test
    public void pressing_up_moves_caret_to_previous_line() {
        area.moveTo(66);

        push(UP);

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

@@ -886,10 +886,90 @@
 eTo(
-27
+0);%0A        assertEquals(0, area.getCaretSelectionBind().getLineIndex().getAsInt()
 );%0A%0A
@@ -1014,10 +1014,9 @@
 als(
-57
+1
 , ar
@@ -1022,32 +1022,63 @@
 rea.getCaret
-Position
+SelectionBind().getLineIndex().getAsInt
 ());%0A    %7D%0A%0A
@@ -1172,79 +1172,296 @@
 eTo(
-66);%0A%0A        push(UP);%0A%0A        assertEquals(36, area.getCaretPosition
+area.getLength());%0A        int lastLineIndex = area.getParagraphLinesCount(0) - 1;%0A        assertEquals(lastLineIndex, area.getCaretSelectionBind().getLineIndex().getAsInt());%0A%0A        push(UP);%0A%0A        assertEquals(lastLineIndex - 1, area.getCaretSelectionBind().getLineIndex().getAsInt
 ());

Use different approach to determine line index of caret