1
0
mirror of https://github.com/chylex/IntelliJ-Keyboard-Master.git synced 2025-04-23 02:15:42 +02:00

Add additional vim-style bindings for navigating submenus

This commit is contained in:
chylex 2024-05-06 22:50:45 +02:00
parent 6931387370
commit e6ab49cb16
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
2 changed files with 21 additions and 15 deletions
src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation

View File

@ -38,20 +38,11 @@ object VimNavigation {
val originalBindings = (UIManager.get("PopupMenu.selectedWindowInputMapBindings") as Array<*>).also { originalPopupBindings = it }
val updatedBindings = mutableListOf(*originalBindings)
updatedBindings.add(KeyStroke.getKeyStroke('h'))
updatedBindings.add("selectParent")
updatedBindings.add(KeyStroke.getKeyStroke('j'))
updatedBindings.add("selectNext")
updatedBindings.add(KeyStroke.getKeyStroke('k'))
updatedBindings.add("selectPrevious")
updatedBindings.add(KeyStroke.getKeyStroke('l'))
updatedBindings.add("selectChild")
updatedBindings.add(KeyStroke.getKeyStroke('q'))
updatedBindings.add("cancel")
addBinding(updatedBindings, "selectParent", setOf('h', 'p', 'x'))
addBinding(updatedBindings, "selectNext", setOf('j'))
addBinding(updatedBindings, "selectPrevious", setOf('k'))
addBinding(updatedBindings, "selectChild", setOf('l', 'o'))
addBinding(updatedBindings, "cancel", setOf('q'))
UIManager.put("PopupMenu.selectedWindowInputMapBindings", updatedBindings.toTypedArray())
UISettings.getInstance().disableMnemonics = true
@ -62,6 +53,13 @@ object VimNavigation {
}
}
private fun addBinding(bindings: MutableList<Any?>, action: String, chars: Set<Char>) {
for (char in chars) {
bindings.add(KeyStroke.getKeyStroke(char))
bindings.add(action)
}
}
private fun handleEvent(event: AWTEvent) {
if (event is FocusEvent && event.id == FocusEvent.FOCUS_GAINED && isEnabled.get()) {
when (val source = event.source) {

View File

@ -34,6 +34,14 @@ internal object VimListNavigation {
)
)
private val POPUP_LIST_ROOT_NODE = ROOT_NODE + Parent(
mapOf(
KeyStroke.getKeyStroke('o') to IdeaAction("List-selectNextColumn"),
KeyStroke.getKeyStroke('p') to IdeaAction("List-selectPreviousColumn"),
KeyStroke.getKeyStroke('x') to IdeaAction("List-selectPreviousColumn"),
)
)
fun install(component: JList<*>) {
if (component.getUserData(KEY) == null && component.javaClass.enclosingClass.let { it == null || !WizardPopup::class.java.isAssignableFrom(it) }) {
component.putUserData(KEY, VimNavigationDispatcher(component, ROOT_NODE))
@ -47,7 +55,7 @@ internal object VimListNavigation {
}
@Suppress("serial")
private class VimPopupListNavigationDispatcher(component: JList<*>, override val popup: WizardPopup) : VimNavigationDispatcher<JList<*>>(component, ROOT_NODE) {
private class VimPopupListNavigationDispatcher(component: JList<*>, override val popup: WizardPopup) : VimNavigationDispatcher<JList<*>>(component, POPUP_LIST_ROOT_NODE) {
init {
val speedSearch = SpeedSearchSupply.getSupply(component, true) as? SpeedSearch
if (speedSearch != null) {