override fun execute()

in vim-engine/src/main/kotlin/com/maddyhome/idea/vim/key/MappingInfo.kt [165:219]


  override fun execute(editor: VimEditor, context: ExecutionContext, keyState: KeyHandlerState) {
    LOG.debug("Executing 'ToHandler' mapping info...")

    // Cache isOperatorPending in case the extension changes the mode while moving the caret
    // See CommonExtensionTest
    val shouldCalculateOffsets: Boolean = editor.mode is Mode.OP_PENDING

    val startOffsets: Map<ImmutableVimCaret, Int> = editor.carets().associateWith { it.offset }

    if (extensionHandler.isRepeatable) {
      clean()
    }

    val handler = extensionHandler
    if (handler is ExtensionHandler.WithCallback) {
      handler._backingFunction = Runnable {
        myFun(shouldCalculateOffsets, editor, startOffsets, keyState)

        if (shouldCalculateOffsets) {
          injector.application.invokeLater {
            val keyHandler = KeyHandler.getInstance()
            keyHandler.finishedCommandPreparation(
              editor,
              context,
              null,
              false,
              keyState,
            )
          }
        }
      }
    }

    val operatorArguments = OperatorArguments(keyState.commandBuilder.calculateCount0Snapshot(), editor.mode)
    val register = keyState.commandBuilder.registerSnapshot
    if (register != null) {
      injector.registerGroup.selectRegister(register)
    }
    injector.actionExecutor.executeCommand(
      editor,
      { extensionHandler.execute(editor, context, operatorArguments) },
      "Vim " + extensionHandler.javaClass.simpleName,
      null,
    )

    if (extensionHandler.isRepeatable) {
      lastExtensionHandler = extensionHandler
      argumentCaptured = null
      repeatHandler = true
    }

    if (handler !is ExtensionHandler.WithCallback) {
      myFun(shouldCalculateOffsets, editor, startOffsets, keyState)
    }
  }