mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-02-28 02:45:59 +01:00
Macro without invokeLater
This commit is contained in:
parent
1e2005451c
commit
d0670d0244
src/main/java/com/maddyhome/idea/vim
@ -150,15 +150,10 @@ public class MacroGroup {
|
||||
ApplicationManager.getApplication().invokeLater(() -> CommandProcessor.getInstance()
|
||||
.executeCommand(project, run, MessageHelper.message("command.name.vim.macro.playback"), keys.get(pos)));
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("processing key " + pos);
|
||||
}
|
||||
// Handle one keystroke then queue up the next key
|
||||
KeyHandler.getInstance().handleKey(editor, keys.get(pos), context);
|
||||
if (pos < keys.size() - 1) {
|
||||
playbackKeys(editor, context, project, keys, pos + 1, cnt, total);
|
||||
} else {
|
||||
playbackKeys(editor, context, project, keys, 0, cnt + 1, total);
|
||||
for (int i = 0; i < total; ++i) {
|
||||
for (KeyStroke key : keys) {
|
||||
KeyHandler.getInstance().handleKey(editor, key, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,64 +20,76 @@ package com.maddyhome.idea.vim.vimscript.model.commands
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.LogicalPosition
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
|
||||
import com.maddyhome.idea.vim.helper.exitInsertMode
|
||||
import com.maddyhome.idea.vim.helper.exitSelectMode
|
||||
import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
||||
import com.maddyhome.idea.vim.helper.mode
|
||||
import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
|
||||
data class NormalCommand(val ranges: Ranges, val argument: String) : Command.SingleExecution(ranges, argument) {
|
||||
override val argFlags = flags(RangeFlag.RANGE_OPTIONAL, ArgumentFlag.ARGUMENT_OPTIONAL, Access.WRITABLE, Flag.SAVE_VISUAL)
|
||||
|
||||
override fun processCommand(editor: Editor, context: DataContext): ExecutionResult {
|
||||
// var useMappings = true
|
||||
// var argument = argument
|
||||
// if (argument.startsWith("!")) {
|
||||
// useMappings = false
|
||||
// argument = argument.substring(1)
|
||||
// }
|
||||
//
|
||||
// val commandState = CommandState.getInstance(editor)
|
||||
// val rangeUsed = ranges.size() != 0
|
||||
// when (editor.mode) {
|
||||
// CommandState.Mode.VISUAL -> {
|
||||
// editor.getTopLevelEditor().exitVisualMode()
|
||||
// if (!rangeUsed) {
|
||||
// val selectionStart = VimPlugin.getMark().getMark(editor, '<')!!
|
||||
// editor.caretModel.moveToLogicalPosition(LogicalPosition(selectionStart.logicalLine, selectionStart.col))
|
||||
// }
|
||||
// }
|
||||
// CommandState.Mode.CMD_LINE -> VimPlugin.getProcess().cancelExEntry(editor, false)
|
||||
// CommandState.Mode.INSERT, CommandState.Mode.REPLACE -> editor.exitInsertMode(context, OperatorArguments(false, 1, commandState.mode, commandState.subMode))
|
||||
// CommandState.Mode.SELECT -> editor.exitSelectMode(false)
|
||||
// CommandState.Mode.OP_PENDING, CommandState.Mode.COMMAND -> Unit
|
||||
// }
|
||||
// val range = getLineRange(editor, editor.caretModel.primaryCaret)
|
||||
//
|
||||
// for (line in range.startLine..range.endLine) {
|
||||
// if (rangeUsed) {
|
||||
// // Move caret to the first position on line
|
||||
// if (editor.document.lineCount < line) {
|
||||
// break
|
||||
// }
|
||||
// val startOffset = EditorHelper.getLineStartOffset(editor, line)
|
||||
// editor.caretModel.moveToOffset(startOffset)
|
||||
// }
|
||||
//
|
||||
// // Perform operations
|
||||
// val keys = stringToKeys(argument)
|
||||
// val keyHandler = KeyHandler.getInstance()
|
||||
// keyHandler.reset(editor)
|
||||
// for (key in keys) {
|
||||
// keyHandler.handleKey(editor, key, context, useMappings, true)
|
||||
// }
|
||||
//
|
||||
// // Exit if state leaves as insert or cmd_line
|
||||
// val mode = commandState.mode
|
||||
// if (mode == CommandState.Mode.CMD_LINE) {
|
||||
// VimPlugin.getProcess().cancelExEntry(editor, false)
|
||||
// }
|
||||
// if (mode == CommandState.Mode.INSERT || mode == CommandState.Mode.REPLACE) {
|
||||
// editor.exitInsertMode(context, OperatorArguments(false, 1, commandState.mode, commandState.subMode))
|
||||
// }
|
||||
// }
|
||||
var useMappings = true
|
||||
var argument = argument
|
||||
if (argument.startsWith("!")) {
|
||||
useMappings = false
|
||||
argument = argument.substring(1)
|
||||
}
|
||||
|
||||
val commandState = CommandState.getInstance(editor)
|
||||
val rangeUsed = ranges.size() != 0
|
||||
when (editor.mode) {
|
||||
CommandState.Mode.VISUAL -> {
|
||||
editor.getTopLevelEditor().exitVisualMode()
|
||||
if (!rangeUsed) {
|
||||
val selectionStart = VimPlugin.getMark().getMark(editor, '<')!!
|
||||
editor.caretModel.moveToLogicalPosition(LogicalPosition(selectionStart.logicalLine, selectionStart.col))
|
||||
}
|
||||
}
|
||||
CommandState.Mode.CMD_LINE -> VimPlugin.getProcess().cancelExEntry(editor, false)
|
||||
CommandState.Mode.INSERT, CommandState.Mode.REPLACE -> editor.exitInsertMode(context, OperatorArguments(false, 1, commandState.mode, commandState.subMode))
|
||||
CommandState.Mode.SELECT -> editor.exitSelectMode(false)
|
||||
CommandState.Mode.OP_PENDING, CommandState.Mode.COMMAND -> Unit
|
||||
}
|
||||
val range = getLineRange(editor, editor.caretModel.primaryCaret)
|
||||
|
||||
for (line in range.startLine..range.endLine) {
|
||||
if (rangeUsed) {
|
||||
// Move caret to the first position on line
|
||||
if (editor.document.lineCount < line) {
|
||||
break
|
||||
}
|
||||
val startOffset = EditorHelper.getLineStartOffset(editor, line)
|
||||
editor.caretModel.moveToOffset(startOffset)
|
||||
}
|
||||
|
||||
// Perform operations
|
||||
val keys = stringToKeys(argument)
|
||||
val keyHandler = KeyHandler.getInstance()
|
||||
keyHandler.reset(editor)
|
||||
for (key in keys) {
|
||||
keyHandler.handleKey(editor, key, context, useMappings, true)
|
||||
}
|
||||
|
||||
// Exit if state leaves as insert or cmd_line
|
||||
val mode = commandState.mode
|
||||
if (mode == CommandState.Mode.CMD_LINE) {
|
||||
VimPlugin.getProcess().cancelExEntry(editor, false)
|
||||
}
|
||||
if (mode == CommandState.Mode.INSERT || mode == CommandState.Mode.REPLACE) {
|
||||
editor.exitInsertMode(context, OperatorArguments(false, 1, commandState.mode, commandState.subMode))
|
||||
}
|
||||
}
|
||||
|
||||
return ExecutionResult.Success
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ internal class OptionServiceImpl : OptionService {
|
||||
ToggleOption("timeout", "to", true),
|
||||
ToggleOption("visualbell", "vb", false),
|
||||
ToggleOption("wrapscan", "ws", true),
|
||||
ToggleOption("ideadelaymacro", "ideadelaymacro", true),
|
||||
ToggleOption("ideadelaymacro", "ideadelaymacro", false),
|
||||
StringOption("ide", "ide", ApplicationNamesInfo.getInstance().fullProductNameWithEdition),
|
||||
StringOption("idearefactormode", "idearefactormode", "select", isList = false, ideaRefactorModeValues),
|
||||
StringOption("ideastatusicon", "ideastatusicon", "enabled", isList = false, ideaStatusIconValues),
|
||||
|
Loading…
Reference in New Issue
Block a user