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());
}
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);
}
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);
}
}
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));
}
}
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());
}
Aggregations