mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-06-02 04:34:06 +02:00
Specify which commands perform mode change
We need this for undo subsystem. Mode change is not something that we want to be a separate entity in the undo log P.S. It's not a full list of such commands, e.g. <ESC> for leaving insert mode is missing. It is because <ESC> may insert some text after visual block mode, I'll figure out a solution for this later
This commit is contained in:
parent
eae3fb3ebe
commit
cccb23d9ee
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
@ -14,14 +14,18 @@ import com.maddyhome.idea.vim.api.ExecutionContext
|
|||||||
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
|
||||||
|
import com.maddyhome.idea.vim.command.CommandFlags
|
||||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||||
|
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||||
import com.maddyhome.idea.vim.undo.VimKeyBasedUndoService
|
import com.maddyhome.idea.vim.undo.VimKeyBasedUndoService
|
||||||
import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService
|
import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService
|
||||||
|
import java.util.EnumSet
|
||||||
|
|
||||||
@CommandOrMotion(keys = ["<C-G>u"], modes = [Mode.INSERT])
|
@CommandOrMotion(keys = ["<C-G>u"], modes = [Mode.INSERT])
|
||||||
class BreakUndoSequenceAction : VimActionHandler.SingleExecution() {
|
class BreakUndoSequenceAction : VimActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||||
|
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_UNDO_AWARE)
|
||||||
|
|
||||||
override fun execute(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
|
@ -19,7 +19,7 @@ import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
|||||||
|
|
||||||
@CommandOrMotion(keys = ["a"], modes = [Mode.NORMAL])
|
@CommandOrMotion(keys = ["a"], modes = [Mode.NORMAL])
|
||||||
class InsertAfterCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
class InsertAfterCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.INSERT
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
|
@ -19,7 +19,7 @@ import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
|||||||
|
|
||||||
@CommandOrMotion(keys = ["A"], modes = [Mode.NORMAL])
|
@CommandOrMotion(keys = ["A"], modes = [Mode.NORMAL])
|
||||||
class InsertAfterLineEndAction : ChangeEditorActionHandler.SingleExecution() {
|
class InsertAfterLineEndAction : ChangeEditorActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.INSERT
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
|
@ -21,7 +21,7 @@ import org.jetbrains.annotations.Contract
|
|||||||
@CommandOrMotion(keys = ["i", "<Insert>"], modes = [Mode.NORMAL])
|
@CommandOrMotion(keys = ["i", "<Insert>"], modes = [Mode.NORMAL])
|
||||||
class InsertBeforeCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
class InsertBeforeCursorAction : ChangeEditorActionHandler.SingleExecution() {
|
||||||
@get:Contract(pure = true)
|
@get:Contract(pure = true)
|
||||||
override val type: Command.Type = Command.Type.INSERT
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
|
@ -19,7 +19,7 @@ import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler
|
|||||||
|
|
||||||
@CommandOrMotion(keys = ["I"], modes = [Mode.NORMAL])
|
@CommandOrMotion(keys = ["I"], modes = [Mode.NORMAL])
|
||||||
class InsertBeforeFirstNonBlankAction : ChangeEditorActionHandler.SingleExecution() {
|
class InsertBeforeFirstNonBlankAction : ChangeEditorActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.INSERT
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
|
@ -22,7 +22,7 @@ import java.util.*
|
|||||||
@CommandOrMotion(keys = [":"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
|
@CommandOrMotion(keys = [":"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
|
||||||
class ExEntryAction : VimActionHandler.SingleExecution() {
|
class ExEntryAction : VimActionHandler.SingleExecution() {
|
||||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_START_EX)
|
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_START_EX)
|
||||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||||
if (editor.isOneLineMode()) return false
|
if (editor.isOneLineMode()) return false
|
||||||
|
@ -25,7 +25,7 @@ import java.util.*
|
|||||||
@CommandOrMotion(keys = ["<Esc>", "<C-[>", "<C-C>"], modes = [Mode.CMD_LINE])
|
@CommandOrMotion(keys = ["<Esc>", "<C-[>", "<C-C>"], modes = [Mode.CMD_LINE])
|
||||||
class LeaveCommandLineAction : VimActionHandler.SingleExecution() {
|
class LeaveCommandLineAction : VimActionHandler.SingleExecution() {
|
||||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_END_EX)
|
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_END_EX)
|
||||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||||
val argument = cmd.argument as? Argument.ExString ?: return true
|
val argument = cmd.argument as? Argument.ExString ?: return true
|
||||||
|
@ -14,12 +14,16 @@ import com.maddyhome.idea.vim.api.ExecutionContext
|
|||||||
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
|
||||||
|
import com.maddyhome.idea.vim.command.CommandFlags
|
||||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||||
|
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||||
|
import java.util.EnumSet
|
||||||
|
|
||||||
@CommandOrMotion(keys = ["<Insert>"], modes = [Mode.CMD_LINE])
|
@CommandOrMotion(keys = ["<Insert>"], modes = [Mode.CMD_LINE])
|
||||||
class ToggleInsertModeAction : VimActionHandler.SingleExecution() {
|
class ToggleInsertModeAction : VimActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
||||||
|
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_UNDO_AWARE)
|
||||||
|
|
||||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||||
val commandLine = injector.commandLine.getActiveCommandLine() ?: return false
|
val commandLine = injector.commandLine.getActiveCommandLine() ?: return false
|
||||||
|
@ -21,7 +21,7 @@ import java.util.*
|
|||||||
|
|
||||||
@CommandOrMotion(keys = ["/"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
|
@CommandOrMotion(keys = ["/"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
|
||||||
class SearchEntryFwdAction : VimActionHandler.SingleExecution() {
|
class SearchEntryFwdAction : VimActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_START_EX, CommandFlags.FLAG_SAVE_JUMP)
|
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_START_EX, CommandFlags.FLAG_SAVE_JUMP)
|
||||||
|
|
||||||
override fun execute( editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
override fun execute( editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||||
@ -32,7 +32,7 @@ class SearchEntryFwdAction : VimActionHandler.SingleExecution() {
|
|||||||
|
|
||||||
@CommandOrMotion(keys = ["?"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
|
@CommandOrMotion(keys = ["?"], modes = [Mode.NORMAL, Mode.VISUAL, Mode.OP_PENDING])
|
||||||
class SearchEntryRevAction : VimActionHandler.SingleExecution() {
|
class SearchEntryRevAction : VimActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_START_EX, CommandFlags.FLAG_SAVE_JUMP)
|
override val flags: EnumSet<CommandFlags> = enumSetOf(CommandFlags.FLAG_START_EX, CommandFlags.FLAG_SAVE_JUMP)
|
||||||
|
|
||||||
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||||
|
@ -25,7 +25,7 @@ import com.maddyhome.idea.vim.helper.exitVisualMode
|
|||||||
*/
|
*/
|
||||||
@CommandOrMotion(keys = ["<Esc>", "<C-[>", "<C-C>"], modes = [Mode.VISUAL])
|
@CommandOrMotion(keys = ["<Esc>", "<C-[>", "<C-C>"], modes = [Mode.VISUAL])
|
||||||
class VisualExitModeAction : VimActionHandler.ConditionalMulticaret() {
|
class VisualExitModeAction : VimActionHandler.ConditionalMulticaret() {
|
||||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
override fun runAsMulticaret(
|
override fun runAsMulticaret(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
context: ExecutionContext,
|
context: ExecutionContext,
|
||||||
|
@ -21,7 +21,7 @@ import com.maddyhome.idea.vim.options.OptionConstants
|
|||||||
|
|
||||||
@CommandOrMotion(keys = ["<C-q>", "<C-v>"], modes = [Mode.NORMAL, Mode.VISUAL])
|
@CommandOrMotion(keys = ["<C-q>", "<C-v>"], modes = [Mode.NORMAL, Mode.VISUAL])
|
||||||
class VisualToggleBlockModeAction : VimActionHandler.SingleExecution() {
|
class VisualToggleBlockModeAction : VimActionHandler.SingleExecution() {
|
||||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
override val type: Command.Type = Command.Type.MODE_CHANGE
|
||||||
|
|
||||||
override fun execute(
|
override fun execute(
|
||||||
editor: VimEditor,
|
editor: VimEditor,
|
||||||
|
@ -93,11 +93,12 @@ data class Command(
|
|||||||
*/
|
*/
|
||||||
OTHER_SELF_SYNCHRONIZED,
|
OTHER_SELF_SYNCHRONIZED,
|
||||||
|
|
||||||
|
MODE_CHANGE,
|
||||||
;
|
;
|
||||||
|
|
||||||
val isRead: Boolean
|
val isRead: Boolean
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
MOTION, COPY, OTHER_READONLY -> true
|
MOTION, COPY, OTHER_READONLY, MODE_CHANGE -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ abstract class EditorActionHandlerBase(private val myRunForEachCaret: Boolean) {
|
|||||||
if (editor.mode == Mode.INSERT) return // typing handles undo on its own
|
if (editor.mode == Mode.INSERT) return // typing handles undo on its own
|
||||||
if (command.flags.contains(CommandFlags.FLAG_UNDO_AWARE)) return
|
if (command.flags.contains(CommandFlags.FLAG_UNDO_AWARE)) return
|
||||||
|
|
||||||
if (command.type == Command.Type.MOTION) {
|
if (command.type == Command.Type.MOTION || command.type == Command.Type.MODE_CHANGE) {
|
||||||
undo.setMergeUndoKey()
|
undo.setMergeUndoKey()
|
||||||
} else {
|
} else {
|
||||||
undo.updateNonMergeUndoKey()
|
undo.updateNonMergeUndoKey()
|
||||||
|
Loading…
Reference in New Issue
Block a user