From 5e654762fc8c03da1f9ecc166ca01da73f96c074 Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Mon, 5 Aug 2024 03:55:14 +0200 Subject: [PATCH] Fix vim-style navigation not scrolling after collapsing a tree node --- .../vimNavigation/components/VimTreeNavigation.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimTreeNavigation.kt b/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimTreeNavigation.kt index 6585b4a..6c476f6 100644 --- a/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimTreeNavigation.kt +++ b/src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/vimNavigation/components/VimTreeNavigation.kt @@ -70,15 +70,20 @@ internal object VimTreeNavigation { val path = tree.selectionPath ?: return if (tree.isExpanded(path)) { - tree.collapsePath(path) + collapseAndScroll(tree, path) } else { val parentPath = path.parentPath if (parentPath.parentPath != null || tree.isRootVisible) { - tree.collapsePath(parentPath) + collapseAndScroll(tree, parentPath) } } } + + private fun collapseAndScroll(tree: JTree, path: TreePath) { + tree.collapsePath(path) + tree.scrollRowToVisible(tree.getRowForPath(path)) + } } private data object ExpandTreeNodeChildrenToNextLevel : ActionNode<VimNavigationDispatcher<JTree>> {