How to get current editor line content
已回答
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!
请先登录再写评论。
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!