mirror of
https://github.com/chylex/IntelliJ-Rainbow-Brackets.git
synced 2025-05-14 12:34:03 +02:00
parent
385ebd126d
commit
04df9188d8
@ -13,9 +13,11 @@ import com.intellij.notification.NotificationGroup
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.core.util.getLineCount
|
||||
import java.awt.Color
|
||||
|
||||
|
||||
@ -114,4 +116,20 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private var bigFilesNotified = false
|
||||
private var bigFilesNotified = false
|
||||
|
||||
fun PsiElement.getLineCount(): Int {
|
||||
val doc = containingFile?.let { PsiDocumentManager.getInstance(project).getDocument(it) }
|
||||
if (doc != null) {
|
||||
val spaceRange = textRange ?: TextRange.EMPTY_RANGE
|
||||
|
||||
if (spaceRange.endOffset <= doc.textLength && spaceRange.startOffset < spaceRange.endOffset) {
|
||||
val startLine = doc.getLineNumber(spaceRange.startOffset)
|
||||
val endLine = doc.getLineNumber(spaceRange.endOffset - 1)
|
||||
|
||||
return endLine - startLine + 1
|
||||
}
|
||||
}
|
||||
|
||||
return StringUtil.getLineBreakCount(text ?: "") + 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user