mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2025-04-28 07:15:44 +02:00
Make vim-style navigation Enter handling during search in popups consistent with other components
This commit is contained in:
parent
0e2928a737
commit
844738794b
src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation
@ -28,7 +28,9 @@ import javax.swing.KeyStroke
|
|||||||
internal open class VimNavigationDispatcher<T : JComponent>(final override val component: T, private val rootNode: KeyStrokeNode.Parent<VimNavigationDispatcher<T>>) : DumbAwareAction(), ComponentHolder {
|
internal open class VimNavigationDispatcher<T : JComponent>(final override val component: T, private val rootNode: KeyStrokeNode.Parent<VimNavigationDispatcher<T>>) : DumbAwareAction(), ComponentHolder {
|
||||||
companion object {
|
companion object {
|
||||||
private val DISPOSABLE = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
|
private val DISPOSABLE = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
|
||||||
private val ENTER_KEY = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)
|
|
||||||
|
@JvmStatic
|
||||||
|
protected val ENTER_KEY: KeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)
|
||||||
|
|
||||||
private fun findOriginalEnterAction(component: JComponent): WrappedAction {
|
private fun findOriginalEnterAction(component: JComponent): WrappedAction {
|
||||||
var originalEnterAction: WrappedAction? = null
|
var originalEnterAction: WrappedAction? = null
|
||||||
@ -106,15 +108,23 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleEnterKeyPress(actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
private fun handleEnterKeyPress(actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||||
|
handleEnterKeyPress { originalEnterAction.perform(actionEvent, keyEvent) }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun handleEnterKeyPress(originalAction: () -> Unit) {
|
||||||
if (isSearching.compareAndSet(true, false)) {
|
if (isSearching.compareAndSet(true, false)) {
|
||||||
when (val supply = SpeedSearchSupply.getSupply(component)) {
|
stopSpeedSearch()
|
||||||
is SpeedSearchBase<*> -> supply.hidePopup()
|
|
||||||
is SpeedSearch -> supply.reset()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentNode = rootNode
|
currentNode = rootNode
|
||||||
originalEnterAction.perform(actionEvent, keyEvent)
|
originalAction()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun stopSpeedSearch() {
|
||||||
|
when (val supply = SpeedSearchSupply.getSupply(component)) {
|
||||||
|
is SpeedSearchBase<*> -> supply.hidePopup()
|
||||||
|
is SpeedSearch -> supply.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.intellij.openapi.ui.getUserData
|
|||||||
import com.intellij.openapi.ui.putUserData
|
import com.intellij.openapi.ui.putUserData
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.ui.popup.WizardPopup
|
import com.intellij.ui.popup.WizardPopup
|
||||||
|
import com.intellij.ui.popup.list.ListPopupImpl
|
||||||
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.ActionEvent
|
||||||
@ -85,6 +86,24 @@ internal object VimListNavigation {
|
|||||||
// WizardPopup only checks key codes against its input map, but key codes may be undefined for some characters.
|
// WizardPopup only checks key codes against its input map, but key codes may be undefined for some characters.
|
||||||
popup.registerAction("KeyboardMaster-VimListNavigation-PauseSpeedSearch", KeyStroke.getKeyStroke(KeyEvent.CHAR_UNDEFINED, 0), pauseAction)
|
popup.registerAction("KeyboardMaster-VimListNavigation-PauseSpeedSearch", KeyStroke.getKeyStroke(KeyEvent.CHAR_UNDEFINED, 0), pauseAction)
|
||||||
popup.registerAction("KeyboardMaster-VimListNavigation-PauseSpeedSearch", KeyStroke.getKeyStroke(KeyEvent.CHAR_UNDEFINED, KeyEvent.SHIFT_DOWN_MASK), pauseAction)
|
popup.registerAction("KeyboardMaster-VimListNavigation-PauseSpeedSearch", KeyStroke.getKeyStroke(KeyEvent.CHAR_UNDEFINED, KeyEvent.SHIFT_DOWN_MASK), pauseAction)
|
||||||
|
|
||||||
|
if (popup is ListPopupImpl) {
|
||||||
|
popup.registerAction("KeyboardMaster-VimListNavigation-Enter", ENTER_KEY, object : AbstractAction() {
|
||||||
|
override fun actionPerformed(e: ActionEvent) {
|
||||||
|
handleEnterKeyPress { popup.handleSelect(true, createEnterEvent(e)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createEnterEvent(e: ActionEvent): KeyEvent {
|
||||||
|
return KeyEvent(component, KeyEvent.KEY_PRESSED, e.`when`, e.modifiers, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stopSpeedSearch() {
|
||||||
|
val selectedValue = component.selectedValue
|
||||||
|
super.stopSpeedSearch()
|
||||||
|
component.setSelectedValue(selectedValue, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PauseSpeedSearchAction(private val dispatcher: VimNavigationDispatcher<JList<*>>, private val speedSearch: SpeedSearch) : AbstractAction() {
|
private class PauseSpeedSearchAction(private val dispatcher: VimNavigationDispatcher<JList<*>>, private val speedSearch: SpeedSearch) : AbstractAction() {
|
||||||
|
Loading…
Reference in New Issue
Block a user