override fun showDigraphs()

in vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimDigraphGroupBase.kt [116:193]


  override fun showDigraphs(editor: VimEditor, showHeaders: Boolean) {
    val width = injector.engineEditorHelper.getApproximateOutputPanelWidth(editor).let { if (it < 10) 80 else it }

    // Vim's columns are 13 characters wide, but for some reason, they suddenly switch to 12. It makes no obvious sense,
    // and it's a quirk too far to copy.
    val columnWidth = 13
    val columnCount = width / columnWidth
    val height = ceil(digraphToCodepoint.size.toDouble() / columnCount.toDouble()).toInt()

    if (logger.isDebug()) {
      logger.debug("width=$width")
      logger.debug("colCount=$columnCount")
      logger.debug("height=$height")
    }

    val digraphCount = (defaultDigraphs.size / 3) + customDigraphToCodepoint.size
    val capacity = (digraphCount * columnWidth) + (digraphCount / columnCount) + 300 // Text + newlines + headers
    val output = buildString(capacity) {
      var column = 0
      var columnLength = 0
      var previousUnicodeBlock: Character.UnicodeBlock? = null

      // We cannot guarantee ordering with the dictionaries, so let's use the defaultDigraphs list.
      // We output in codepoint order, but there are duplicate digraphs for some codepoints and we want control of order
      for (i in 0 until defaultDigraphs.size step 3) {
        val codepoint = defaultDigraphs[i + 2].code

        // Show headers if requested. Vim shows headers for some Unicode blocks, but not all. And its block boundaries
        // aren't necessarily correct
        val block = getVimCompatibleUnicodeBlock(codepoint)
        if (showHeaders && block != previousUnicodeBlock && digraphHeaderNames.containsKey(block)) {
          if (column != 0) {
            appendLine()
          }
          appendLine(digraphHeaderNames[block])
          previousUnicodeBlock = block
          column = 0
        }

        if (column != 0) {
          repeat(columnWidth - (columnLength % columnWidth)) { append(' ') }
        }

        columnLength = appendDigraph(defaultDigraphs[i], defaultDigraphs[i + 1], codepoint)
        column++

        if (column == columnCount) {
          appendLine()
          column = 0
        }
      }

      if (showHeaders && customDigraphToCodepoint.isNotEmpty()) {
        if (column != 0) {
          appendLine()
        }
        appendLine("Custom")
        column = 0
      }

      customDigraphToCodepoint.forEach { (digraph, char) ->
        if (column != 0) {
          repeat(columnWidth - (columnLength % columnWidth)) { append(' ') }
        }

        columnLength = appendDigraph(digraph[0], digraph[1], char)
        column++

        if (column == columnCount) {
          appendLine()
          column = 0
        }
      }
    }

    val context = injector.executionContextManager.getEditorExecutionContext(editor)
    injector.outputPanel.output(editor, context, output)
  }