RichTextFX CodeArea Force Caret to Last Paragraph

145 views Asked by At

I'm designing a cmd like console I want to force the caret to last line so that previous line wont be editable.

codeArea.currentParagraphProperty().addListener((obs, o, n) -> codeArea.moveTo(codeArea.getLength()));

I used the above statement to force caret to last character of CodeArea although it works when I try to reach previous line but fails to work when I press backspace as it moves caret to previous line by removing characters. I want the caret to be uneditable from current paragraph containing directory path till first line of code area

1

There are 1 answers

0
blaze-centurion On

Rather than using this.

codeArea.currentParagraphProperty().addListener((obs, o, n) -> codeArea.moveTo(codeArea.getLength()));

Use this code:

codeArea.currentParagraphProperty().addListener((obs, o, n) -> codeArea.getCaretSelectionBind().moveTo(codeArea.getText().length()));