mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2025-05-02 02:34:06 +02:00
Add additional vim-style bindings for navigating submenus
This commit is contained in:
parent
6931387370
commit
e6ab49cb16
src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation
@ -38,20 +38,11 @@ object VimNavigation {
|
|||||||
val originalBindings = (UIManager.get("PopupMenu.selectedWindowInputMapBindings") as Array<*>).also { originalPopupBindings = it }
|
val originalBindings = (UIManager.get("PopupMenu.selectedWindowInputMapBindings") as Array<*>).also { originalPopupBindings = it }
|
||||||
val updatedBindings = mutableListOf(*originalBindings)
|
val updatedBindings = mutableListOf(*originalBindings)
|
||||||
|
|
||||||
updatedBindings.add(KeyStroke.getKeyStroke('h'))
|
addBinding(updatedBindings, "selectParent", setOf('h', 'p', 'x'))
|
||||||
updatedBindings.add("selectParent")
|
addBinding(updatedBindings, "selectNext", setOf('j'))
|
||||||
|
addBinding(updatedBindings, "selectPrevious", setOf('k'))
|
||||||
updatedBindings.add(KeyStroke.getKeyStroke('j'))
|
addBinding(updatedBindings, "selectChild", setOf('l', 'o'))
|
||||||
updatedBindings.add("selectNext")
|
addBinding(updatedBindings, "cancel", setOf('q'))
|
||||||
|
|
||||||
updatedBindings.add(KeyStroke.getKeyStroke('k'))
|
|
||||||
updatedBindings.add("selectPrevious")
|
|
||||||
|
|
||||||
updatedBindings.add(KeyStroke.getKeyStroke('l'))
|
|
||||||
updatedBindings.add("selectChild")
|
|
||||||
|
|
||||||
updatedBindings.add(KeyStroke.getKeyStroke('q'))
|
|
||||||
updatedBindings.add("cancel")
|
|
||||||
|
|
||||||
UIManager.put("PopupMenu.selectedWindowInputMapBindings", updatedBindings.toTypedArray())
|
UIManager.put("PopupMenu.selectedWindowInputMapBindings", updatedBindings.toTypedArray())
|
||||||
UISettings.getInstance().disableMnemonics = true
|
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) {
|
private fun handleEvent(event: AWTEvent) {
|
||||||
if (event is FocusEvent && event.id == FocusEvent.FOCUS_GAINED && isEnabled.get()) {
|
if (event is FocusEvent && event.id == FocusEvent.FOCUS_GAINED && isEnabled.get()) {
|
||||||
when (val source = event.source) {
|
when (val source = event.source) {
|
||||||
|
@ -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<*>) {
|
fun install(component: JList<*>) {
|
||||||
if (component.getUserData(KEY) == null && component.javaClass.enclosingClass.let { it == null || !WizardPopup::class.java.isAssignableFrom(it) }) {
|
if (component.getUserData(KEY) == null && component.javaClass.enclosingClass.let { it == null || !WizardPopup::class.java.isAssignableFrom(it) }) {
|
||||||
component.putUserData(KEY, VimNavigationDispatcher(component, ROOT_NODE))
|
component.putUserData(KEY, VimNavigationDispatcher(component, ROOT_NODE))
|
||||||
@ -47,7 +55,7 @@ internal object VimListNavigation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("serial")
|
@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 {
|
init {
|
||||||
val speedSearch = SpeedSearchSupply.getSupply(component, true) as? SpeedSearch
|
val speedSearch = SpeedSearchSupply.getSupply(component, true) as? SpeedSearch
|
||||||
if (speedSearch != null) {
|
if (speedSearch != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user