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. "38c80a7b277cc59ad9d995687b59e8023a6349e2" and "f814ec04bd711174445f3ae3bcd560cbecb2e6a4" have entirely different histories.
38c80a7b27
...
f814ec04bd
@ -25,26 +25,22 @@ internal object VimTreeNavigation {
|
||||
KeyStroke.getKeyStroke('g') to IdeaAction("Tree-selectFirst"),
|
||||
KeyStroke.getKeyStroke('j') to SelectLastSibling,
|
||||
KeyStroke.getKeyStroke('k') to SelectFirstSibling,
|
||||
KeyStroke.getKeyStroke('o') to ExpandChildrenToNextLevel,
|
||||
KeyStroke.getKeyStroke('o') to ExpandTreeNodeChildrenToNextLevel,
|
||||
)
|
||||
),
|
||||
KeyStroke.getKeyStroke('G') to IdeaAction("Tree-selectLast"),
|
||||
KeyStroke.getKeyStroke('h') to CollapseSelfOrMoveToParentNode,
|
||||
KeyStroke.getKeyStroke('H') to CollapseUntilRootNode,
|
||||
KeyStroke.getKeyStroke('j') to IdeaAction("Tree-selectNext"),
|
||||
KeyStroke.getKeyStroke('j', KeyEvent.ALT_DOWN_MASK) to IdeaAction("Tree-selectNextSibling"),
|
||||
KeyStroke.getKeyStroke('J') to IdeaAction("Tree-selectNextExtendSelection"),
|
||||
KeyStroke.getKeyStroke('k') to IdeaAction("Tree-selectPrevious"),
|
||||
KeyStroke.getKeyStroke('k', KeyEvent.ALT_DOWN_MASK) to IdeaAction("Tree-selectPreviousSibling"),
|
||||
KeyStroke.getKeyStroke('K') to IdeaAction("Tree-selectPreviousExtendSelection"),
|
||||
KeyStroke.getKeyStroke('l') to ExpandSelfOrMoveToFirstChildNode,
|
||||
KeyStroke.getKeyStroke('L') to ExpandUntilFirstLeafNode,
|
||||
KeyStroke.getKeyStroke('o') to ExpandOrCollapseTreeNode,
|
||||
KeyStroke.getKeyStroke('O') to IdeaAction("FullyExpandTreeNode"),
|
||||
KeyStroke.getKeyStroke('p') to IdeaAction("Tree-selectParentNoCollapse"),
|
||||
KeyStroke.getKeyStroke('P') to IdeaAction("Tree-selectFirst"),
|
||||
KeyStroke.getKeyStroke('x') to CollapseSelfOrParentNode,
|
||||
KeyStroke.getKeyStroke('X') to CollapseAll,
|
||||
KeyStroke.getKeyStroke('X') to IdeaAction("CollapseTreeNode"),
|
||||
)
|
||||
)
|
||||
|
||||
@ -63,51 +59,7 @@ internal object VimTreeNavigation {
|
||||
tree.collapsePath(path)
|
||||
}
|
||||
else {
|
||||
runWithoutAutoExpand(tree) { tree.expandPath(path) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object ExpandSelfOrMoveToFirstChildNode : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
val path = tree.selectionPath?.takeUnless { isLeaf(tree, it) } ?: return
|
||||
|
||||
if (tree.isExpanded(path)) {
|
||||
selectRow(tree, getFirstChild(tree, path))
|
||||
}
|
||||
else {
|
||||
runWithoutAutoExpand(tree) { tree.expandPath(path) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object ExpandUntilFirstLeafNode : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
val path = tree.selectionPath ?: return
|
||||
|
||||
var firstChildPath = path
|
||||
|
||||
while (!isLeaf(tree, firstChildPath)) {
|
||||
tree.expandPath(firstChildPath)
|
||||
firstChildPath = getFirstChild(tree, firstChildPath)
|
||||
}
|
||||
|
||||
selectRow(tree, firstChildPath)
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseSelfOrMoveToParentNode : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
val path = tree.selectionPath ?: return
|
||||
|
||||
if (tree.isExpanded(path)) {
|
||||
collapseAndScroll(tree, path)
|
||||
}
|
||||
else {
|
||||
withParentPath(tree, path) { selectRow(tree, it) }
|
||||
tree.expandPath(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,46 +73,24 @@ internal object VimTreeNavigation {
|
||||
collapseAndScroll(tree, path)
|
||||
}
|
||||
else {
|
||||
withParentPath(tree, path) { collapseAndScroll(tree, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseUntilRootNode : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
val path = tree.selectionPath ?: return
|
||||
|
||||
var parentPath = path
|
||||
|
||||
while (true) {
|
||||
parentPath = parentPath.parentPath.takeUnless { isInvisibleRoot(tree, it) } ?: break
|
||||
}
|
||||
|
||||
val parentPath = path.parentPath
|
||||
if (parentPath.parentPath != null || tree.isRootVisible) {
|
||||
collapseAndScroll(tree, parentPath)
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseAll : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
|
||||
CollapseUntilRootNode.performAction(holder, actionEvent, keyEvent)
|
||||
|
||||
var row = 0
|
||||
|
||||
while (row < tree.rowCount) {
|
||||
tree.collapseRow(row)
|
||||
row++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object ExpandChildrenToNextLevel : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
private fun collapseAndScroll(tree: JTree, path: TreePath) {
|
||||
tree.collapsePath(path)
|
||||
tree.scrollRowToVisible(tree.getRowForPath(path))
|
||||
}
|
||||
}
|
||||
|
||||
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 { isLeaf(tree, it) } ?: return
|
||||
val path = tree.selectionPath?.takeUnless { model.isLeaf(it.lastPathComponent) } ?: return
|
||||
|
||||
var pathsToExpand = mutableListOf(path)
|
||||
|
||||
@ -186,6 +116,16 @@ internal object VimTreeNavigation {
|
||||
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>> {
|
||||
@ -226,46 +166,8 @@ internal object VimTreeNavigation {
|
||||
}
|
||||
}
|
||||
|
||||
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 fun selectRow(tree: JTree, row: Int) {
|
||||
tree.setSelectionRow(row)
|
||||
tree.scrollRowToVisible(row)
|
||||
}
|
||||
|
||||
private fun selectRow(tree: JTree, path: TreePath) {
|
||||
selectRow(tree, tree.getRowForPath(path))
|
||||
}
|
||||
|
||||
private fun collapseAndScroll(tree: JTree, path: TreePath) {
|
||||
tree.collapsePath(path)
|
||||
tree.scrollRowToVisible(tree.getRowForPath(path))
|
||||
}
|
||||
|
||||
private inline fun withParentPath(tree: JTree, path: TreePath, action: (TreePath) -> Unit) {
|
||||
val parentPath = path.parentPath
|
||||
if (!isInvisibleRoot(tree, parentPath)) {
|
||||
action(parentPath)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isInvisibleRoot(tree: JTree, parentPath: TreePath): Boolean {
|
||||
return parentPath.parentPath == null && !tree.isRootVisible
|
||||
}
|
||||
|
||||
private fun getFirstChild(tree: JTree, path: TreePath): TreePath {
|
||||
return path.pathByAddingChild(tree.model.getChild(path.lastPathComponent, 0))
|
||||
}
|
||||
|
||||
private fun isLeaf(tree: JTree, firstChildPath: TreePath): Boolean {
|
||||
return tree.model.isLeaf(firstChildPath.lastPathComponent)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user