Skip to content

Commit

Permalink
Fix(VIM-1611): actions related to resolving conflicts doesn't seem to…
Browse files Browse the repository at this point in the history
… work
  • Loading branch information
lippfi committed Nov 17, 2023
1 parent 87ceb8f commit b1323c0
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/helper/IjActionExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.AnActionResult
import com.intellij.openapi.actionSystem.DataContextWrapper
import com.intellij.openapi.actionSystem.EmptyAction
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.actionSystem.ex.ActionManagerEx
import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.command.UndoConfirmationPolicy
import com.intellij.openapi.components.Service
Expand All @@ -39,6 +41,8 @@ import com.maddyhome.idea.vim.newapi.IjNativeAction
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.runFromVimKey
import org.jetbrains.annotations.NonNls
import java.awt.Component
import javax.swing.JComponent
import javax.swing.SwingUtilities

@Service
Expand Down Expand Up @@ -150,10 +154,43 @@ internal class IjActionExecutor : VimActionExecutor {
* @param context The context to run it in
*/
override fun executeAction(name: @NonNls String, context: ExecutionContext): Boolean {
val aMgr = ActionManager.getInstance()
val action = aMgr.getAction(name)
val action = getAction(name, context)
return action != null && executeAction(null, IjNativeAction(action), context)
}

private fun getAction(name: String, context: ExecutionContext): AnAction? {
val actionManager = ActionManager.getInstance()
val action = actionManager.getAction(name)
if (action !is EmptyAction) return action

// But if the action is an instance of EmptyAction, the fun begins
var component: Component? = context.ij.getData(PlatformDataKeys.CONTEXT_COMPONENT) ?: return null
while (component != null) {
if (component !is JComponent) {
component = component.parent
continue
}

val listOfActions = ActionUtil.getActions(component)
if (listOfActions.isEmpty()) {
component = component.getParent()
continue
}

fun AnAction.getId(): String? {
return actionManager.getId(this)
?: (shortcutSet as? ProxyShortcutSet)?.actionId
}

for (action in listOfActions) {
if (action.getId() == name) {
return action
}
}
component = component.getParent()
}
return null
}

override fun executeCommand(
editor: VimEditor?,
Expand Down

0 comments on commit b1323c0

Please sign in to comment.