Search in sources :

Example 1 with TwoLevelNavigator

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

the class TextFlowExt method getLineStartPosition.

int getLineStartPosition(int charIdx) {
    TextLine[] lines = getLines();
    TwoLevelNavigator navigator = new TwoLevelNavigator(() -> lines.length, i -> lines[i].getLength());
    int currentLineIndex = navigator.offsetToPosition(charIdx, Forward).getMajor();
    return navigator.position(currentLineIndex, 0).toOffset();
}
Also used : TwoLevelNavigator(org.fxmisc.richtext.model.TwoLevelNavigator)

Example 2 with TwoLevelNavigator

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

the class TextFlowExt method getLineOfCharacter.

int getLineOfCharacter(int charIdx) {
    TextLine[] lines = getLines();
    TwoLevelNavigator navigator = new TwoLevelNavigator(() -> lines.length, i -> lines[i].getLength());
    return navigator.offsetToPosition(charIdx, Forward).getMajor();
}
Also used : TwoLevelNavigator(org.fxmisc.richtext.model.TwoLevelNavigator)

Example 3 with TwoLevelNavigator

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

the class TextFlowExt method getLineEndPosition.

int getLineEndPosition(int charIdx) {
    TextLine[] lines = getLines();
    TwoLevelNavigator navigator = new TwoLevelNavigator(() -> lines.length, i -> lines[i].getLength());
    int currentLineIndex = navigator.offsetToPosition(charIdx, Forward).getMajor();
    int minor = currentLineIndex == lines.length - 1 ? 0 : -1;
    return navigator.position(currentLineIndex + 1, minor).toOffset();
}
Also used : TwoLevelNavigator(org.fxmisc.richtext.model.TwoLevelNavigator)

Aggregations

TwoLevelNavigator (org.fxmisc.richtext.model.TwoLevelNavigator)3