mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2025-09-14 14:32:16 +02:00
Compare commits
12 Commits
d76e259c25
...
main
Author | SHA1 | Date | |
---|---|---|---|
7596b8727a
|
|||
38c80a7b27
|
|||
efe13712ad
|
|||
5aea7947ec
|
|||
f814ec04bd
|
|||
c7229a6d8e
|
|||
d711e60da8
|
|||
356826f6ae
|
|||
f3a3685084
|
|||
5e654762fc
|
|||
723b8af939
|
|||
72158689ff
|
@@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.chylex.intellij.keyboardmaster"
|
group = "com.chylex.intellij.keyboardmaster"
|
||||||
version = "0.5.6"
|
version = "0.6.2"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -16,7 +16,7 @@ repositories {
|
|||||||
|
|
||||||
intellij {
|
intellij {
|
||||||
type.set("IU")
|
type.set("IU")
|
||||||
version.set("2024.1.1")
|
version.set("2024.2")
|
||||||
updateSinceUntilBuild.set(false)
|
updateSinceUntilBuild.set(false)
|
||||||
|
|
||||||
plugins.add("com.intellij.java")
|
plugins.add("com.intellij.java")
|
||||||
@@ -35,7 +35,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.patchPluginXml {
|
tasks.patchPluginXml {
|
||||||
sinceBuild.set("241")
|
sinceBuild.set("242")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
|
@@ -2,9 +2,10 @@ package com.chylex.intellij.keyboardmaster.feature.action.gotoError
|
|||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightActionHandler
|
import com.intellij.codeInsight.CodeInsightActionHandler
|
||||||
import com.intellij.codeInsight.daemon.impl.actions.GotoNextErrorAction
|
import com.intellij.codeInsight.daemon.impl.actions.GotoNextErrorAction
|
||||||
|
import com.intellij.openapi.actionSystem.DataContext
|
||||||
|
|
||||||
class GotoNextErrorInOtherModeAction : GotoNextErrorAction() {
|
class GotoNextErrorInOtherModeAction : GotoNextErrorAction() {
|
||||||
override fun getHandler(): CodeInsightActionHandler {
|
override fun getHandler(dataContext: DataContext): CodeInsightActionHandler {
|
||||||
return GotoErrorInOtherModeHandler(forward = true)
|
return GotoErrorInOtherModeHandler(forward = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,10 @@ package com.chylex.intellij.keyboardmaster.feature.action.gotoError
|
|||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightActionHandler
|
import com.intellij.codeInsight.CodeInsightActionHandler
|
||||||
import com.intellij.codeInsight.daemon.impl.actions.GotoPreviousErrorAction
|
import com.intellij.codeInsight.daemon.impl.actions.GotoPreviousErrorAction
|
||||||
|
import com.intellij.openapi.actionSystem.DataContext
|
||||||
|
|
||||||
class GotoPreviousErrorInOtherModeAction : GotoPreviousErrorAction() {
|
class GotoPreviousErrorInOtherModeAction : GotoPreviousErrorAction() {
|
||||||
override fun getHandler(): CodeInsightActionHandler {
|
override fun getHandler(dataContext: DataContext): CodeInsightActionHandler {
|
||||||
return GotoErrorInOtherModeHandler(forward = false)
|
return GotoErrorInOtherModeHandler(forward = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,7 @@ class GotoTypeInFileHandler(private val forward: Boolean) : CodeInsightActionHan
|
|||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
fun getNavigationOffsets(file: PsiFile, searchedOffsetRange: IntRange): IntArray {
|
fun getNavigationOffsets(file: PsiFile, searchedOffsetRange: IntRange): IntArray {
|
||||||
val structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file)
|
val structureViewBuilder = LanguageStructureViewBuilder.getInstance().getStructureViewBuilder(file)
|
||||||
if (structureViewBuilder !is TreeBasedStructureViewBuilder) {
|
if (structureViewBuilder !is TreeBasedStructureViewBuilder) {
|
||||||
return intArrayOf()
|
return intArrayOf()
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
package com.chylex.intellij.keyboardmaster.feature.codeCompletion
|
package com.chylex.intellij.keyboardmaster.feature.codeCompletion
|
||||||
|
|
||||||
import com.intellij.util.containers.IntIntHashMap
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap
|
||||||
|
|
||||||
object CodeCompletionPopupConfiguration {
|
object CodeCompletionPopupConfiguration {
|
||||||
const val SHORTCUT_NONE = -1
|
const val SHORTCUT_NONE = -1
|
||||||
const val SHORTCUT_NEXT_PAGE = -2
|
const val SHORTCUT_NEXT_PAGE = -2
|
||||||
const val SHORTCUT_PREV_PAGE = -3
|
const val SHORTCUT_PREV_PAGE = -3
|
||||||
|
|
||||||
private val charToShortcutMap = IntIntHashMap(16, SHORTCUT_NONE)
|
private val charToShortcutMap = Int2IntOpenHashMap(16).also { it.defaultReturnValue(SHORTCUT_NONE) }
|
||||||
private var hintTexts = mutableListOf<String>()
|
private var hintTexts = mutableListOf<String>()
|
||||||
|
|
||||||
val itemShortcutCount
|
val itemShortcutCount
|
||||||
|
@@ -59,7 +59,7 @@ internal interface KeyStrokeNode<T> {
|
|||||||
override fun performAction(holder: T, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
override fun performAction(holder: T, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||||
val action = actionEvent.actionManager.getAction(name) ?: return
|
val action = actionEvent.actionManager.getAction(name) ?: return
|
||||||
|
|
||||||
val dataContext = CustomizedDataContext.create(actionEvent.dataContext) {
|
val dataContext = CustomizedDataContext.withProvider(actionEvent.dataContext) {
|
||||||
when {
|
when {
|
||||||
PlatformDataKeys.CONTEXT_COMPONENT.`is`(it) -> holder.component
|
PlatformDataKeys.CONTEXT_COMPONENT.`is`(it) -> holder.component
|
||||||
else -> null
|
else -> null
|
||||||
|
@@ -27,7 +27,7 @@ object VimNavigation {
|
|||||||
fun register() {
|
fun register() {
|
||||||
val disposable = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
|
val disposable = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
|
||||||
|
|
||||||
StartupUiUtil.addAwtListener(::handleEvent, AWTEvent.FOCUS_EVENT_MASK, disposable)
|
StartupUiUtil.addAwtListener(AWTEvent.FOCUS_EVENT_MASK, disposable, ::handleEvent)
|
||||||
UiInterceptors.registerPersistent(disposable, PopupInterceptor)
|
UiInterceptors.registerPersistent(disposable, PopupInterceptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package com.chylex.intellij.keyboardmaster.feature.vimNavigation
|
package com.chylex.intellij.keyboardmaster.feature.vimNavigation
|
||||||
|
|
||||||
import com.chylex.intellij.keyboardmaster.PluginDisposableService
|
|
||||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.VimNavigationDispatcher.WrappedAction.ForKeyListener
|
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.VimNavigationDispatcher.WrappedAction.ForKeyListener
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||||
import com.intellij.openapi.actionSystem.AnAction
|
import com.intellij.openapi.actionSystem.AnAction
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||||
@@ -26,10 +26,8 @@ import javax.swing.Action
|
|||||||
import javax.swing.JComponent
|
import javax.swing.JComponent
|
||||||
import javax.swing.KeyStroke
|
import javax.swing.KeyStroke
|
||||||
|
|
||||||
internal open class VimNavigationDispatcher<T : JComponent>(final override val component: T, private val rootNode: KeyStrokeNode.Parent<VimNavigationDispatcher<T>>) : DumbAwareAction(), ComponentHolder {
|
internal open class VimNavigationDispatcher<T : JComponent>(final override val component: T, private val rootNode: KeyStrokeNode.Parent<VimNavigationDispatcher<T>>, disposable: Disposable? = null) : DumbAwareAction(), ComponentHolder {
|
||||||
companion object {
|
companion object {
|
||||||
private val DISPOSABLE = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected val ENTER_KEY: KeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)
|
protected val ENTER_KEY: KeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)
|
||||||
|
|
||||||
@@ -73,7 +71,7 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
|
|||||||
var isSearching = AtomicBoolean(false)
|
var isSearching = AtomicBoolean(false)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
registerCustomShortcutSet(KeyStrokeNode.getAllShortcuts(getAllKeyStrokes()), component, DISPOSABLE)
|
registerCustomShortcutSet(KeyStrokeNode.getAllShortcuts(getAllKeyStrokes()), component, disposable)
|
||||||
SpeedSearchSupply.getSupply(component, true)?.addChangeListener(::handleSpeedSearchChange)
|
SpeedSearchSupply.getSupply(component, true)?.addChangeListener(::handleSpeedSearchChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ internal object VimListNavigation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("serial")
|
@Suppress("serial")
|
||||||
private class VimPopupListNavigationDispatcher(component: JList<*>, override val popup: WizardPopup) : VimNavigationDispatcher<JList<*>>(component, POPUP_LIST_ROOT_NODE) {
|
private class VimPopupListNavigationDispatcher(component: JList<*>, override val popup: WizardPopup) : VimNavigationDispatcher<JList<*>>(component, POPUP_LIST_ROOT_NODE, popup.parent) {
|
||||||
init {
|
init {
|
||||||
val speedSearch = SpeedSearchSupply.getSupply(component, true) as? SpeedSearch
|
val speedSearch = SpeedSearchSupply.getSupply(component, true) as? SpeedSearch
|
||||||
if (speedSearch != null) {
|
if (speedSearch != null) {
|
||||||
|
@@ -8,9 +8,12 @@ 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")
|
||||||
@@ -22,21 +25,26 @@ 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 ExpandChildrenToNextLevel,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
KeyStroke.getKeyStroke('G') to IdeaAction("Tree-selectLast"),
|
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') to IdeaAction("Tree-selectNext"),
|
||||||
KeyStroke.getKeyStroke('j', KeyEvent.ALT_DOWN_MASK) to IdeaAction("Tree-selectNextSibling"),
|
KeyStroke.getKeyStroke('j', KeyEvent.ALT_DOWN_MASK) to IdeaAction("Tree-selectNextSibling"),
|
||||||
KeyStroke.getKeyStroke('J') to IdeaAction("Tree-selectNextExtendSelection"),
|
KeyStroke.getKeyStroke('J') to IdeaAction("Tree-selectNextExtendSelection"),
|
||||||
KeyStroke.getKeyStroke('k') to IdeaAction("Tree-selectPrevious"),
|
KeyStroke.getKeyStroke('k') to IdeaAction("Tree-selectPrevious"),
|
||||||
KeyStroke.getKeyStroke('k', KeyEvent.ALT_DOWN_MASK) to IdeaAction("Tree-selectPreviousSibling"),
|
KeyStroke.getKeyStroke('k', KeyEvent.ALT_DOWN_MASK) to IdeaAction("Tree-selectPreviousSibling"),
|
||||||
KeyStroke.getKeyStroke('K') to IdeaAction("Tree-selectPreviousExtendSelection"),
|
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 ExpandOrCollapseTreeNode,
|
||||||
KeyStroke.getKeyStroke('O') to IdeaAction("FullyExpandTreeNode"),
|
KeyStroke.getKeyStroke('O') to IdeaAction("FullyExpandTreeNode"),
|
||||||
KeyStroke.getKeyStroke('p') to IdeaAction("Tree-selectParentNoCollapse"),
|
KeyStroke.getKeyStroke('p') to IdeaAction("Tree-selectParentNoCollapse"),
|
||||||
KeyStroke.getKeyStroke('P') to IdeaAction("Tree-selectFirst"),
|
KeyStroke.getKeyStroke('P') to IdeaAction("Tree-selectFirst"),
|
||||||
KeyStroke.getKeyStroke('x') to CollapseSelfOrParentNode,
|
KeyStroke.getKeyStroke('x') to CollapseSelfOrParentNode,
|
||||||
KeyStroke.getKeyStroke('X') to IdeaAction("CollapseTreeNode"),
|
KeyStroke.getKeyStroke('X') to CollapseAll,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,7 +63,51 @@ internal object VimTreeNavigation {
|
|||||||
tree.collapsePath(path)
|
tree.collapsePath(path)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tree.expandPath(path)
|
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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,17 +118,76 @@ internal object VimTreeNavigation {
|
|||||||
val path = tree.selectionPath ?: return
|
val path = tree.selectionPath ?: return
|
||||||
|
|
||||||
if (tree.isExpanded(path)) {
|
if (tree.isExpanded(path)) {
|
||||||
tree.collapsePath(path)
|
collapseAndScroll(tree, path)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val parentPath = path.parentPath
|
withParentPath(tree, path) { collapseAndScroll(tree, it) }
|
||||||
if (parentPath.parentPath != null || tree.isRootVisible) {
|
|
||||||
tree.collapsePath(parentPath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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>> {
|
||||||
|
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
|
||||||
|
|
||||||
|
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 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
|
||||||
@@ -115,8 +226,46 @@ 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) {
|
private fun selectRow(tree: JTree, row: Int) {
|
||||||
tree.setSelectionRow(row)
|
tree.setSelectionRow(row)
|
||||||
tree.scrollRowToVisible(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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user