EA-215872: Check text range validity before 'getText(range)'

This commit is contained in:
Yan Zhulanow
2019-11-13 20:37:22 +09:00
parent 49bcb103ef
commit 89bd3b8767
@@ -15,6 +15,7 @@ import com.intellij.openapi.editor.event.EditorFactoryListener
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.idea.core.util.end
import org.jetbrains.kotlin.idea.core.util.range
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.psiUtil.endOffset
@@ -47,6 +48,9 @@ class KotlinCodeHintsModel(val project: Project) : EditorFactoryListener {
if (textRange == null || !(textRange.startOffset <= offset && offset <= textRange.endOffset)) {
return@firstOrNull false
}
if (textRange.end > document.textLength) {
return@firstOrNull false
}
val document = marker.document
val hasNewLine = document.getText(textRange).contains('\n')