1
0
mirror of https://github.com/chylex/IntelliJ-Keyboard-Master.git synced 2024-11-25 01:42:47 +01:00

Compare commits

..

No commits in common. "215049bf26c79b4381612719f1f2dd7fc036f4c4" and "381db0e664ff2b9cb83b52070459b2ee7c950728" have entirely different histories.

2 changed files with 13 additions and 10 deletions

View File

@ -8,7 +8,7 @@ plugins {
} }
group = "com.chylex.intellij.keyboardmaster" group = "com.chylex.intellij.keyboardmaster"
version = "0.5.1" version = "0.5.0"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -3,14 +3,15 @@ package com.chylex.intellij.keyboardmaster.feature.vimNavigation
import com.chylex.intellij.keyboardmaster.PluginDisposableService import com.chylex.intellij.keyboardmaster.PluginDisposableService
import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.DumbAwareAction
import com.intellij.pom.Navigatable
import com.intellij.toolWindow.InternalDecoratorImpl import com.intellij.toolWindow.InternalDecoratorImpl
import com.intellij.ui.SpeedSearchBase import com.intellij.ui.SpeedSearchBase
import com.intellij.ui.speedSearch.SpeedSearch import com.intellij.ui.speedSearch.SpeedSearch
import com.intellij.ui.speedSearch.SpeedSearchSupply import com.intellij.ui.speedSearch.SpeedSearchSupply
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.KeyEvent import java.awt.event.KeyEvent
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import javax.swing.JComponent import javax.swing.JComponent
@ -21,7 +22,7 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
private val DISPOSABLE = ApplicationManager.getApplication().getService(PluginDisposableService::class.java) private val DISPOSABLE = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
private val EXTRA_SHORTCUTS = setOf( private val EXTRA_SHORTCUTS = setOf(
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
) )
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
@ -30,7 +31,6 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
} }
} }
private val originalEnterAction: ActionListener? = component.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))
private var currentNode: KeyStrokeNode.Parent<VimNavigationDispatcher<T>> = rootNode private var currentNode: KeyStrokeNode.Parent<VimNavigationDispatcher<T>> = rootNode
var isSearching = AtomicBoolean(false) var isSearching = AtomicBoolean(false)
@ -52,7 +52,7 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
final override fun actionPerformed(e: AnActionEvent) { final override fun actionPerformed(e: AnActionEvent) {
val keyEvent = e.inputEvent as? KeyEvent ?: return val keyEvent = e.inputEvent as? KeyEvent ?: return
if (keyEvent.id == KeyEvent.KEY_PRESSED && handleSpecialKeyPress(keyEvent)) { if (keyEvent.id == KeyEvent.KEY_PRESSED && handleSpecialKeyPress(keyEvent, e.dataContext)) {
currentNode = rootNode currentNode = rootNode
return return
} }
@ -66,20 +66,20 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
} }
} }
private fun handleSpecialKeyPress(keyEvent: KeyEvent): Boolean { private fun handleSpecialKeyPress(keyEvent: KeyEvent, dataContext: DataContext): Boolean {
if (keyEvent.keyCode == KeyEvent.VK_ESCAPE) { if (keyEvent.keyCode == KeyEvent.VK_ESCAPE) {
return true return true
} }
if (keyEvent.keyCode == KeyEvent.VK_ENTER) { if (keyEvent.keyCode == KeyEvent.VK_ENTER) {
handleEnterKeyPress(ActionEvent(component, ActionEvent.ACTION_PERFORMED, "Enter", keyEvent.`when`, keyEvent.modifiersEx)) handleEnterKeyPress(dataContext)
return true return true
} }
return false return false
} }
private fun handleEnterKeyPress(e: ActionEvent) { private fun handleEnterKeyPress(dataContext: DataContext) {
if (isSearching.compareAndSet(true, false)) { if (isSearching.compareAndSet(true, false)) {
when (val supply = SpeedSearchSupply.getSupply(component)) { when (val supply = SpeedSearchSupply.getSupply(component)) {
is SpeedSearchBase<*> -> supply.hidePopup() is SpeedSearchBase<*> -> supply.hidePopup()
@ -87,7 +87,10 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
} }
} }
else { else {
originalEnterAction?.actionPerformed(e) val navigatables = dataContext.getData(CommonDataKeys.NAVIGATABLE_ARRAY)?.filter(Navigatable::canNavigate).orEmpty()
for ((index, navigatable) in navigatables.withIndex()) {
navigatable.navigate(index == navigatables.lastIndex)
}
} }
} }