How to know which line the specified position is in the TextArea
-
TextArea { id: text readOnly: true width: parent.width - 30 textFormat: Text.RichText renderType: Text.NativeRendering text: "hello\nhelloh\nellohxxxellohello" selectByMouse: true selectionColor: "#7887FF" selectedTextColor: "#FFF" }
After:
text.cursorPosition = 20; text.moveCursorSelection(23, TextEdit.SelectCharacters);
How to know which line the specified position is in the TextArea?
-
You can try to get the whole text from the start to the position of the cursor. Then split it into a list of lines and return the length of the list.
function currentLine(){ let list = text.text.substring(0, text.cursorPosition).split(/\n/gm) return list.length }