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. "723b8af9392af050f74aa6c579fcbc0e2f31b0d9" and "d76e259c255d3a2eb84db811411b1a2ad9c284ff" have entirely different histories.
723b8af939
...
d76e259c25
@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.chylex.intellij.keyboardmaster"
|
group = "com.chylex.intellij.keyboardmaster"
|
||||||
version = "0.5.7"
|
version = "0.5.6"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -8,12 +8,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent
|
|||||||
import com.intellij.openapi.ui.getUserData
|
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.ClientProperty
|
|
||||||
import com.intellij.ui.tree.ui.DefaultTreeUI
|
|
||||||
import java.awt.event.KeyEvent
|
import java.awt.event.KeyEvent
|
||||||
import javax.swing.JTree
|
import javax.swing.JTree
|
||||||
import javax.swing.KeyStroke
|
import javax.swing.KeyStroke
|
||||||
import javax.swing.tree.TreePath
|
|
||||||
|
|
||||||
internal object VimTreeNavigation {
|
internal object VimTreeNavigation {
|
||||||
private val KEY = Key.create<VimNavigationDispatcher<JTree>>("KeyboardMaster-VimTreeNavigation")
|
private val KEY = Key.create<VimNavigationDispatcher<JTree>>("KeyboardMaster-VimTreeNavigation")
|
||||||
@ -25,7 +22,6 @@ internal object VimTreeNavigation {
|
|||||||
KeyStroke.getKeyStroke('g') to IdeaAction("Tree-selectFirst"),
|
KeyStroke.getKeyStroke('g') to IdeaAction("Tree-selectFirst"),
|
||||||
KeyStroke.getKeyStroke('j') to SelectLastSibling,
|
KeyStroke.getKeyStroke('j') to SelectLastSibling,
|
||||||
KeyStroke.getKeyStroke('k') to SelectFirstSibling,
|
KeyStroke.getKeyStroke('k') to SelectFirstSibling,
|
||||||
KeyStroke.getKeyStroke('o') to ExpandTreeNodeChildrenToNextLevel,
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
KeyStroke.getKeyStroke('G') to IdeaAction("Tree-selectLast"),
|
KeyStroke.getKeyStroke('G') to IdeaAction("Tree-selectLast"),
|
||||||
@ -81,48 +77,6 @@ internal object VimTreeNavigation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data object ExpandTreeNodeChildrenToNextLevel : ActionNode<VimNavigationDispatcher<JTree>> {
|
|
||||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
|
||||||
val tree = holder.component
|
|
||||||
val model = tree.model
|
|
||||||
val path = tree.selectionPath?.takeUnless { model.isLeaf(it.lastPathComponent) } ?: return
|
|
||||||
|
|
||||||
var pathsToExpand = mutableListOf(path)
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (pathsToExpand.any(tree::isCollapsed)) {
|
|
||||||
runWithoutAutoExpand(tree) { pathsToExpand.forEach(tree::expandPath) }
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
val nextPathsToExpand = mutableListOf<TreePath>()
|
|
||||||
|
|
||||||
for (parentPath in pathsToExpand) {
|
|
||||||
val lastPathComponent = parentPath.lastPathComponent
|
|
||||||
|
|
||||||
for (i in 0 until model.getChildCount(lastPathComponent)) {
|
|
||||||
val child = model.getChild(lastPathComponent, i)
|
|
||||||
if (!model.isLeaf(child)) {
|
|
||||||
nextPathsToExpand.add(parentPath.pathByAddingChild(child))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pathsToExpand = nextPathsToExpand
|
|
||||||
} while (pathsToExpand.isNotEmpty())
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun runWithoutAutoExpand(tree: JTree, action: () -> Unit) {
|
|
||||||
val previousAutoExpandValue = ClientProperty.get(tree, DefaultTreeUI.AUTO_EXPAND_ALLOWED)
|
|
||||||
ClientProperty.put(tree, DefaultTreeUI.AUTO_EXPAND_ALLOWED, false)
|
|
||||||
try {
|
|
||||||
action()
|
|
||||||
} finally {
|
|
||||||
ClientProperty.put(tree, DefaultTreeUI.AUTO_EXPAND_ALLOWED, previousAutoExpandValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private data object SelectFirstSibling : ActionNode<VimNavigationDispatcher<JTree>> {
|
private data object SelectFirstSibling : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||||
val tree = holder.component
|
val tree = holder.component
|
||||||
|
Loading…
Reference in New Issue
Block a user