mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-06-05 22:34:03 +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.KeyHandler
|
||||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
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.VimEditor
|
||||||
import com.maddyhome.idea.vim.api.injector
|
import com.maddyhome.idea.vim.api.injector
|
||||||
import com.maddyhome.idea.vim.command.Command
|
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.handler.VimActionHandler
|
||||||
import com.maddyhome.idea.vim.helper.mode
|
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 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(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
@ -36,16 +62,6 @@ class ResetModeAction : VimActionHandler.SingleExecution() {
|
|||||||
cmd: Command,
|
cmd: Command,
|
||||||
operatorArguments: OperatorArguments,
|
operatorArguments: OperatorArguments,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val modeBeforeReset = editor.mode
|
error("This method should not be used")
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user