automatic tab indentation after new line (textEdit element)
-
We are working on an Code Editor in our Company, for that we are using an textEdit element in our qml program.
What I am trying to achieve is that after a new Line an automatic Tab indentation is placed, like in popular IDEs like Visual Studiothis is the code I already have for that in my textedit element:
Keys.onPressed: { if(event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { pos1 = edit.cursorPosition //helping variable to reset actual position in line console.log("lastTab nach enter: " + posDifference) let spaces = ""; for(let i = 0; i < posDifference; i++) { spaces += " " console.log("Iterator:" + i) } } } onLineCountChanged: / { update() console.log("string to write:"+ spaces) edit.cursorPosition = edit.length edit.insert(edit.cursorPosition,spaces) }
the problem is that the blank spaces are placed in the previous line not in the new Line. I have no idea how to fix.
Note: posDifferent is the actual Position in the current line