How to get current editor line content
Answered
Hello,
I need to get text from current line. I tried something like this
val caretModel: CaretModel = editor.caretModel
val psiFile = PsiManager.getInstance(project).findFile(virtualFile) ?: return
val currentLinePsiElement = psiFile.findElementAt(caretModel.offset)
But it return only current PsiElement, not an full text.
Could someone help?
Thank you!
Please sign in to leave a comment.
Hello, If we are talking about the content of a particular line (from the startOffset to the endOffset), then it would be more correct to use the document:
This is exactly what is needed. Thank you so much!