From 5aea7947ec6d144d2665915fba3779d010c94927 Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Wed, 18 Sep 2024 08:52:51 +0200 Subject: [PATCH] Disable automatic tree auto-expansion in vim-style navigation --- .../components/VimTreeNavigation.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 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 6c476f6..d952159 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 @@ -59,7 +59,7 @@ internal object VimTreeNavigation { tree.collapsePath(path) } else { - tree.expandPath(path) + runWithoutAutoExpand(tree) { tree.expandPath(path) } } } } @@ -116,16 +116,6 @@ 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>> { @@ -166,6 +156,16 @@ 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)