diff --git a/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/VimNavigationDispatcher.kt b/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/VimNavigationDispatcher.kt index bfb3722..52c1dd0 100644 --- a/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/VimNavigationDispatcher.kt +++ b/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/VimNavigationDispatcher.kt @@ -10,6 +10,7 @@ import com.intellij.openapi.actionSystem.KeyboardShortcut import com.intellij.openapi.actionSystem.ex.ActionUtil import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.DumbAwareAction +import com.intellij.openapi.util.SystemInfo import com.intellij.toolWindow.InternalDecoratorImpl import com.intellij.ui.SpeedSearchBase import com.intellij.ui.speedSearch.SpeedSearch @@ -32,6 +33,9 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c @JvmStatic protected val ENTER_KEY: KeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) + private val CTRL_ENTER_KEY: KeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK) + private val META_ENTER_KEY: KeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.META_DOWN_MASK) + private fun findOriginalEnterAction(component: JComponent): WrappedAction { var originalEnterAction: WrappedAction? = null @@ -74,7 +78,7 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c } protected fun getAllKeyStrokes(): Set<KeyStroke> { - return KeyStrokeNode.getAllKeyStrokes(rootNode, setOf(ENTER_KEY)) + return KeyStrokeNode.getAllKeyStrokes(rootNode, setOf(ENTER_KEY, CTRL_ENTER_KEY, META_ENTER_KEY)) } private fun handleSpeedSearchChange(e: PropertyChangeEvent) { @@ -108,19 +112,23 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c } private fun handleEnterKeyPress(actionEvent: AnActionEvent, keyEvent: KeyEvent) { - handleEnterKeyPress { originalEnterAction.perform(actionEvent, keyEvent) } + handleEnterKeyPress(keyEvent) { originalEnterAction.perform(actionEvent, it) } } - protected inline fun handleEnterKeyPress(originalAction: () -> Unit) { - if (isSearching.compareAndSet(true, false)) { + protected inline fun handleEnterKeyPress(keyEvent: KeyEvent, originalAction: (KeyEvent) -> Unit) { + if (isSearching.compareAndSet(true, false) && !runEnterActionImmediately(keyEvent)) { stopSpeedSearch() } else { currentNode = rootNode - originalAction() + originalAction(keyEvent) } } + private fun runEnterActionImmediately(keyEvent: KeyEvent): Boolean { + return if (SystemInfo.isMac) keyEvent.isMetaDown else keyEvent.isControlDown + } + protected open fun stopSpeedSearch() { when (val supply = SpeedSearchSupply.getSupply(component)) { is SpeedSearchBase<*> -> supply.hidePopup() diff --git a/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimListNavigation.kt b/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimListNavigation.kt index a0e9357..f224fde 100644 --- a/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimListNavigation.kt +++ b/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimListNavigation.kt @@ -90,7 +90,7 @@ internal object VimListNavigation { if (popup is ListPopupImpl) { popup.registerAction("KeyboardMaster-VimListNavigation-Enter", ENTER_KEY, object : AbstractAction() { override fun actionPerformed(e: ActionEvent) { - handleEnterKeyPress { popup.handleSelect(true, createEnterEvent(e)) } + handleEnterKeyPress(createEnterEvent(e)) { popup.handleSelect(true, it) } } private fun createEnterEvent(e: ActionEvent): KeyEvent {