override fun documentChanged()

in terminal/src/main/kotlin/com/intellij/ideolog/terminal/highlighting/TerminalCommandBlockHighlighter.kt [62:85]


  override fun documentChanged(event: DocumentEvent) {
    if (event.document.textLength == 0) {
      synchronized(highlightingInfos) {
        highlightingInfos.clear()
      }
      return
    }
    val isRemovedNonEmptyPrompt = event.oldLength > event.newLength && !event.oldFragment.isNotBlank()
    if (isRemovedNonEmptyPrompt) {
      synchronized(highlightingInfos) {
        highlightingInfos.forEach { info ->
          if (event.offset < info.commandStartOffset) {
            info.commandStartOffset -= event.oldLength - event.newLength
          }
        }
        highlightingInfos.removeIf { info -> info.commandStartOffset < 0 }
      }
      if (::editor.isInitialized) {
        (editor as? Editor)?.run {
          detectIdeologContext(this).clear()
        }
      }
    }
  }