mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-04-22 19:15:46 +02:00
Add action to run last macro in all opened files
This commit is contained in:
parent
144cc5c3fc
commit
69c748d881
src/main
java/com/maddyhome/idea/vim
resources/META-INF
@ -0,0 +1,52 @@
|
||||
package com.maddyhome.idea.vim.action
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.fileEditor.TextEditor
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.state.mode.Mode
|
||||
|
||||
class VimRunLastMacroInOpenFiles : DumbAwareAction() {
|
||||
override fun update(e: AnActionEvent) {
|
||||
val lastRegister = injector.macro.lastRegister
|
||||
val isEnabled = lastRegister != 0.toChar()
|
||||
|
||||
e.presentation.isEnabled = isEnabled
|
||||
e.presentation.text = if (isEnabled) "Run Macro '${lastRegister}' in Open Files" else "Run Last Macro in Open Files"
|
||||
}
|
||||
|
||||
override fun getActionUpdateThread(): ActionUpdateThread {
|
||||
return ActionUpdateThread.EDT
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = e.project ?: return
|
||||
val fileEditorManager = FileEditorManagerEx.getInstanceExIfCreated(project) ?: return
|
||||
val editors = fileEditorManager.allEditors.filterIsInstance<TextEditor>()
|
||||
|
||||
WriteCommandAction.writeCommandAction(project)
|
||||
.withName(e.presentation.text)
|
||||
.withGlobalUndo()
|
||||
.withUndoConfirmationPolicy(UndoConfirmationPolicy.REQUEST_CONFIRMATION)
|
||||
.run<RuntimeException> {
|
||||
val reg = injector.macro.lastRegister
|
||||
|
||||
for (editor in editors) {
|
||||
fileEditorManager.openFile(editor.file, true)
|
||||
|
||||
val vimEditor = editor.editor.vim
|
||||
vimEditor.mode = Mode.NORMAL()
|
||||
KeyHandler.getInstance().reset(vimEditor)
|
||||
|
||||
injector.macro.playbackRegister(vimEditor, IjEditorExecutionContext(e.dataContext), reg, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -353,7 +353,7 @@ public class ExEntryPanel extends JPanel implements VimCommandLine {
|
||||
int count1 = Math.max(1, KeyHandler.getInstance().getKeyHandlerState().getEditorCommandBuilder()
|
||||
.calculateCount0Snapshot());
|
||||
|
||||
if (labelText.equals("/") || labelText.equals("?") || searchCommand) {
|
||||
if ((labelText.equals("/") || labelText.equals("?") || searchCommand) && !injector.getMacro().isExecutingMacro()) {
|
||||
final boolean forwards = !labelText.equals("?"); // :s, :g, :v are treated as forwards
|
||||
int patternEnd = injector.getSearchGroup().findEndOfPattern(searchText, separator, 0);
|
||||
final String pattern = searchText.substring(0, patternEnd);
|
||||
|
@ -139,10 +139,12 @@
|
||||
<xi:include href="/META-INF/includes/VimListeners.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<actions resource-bundle="messages.IdeaVimBundle">
|
||||
<action id="VimPluginToggle" class="com.maddyhome.idea.vim.action.VimPluginToggleAction">
|
||||
<group id="com.chylex.intellij.vim" text="Vim" popup="true">
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<action id="VimPluginToggle" class="com.maddyhome.idea.vim.action.VimPluginToggleAction"/>
|
||||
<action id="VimRunLastMacroInOpenFiles" class="com.maddyhome.idea.vim.action.VimRunLastMacroInOpenFiles"/>
|
||||
</group>
|
||||
|
||||
<!-- Internal -->
|
||||
<!--suppress PluginXmlI18n -->
|
||||
<action id="VimInternalAddBlockInlays" class="com.maddyhome.idea.vim.action.internal.AddBlockInlaysAction" text="Add Test Block Inlays | IdeaVim Internal" internal="true"/>
|
||||
|
Loading…
Reference in New Issue
Block a user