mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-06 03:34:03 +02:00
Add an editor to the action executor
This commit is contained in:
parent
27be351636
commit
42eefb763b
src/main/java/com/maddyhome/idea/vim
extension/nerdtree
group
helper
newapi
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
action
motion
window
api
vimscript/model/commands
@ -137,7 +137,7 @@ class NerdTree : VimExtension {
|
||||
|
||||
class IjCommandHandler(private val actionId: String) : CommandAliasHandler {
|
||||
override fun execute(command: String, ranges: Ranges, editor: VimEditor, context: ExecutionContext) {
|
||||
callAction(actionId, context)
|
||||
callAction(editor, actionId, context)
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ class NerdTree : VimExtension {
|
||||
if (toolWindow.isVisible) {
|
||||
toolWindow.hide()
|
||||
} else {
|
||||
callAction("ActivateProjectToolWindow", context)
|
||||
callAction(editor, "ActivateProjectToolWindow", context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -210,7 +210,7 @@ class NerdTree : VimExtension {
|
||||
|
||||
val action = nextNode.actionHolder
|
||||
when (action) {
|
||||
is NerdAction.ToIj -> callAction(action.name, e.dataContext.vim)
|
||||
is NerdAction.ToIj -> callAction(null, action.name, e.dataContext.vim)
|
||||
is NerdAction.Code -> e.project?.let { action.action(it, e.dataContext, e) }
|
||||
}
|
||||
}
|
||||
@ -348,7 +348,7 @@ class NerdTree : VimExtension {
|
||||
currentWindow?.split(SwingConstants.VERTICAL, true, file, true)
|
||||
|
||||
// FIXME: 22.01.2021 This solution bouncing a bit
|
||||
callAction("ActivateProjectToolWindow", context.vim)
|
||||
callAction(null, "ActivateProjectToolWindow", context.vim)
|
||||
}
|
||||
)
|
||||
registerCommand(
|
||||
@ -359,7 +359,7 @@ class NerdTree : VimExtension {
|
||||
val currentWindow = splitters.currentWindow
|
||||
currentWindow?.split(SwingConstants.HORIZONTAL, true, file, true)
|
||||
|
||||
callAction("ActivateProjectToolWindow", context.vim)
|
||||
callAction(null, "ActivateProjectToolWindow", context.vim)
|
||||
}
|
||||
)
|
||||
registerCommand(
|
||||
@ -497,20 +497,17 @@ class NerdTree : VimExtension {
|
||||
|
||||
private val LOG = logger<NerdTree>()
|
||||
|
||||
fun callAction(name: String, context: ExecutionContext) {
|
||||
fun callAction(editor: VimEditor?, name: String, context: ExecutionContext) {
|
||||
val action = ActionManager.getInstance().getAction(name) ?: run {
|
||||
VimPlugin.showMessage(MessageHelper.message("action.not.found.0", name))
|
||||
return
|
||||
}
|
||||
val application = ApplicationManager.getApplication()
|
||||
if (application.isUnitTestMode) {
|
||||
injector.actionExecutor.executeAction(action.vim, context)
|
||||
injector.actionExecutor.executeAction(editor, action.vim, context)
|
||||
} else {
|
||||
runAfterGotFocus {
|
||||
injector.actionExecutor.executeAction(
|
||||
action.vim,
|
||||
context,
|
||||
)
|
||||
injector.actionExecutor.executeAction(editor, action.vim, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ public class ChangeGroup extends VimChangeGroupBase {
|
||||
Function0<Unit> actionExecution = () -> {
|
||||
NativeAction joinLinesAction = VimInjectorKt.getInjector().getNativeActionManager().getIndentLines();
|
||||
if (joinLinesAction != null) {
|
||||
VimInjectorKt.getInjector().getActionExecutor().executeAction(joinLinesAction, context);
|
||||
VimInjectorKt.getInjector().getActionExecutor().executeAction(editor, joinLinesAction, context);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ class IjActionExecutor : VimActionExecutor {
|
||||
* @param ijAction The action to execute
|
||||
* @param context The context to run it in
|
||||
*/
|
||||
override fun executeAction(action: NativeAction, context: ExecutionContext): Boolean {
|
||||
override fun executeAction(editor: VimEditor?, action: NativeAction, context: ExecutionContext): Boolean {
|
||||
val ijAction = (action as IjNativeAction).action
|
||||
val event = AnActionEvent(
|
||||
null, context.ij, ActionPlaces.KEYBOARD_SHORTCUT, ijAction.templatePresentation.clone(),
|
||||
@ -138,7 +138,7 @@ class IjActionExecutor : VimActionExecutor {
|
||||
override fun executeAction(name: @NonNls String, context: ExecutionContext): Boolean {
|
||||
val aMgr = ActionManager.getInstance()
|
||||
val action = aMgr.getAction(name)
|
||||
return action != null && executeAction(IjNativeAction(action), context)
|
||||
return action != null && executeAction(null, IjNativeAction(action), context)
|
||||
}
|
||||
|
||||
override fun executeCommand(
|
||||
|
@ -16,7 +16,7 @@ import com.maddyhome.idea.vim.api.injector
|
||||
|
||||
fun NativeAction?.execute(context: ExecutionContext) {
|
||||
if (this == null) return
|
||||
injector.actionExecutor.executeAction(this, context)
|
||||
injector.actionExecutor.executeAction(null, this, context)
|
||||
}
|
||||
|
||||
val VisualPosition.vim: VimVisualPosition
|
||||
|
@ -34,7 +34,7 @@ class CtrlDownAction : VimActionHandler.SingleExecution() {
|
||||
val keyStroke = keySet.first().first()
|
||||
val actions = injector.keyGroup.getKeymapConflicts(keyStroke)
|
||||
for (action in actions) {
|
||||
if (injector.actionExecutor.executeAction(action, context)) break
|
||||
if (injector.actionExecutor.executeAction(editor, action, context)) break
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -55,7 +55,7 @@ class CtrlUpAction : VimActionHandler.SingleExecution() {
|
||||
val keyStroke = keySet.first().first()
|
||||
val actions = injector.keyGroup.getKeymapConflicts(keyStroke)
|
||||
for (action in actions) {
|
||||
if (injector.actionExecutor.executeAction(action, context)) break
|
||||
if (injector.actionExecutor.executeAction(editor, action, context)) break
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class SelectDeleteAction : VimActionHandler.SingleExecution() {
|
||||
val enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0)
|
||||
val actions = injector.keyGroup.getActions(editor, enterKeyStroke)
|
||||
for (action in actions) {
|
||||
if (injector.actionExecutor.executeAction(action, context)) {
|
||||
if (injector.actionExecutor.executeAction(editor, action, context)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class LookupDownAction : VimActionHandler.SingleExecution() {
|
||||
val keyStroke = keySet.first().first()
|
||||
val actions = injector.keyGroup.getKeymapConflicts(keyStroke)
|
||||
for (action in actions) {
|
||||
if (injector.actionExecutor.executeAction(action, context)) break
|
||||
if (injector.actionExecutor.executeAction(editor, action, context)) break
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
@ -37,7 +37,7 @@ class LookupUpAction : VimActionHandler.SingleExecution() {
|
||||
val keyStroke = keySet.first().first()
|
||||
val actions = injector.keyGroup.getKeymapConflicts(keyStroke)
|
||||
for (action in actions) {
|
||||
if (injector.actionExecutor.executeAction(action, context)) break
|
||||
if (injector.actionExecutor.executeAction(editor, action, context)) break
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
@ -27,7 +27,7 @@ interface VimActionExecutor {
|
||||
* @param action The action to execute
|
||||
* @param context The context to run it in
|
||||
*/
|
||||
fun executeAction(action: NativeAction, context: ExecutionContext): Boolean
|
||||
fun executeAction(editor: VimEditor?, action: NativeAction, context: ExecutionContext): Boolean
|
||||
|
||||
/**
|
||||
* Execute an action by name
|
||||
|
@ -231,7 +231,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
for (lastStroke in myLastStrokes) {
|
||||
when (lastStroke) {
|
||||
is NativeAction -> {
|
||||
injector.actionExecutor.executeAction(lastStroke, context)
|
||||
injector.actionExecutor.executeAction(editor, lastStroke, context)
|
||||
strokes.add(lastStroke)
|
||||
}
|
||||
|
||||
@ -478,7 +478,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
val action = injector.nativeActionManager.enterAction
|
||||
if (action != null) {
|
||||
strokes.add(action)
|
||||
injector.actionExecutor.executeAction(action, context)
|
||||
injector.actionExecutor.executeAction(editor, action, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -490,7 +490,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
val action = injector.nativeActionManager.createLineAboveCaret
|
||||
if (action != null) {
|
||||
strokes.add(action)
|
||||
injector.actionExecutor.executeAction(action, context)
|
||||
injector.actionExecutor.executeAction(editor, action, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -590,7 +590,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
val enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)
|
||||
val actions = injector.keyGroup.getActions(editor, enterKeyStroke)
|
||||
for (action in actions) {
|
||||
if (injector.actionExecutor.executeAction(action, context)) {
|
||||
if (injector.actionExecutor.executeAction(editor, action, context)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -796,7 +796,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
for (i in 0 until executions) {
|
||||
val joinLinesAction = injector.nativeActionManager.joinLines
|
||||
if (joinLinesAction != null) {
|
||||
injector.actionExecutor.executeAction(joinLinesAction, context)
|
||||
injector.actionExecutor.executeAction(editor, joinLinesAction, context)
|
||||
}
|
||||
}
|
||||
return true
|
||||
@ -841,7 +841,7 @@ abstract class VimChangeGroupBase : VimChangeGroup {
|
||||
}
|
||||
val joinLinesAction = injector.nativeActionManager.joinLines
|
||||
if (joinLinesAction != null) {
|
||||
injector.actionExecutor.executeAction(joinLinesAction, context)
|
||||
injector.actionExecutor.executeAction(editor, joinLinesAction, context)
|
||||
}
|
||||
editor.nativeCarets().forEach { caret: VimCaret ->
|
||||
caret.removeSelection()
|
||||
|
@ -33,14 +33,14 @@ data class ActionCommand(val ranges: Ranges, val argument: String) : Command.Sin
|
||||
val actionName = argument.trim()
|
||||
val action = injector.actionExecutor.getAction(actionName) ?: throw ExException(injector.messages.message("action.not.found.0", actionName))
|
||||
if (injector.application.isUnitTest()) {
|
||||
executeAction(action, context)
|
||||
executeAction(editor, action, context)
|
||||
} else {
|
||||
injector.application.runAfterGotFocus { executeAction(action, context) }
|
||||
injector.application.runAfterGotFocus { executeAction(editor, action, context) }
|
||||
}
|
||||
return ExecutionResult.Success
|
||||
}
|
||||
|
||||
private fun executeAction(action: NativeAction, context: ExecutionContext) {
|
||||
injector.actionExecutor.executeAction(action, context)
|
||||
private fun executeAction(editor: VimEditor, action: NativeAction, context: ExecutionContext) {
|
||||
injector.actionExecutor.executeAction(editor, action, context)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user