Search in sources :

Example 6 with Position

use of org.fxmisc.richtext.model.TwoDimensional.Position in project RichTextFX by FXMisc.

the class TwoLevelNavigatorTest method testLeftBoundary.

@Test
public void testLeftBoundary() {
    Position pos = navigator.offsetToPosition(25, Forward).offsetBy(-50, Forward);
    assertEquals(0, pos.getMajor());
    assertEquals(0, pos.getMinor());
}
Also used : Position(org.fxmisc.richtext.model.TwoDimensional.Position) Test(org.junit.Test)

Example 7 with Position

use of org.fxmisc.richtext.model.TwoDimensional.Position in project RichTextFX by FXMisc.

the class Paragraph method getStyleRangeAtPosition.

/**
 * Returns the range of homogeneous style that includes the given position.
 * If {@code position} points to a boundary between two styled ranges,
 * then the range preceding {@code position} is returned.
 */
public IndexRange getStyleRangeAtPosition(int position) {
    Position pos = styles.offsetToPosition(position, Backward);
    int start = position - pos.getMinor();
    int end = start + styles.getStyleSpan(pos.getMajor()).getLength();
    return new IndexRange(start, end);
}
Also used : IndexRange(javafx.scene.control.IndexRange) Position(org.fxmisc.richtext.model.TwoDimensional.Position)

Example 8 with Position

use of org.fxmisc.richtext.model.TwoDimensional.Position in project RichTextFX by FXMisc.

the class GenericStyledAreaBehavior method downLines.

private void downLines(SelectionPolicy selectionPolicy, int nLines) {
    Position currentLine = view.currentLine();
    Position targetLine = currentLine.offsetBy(nLines, Forward).clamp();
    if (!currentLine.sameAs(targetLine)) {
        // compute new caret position
        CharacterHit hit = view.hit(view.getTargetCaretOffset(), targetLine);
        // update model
        view.moveTo(hit.getInsertionIndex(), selectionPolicy);
    }
}
Also used : Position(org.fxmisc.richtext.model.TwoDimensional.Position)

Example 9 with Position

use of org.fxmisc.richtext.model.TwoDimensional.Position in project RichTextFX by FXMisc.

the class Paragraph method trim.

public Paragraph<PS, SEG, S> trim(int length) {
    if (length >= length()) {
        return this;
    } else {
        Position pos = navigator.offsetToPosition(length, Backward);
        int segIdx = pos.getMajor();
        List<SEG> segs = new ArrayList<>(segIdx + 1);
        segs.addAll(segments.subList(0, segIdx));
        segs.add(segmentOps.subSequence(segments.get(segIdx), 0, pos.getMinor()));
        if (segs.isEmpty()) {
            segs.add(segmentOps.createEmptySeg());
        }
        return new Paragraph<>(paragraphStyle, segmentOps, segs, styles.subView(0, length));
    }
}
Also used : Position(org.fxmisc.richtext.model.TwoDimensional.Position) ArrayList(java.util.ArrayList)

Example 10 with Position

use of org.fxmisc.richtext.model.TwoDimensional.Position in project RichTextFX by FXMisc.

the class TwoLevelNavigatorTest method testPositiveOffsetWithBackwardBias.

@Test
public void testPositiveOffsetWithBackwardBias() {
    Position pos = navigator.offsetToPosition(10, Backward);
    assertEquals(0, pos.getMajor());
    assertEquals(10, pos.getMinor());
}
Also used : Position(org.fxmisc.richtext.model.TwoDimensional.Position) Test(org.junit.Test)

Aggregations

Position (org.fxmisc.richtext.model.TwoDimensional.Position)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)1 IndexRange (javafx.scene.control.IndexRange)1