override fun displayLocationInfo()

in vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimFileBase.kt [28:94]


  override fun displayLocationInfo(editor: VimEditor) {
    val msg = buildString {

      val caret = editor.currentCaret()
      val offset = editor.currentCaret().offset
      val totalByteCount = editor.fileSize()
      val totalWordCount = countBigWords(editor, offset)

      if (!editor.inVisualMode) {
        val pos = caret.getBufferPosition()
        val line = pos.line + 1
        val col = pos.column + 1
        val lineEndOffset = editor.getLineEndOffset(pos.line)
        val lineEndCol = editor.offsetToBufferPosition(lineEndOffset).column

        // Note that Vim can have different screen columns to buffer columns, and displays these in the form "Col 1-3".
        // Vim uses screen columns to insert inlay text and symbols such as word wrap indicators, but has a single line
        // even when wrapped, unlike IntelliJ, which has a virtual line per screen line. Because of this, it's not clear
        // how IdeaVim could represent this, or even if it would be worthwhile to do so.
        append("Col ").append(col).append(" of ").append(lineEndCol)
        append("; Line ").append(line).append(" of ").append(editor.lineCount())
        append("; Word ").append(totalWordCount.currentWord).append(" of ").append(totalWordCount.count)
        append("; Byte ").append(offset + 1).append(" of ").append(totalByteCount)
      }
      else {

        append("Selected ")

        val selection = VimSelection.create(
          caret.vimSelectionStart,
          caret.offset,
          editor.mode.selectionType ?: CHARACTER_WISE,
          editor
        ).toVimTextRange()

        val selectedLineCount: Int
        val selectedWordCount: Int
        if (selection.isMultiple) {
          selectedLineCount = selection.size()

          var count = 0
          for (i in 0 until selection.size()) {
            val wordCount = countBigWords(editor, offset, selection.startOffsets[i], selection.endOffsets[i])
            count += wordCount.count
          }
          selectedWordCount = count

          append(selection.maxLength).append(" Cols; ")
        }
        else {
          val startPos = editor.offsetToBufferPosition(selection.startOffset)
          val endPos = editor.offsetToBufferPosition(selection.endOffsetInclusive)

          selectedLineCount = endPos.line - startPos.line + 1

          val wordCount = countBigWords(editor, offset, selection.startOffset, selection.endOffset)
          selectedWordCount = wordCount.count
        }

        append(selectedLineCount).append(" of ").append(editor.lineCount()).append(" Lines; ")
        append(selectedWordCount).append(" of ").append(totalWordCount.count).append(" Words; ")
        append(selection.selectionCount).append(" of ").append(totalByteCount).append(" Bytes")
      }
    }

    injector.messages.showStatusBarMessage(editor, msg)
  }