mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-22 01:34:04 +02:00
[VIM-2774] Move reset mode to another handler
This commit is contained in:
parent
7a26307a2b
commit
d03398f3e8
@ -19,6 +19,7 @@ package com.maddyhome.idea.vim.action
|
||||
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimCaret
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
@ -27,8 +28,33 @@ import com.maddyhome.idea.vim.command.VimStateMachine
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.mode
|
||||
|
||||
class ResetModeAction : VimActionHandler.SingleExecution() {
|
||||
class ResetModeAction : VimActionHandler.ConditionalMulticaret() {
|
||||
private lateinit var modeBeforeReset: VimStateMachine.Mode
|
||||
override val type: Command.Type = Command.Type.OTHER_WRITABLE
|
||||
override fun runAsMulticaret(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
modeBeforeReset = editor.mode
|
||||
KeyHandler.getInstance().fullReset(editor)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun execute(
|
||||
editor: VimEditor,
|
||||
caret: VimCaret,
|
||||
context: ExecutionContext,
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
if (modeBeforeReset == VimStateMachine.Mode.INSERT) {
|
||||
val position = injector.motion.getOffsetOfHorizontalMotion(editor, caret, -1, false)
|
||||
caret.moveToOffset(position)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun execute(
|
||||
editor: VimEditor,
|
||||
@ -36,16 +62,6 @@ class ResetModeAction : VimActionHandler.SingleExecution() {
|
||||
cmd: Command,
|
||||
operatorArguments: OperatorArguments,
|
||||
): Boolean {
|
||||
val modeBeforeReset = editor.mode
|
||||
KeyHandler.getInstance().fullReset(editor)
|
||||
|
||||
if (modeBeforeReset == VimStateMachine.Mode.INSERT) {
|
||||
editor.forEachCaret { caret ->
|
||||
val position = injector.motion.getOffsetOfHorizontalMotion(editor, caret, -1, false)
|
||||
caret.moveToOffset(position)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
error("This method should not be used")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user