mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2026-02-18 08:46:43 +01:00
Compare commits
14 Commits
38c80a7b27
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
21c74d8615
|
|||
|
5c71108f49
|
|||
|
a2ad0a7ae0
|
|||
|
3cf84a3e28
|
|||
|
f17139e7b5
|
|||
|
24157080be
|
|||
|
46657f2f7e
|
|||
|
48b342644b
|
|||
|
5c7e20fd78
|
|||
|
ce7ec24d3a
|
|||
|
9fb1774f6d
|
|||
|
90372acdfe
|
|||
|
2d0570de1a
|
|||
|
7596b8727a
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
!/.idea/runConfigurations
|
||||
|
||||
/.gradle/
|
||||
/.intellijPlatform/
|
||||
/build/
|
||||
|
||||
@@ -1,49 +1,56 @@
|
||||
@file:Suppress("ConvertLambdaToReference")
|
||||
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.9.22"
|
||||
id("org.jetbrains.intellij") version "1.17.3"
|
||||
kotlin("jvm")
|
||||
id("org.jetbrains.intellij.platform")
|
||||
}
|
||||
|
||||
group = "com.chylex.intellij.keyboardmaster"
|
||||
version = "0.6.1"
|
||||
version = "0.6.6"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
intellijPlatform {
|
||||
defaultRepositories()
|
||||
}
|
||||
}
|
||||
|
||||
intellij {
|
||||
type.set("IU")
|
||||
version.set("2024.2")
|
||||
updateSinceUntilBuild.set(false)
|
||||
dependencies {
|
||||
intellijPlatform {
|
||||
@Suppress("DEPRECATION")
|
||||
intellijIdeaUltimate("2024.2")
|
||||
|
||||
plugins.add("com.intellij.java")
|
||||
bundledPlugin("com.intellij.java")
|
||||
|
||||
if (System.getenv("IDEAVIM") == "1") {
|
||||
plugins.add("IdeaVIM:2.10.2")
|
||||
plugin("IdeaVIM", "2.10.2")
|
||||
}
|
||||
}
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.0-M1")
|
||||
}
|
||||
|
||||
intellijPlatform {
|
||||
pluginConfiguration {
|
||||
ideaVersion {
|
||||
sinceBuild.set("242")
|
||||
untilBuild.set(provider { null })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
jvmToolchain(21)
|
||||
|
||||
dependencies {
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.0-M1")
|
||||
compilerOptions {
|
||||
freeCompilerArgs = listOf(
|
||||
"-X" + "jvm-default=all",
|
||||
"-X" + "lambdas=indy"
|
||||
)
|
||||
}
|
||||
|
||||
tasks.patchPluginXml {
|
||||
sinceBuild.set("242")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.freeCompilerArgs = listOf(
|
||||
"-Xjvm-default=all"
|
||||
)
|
||||
}
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
20
gradlew
vendored
20
gradlew
vendored
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -145,7 +147,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
@@ -153,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -202,11 +204,11 @@ fi
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
|
||||
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
rootProject.name = "KeyboardMaster"
|
||||
|
||||
pluginManagement {
|
||||
plugins {
|
||||
kotlin("jvm") version "1.9.24"
|
||||
id("org.jetbrains.intellij.platform") version "2.9.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,22 @@ internal interface KeyStrokeNode<T> {
|
||||
|
||||
fun getChild(keyEvent: KeyEvent): KeyStrokeNode<T> {
|
||||
val keyStroke = when {
|
||||
keyEvent.keyChar != KeyEvent.CHAR_UNDEFINED -> KeyStroke.getKeyStroke(keyEvent.keyChar, keyEvent.modifiersEx and KeyEvent.SHIFT_DOWN_MASK.inv())
|
||||
keyEvent.id == KeyEvent.KEY_PRESSED -> KeyStroke.getKeyStroke(keyEvent.keyCode, keyEvent.modifiersEx, false)
|
||||
isCharEvent(keyEvent) -> KeyStroke.getKeyStroke(keyEvent.keyChar, keyEvent.modifiersEx and KeyEvent.SHIFT_DOWN_MASK.inv())
|
||||
isCodeEvent(keyEvent) -> KeyStroke.getKeyStroke(keyEvent.keyCode, keyEvent.modifiersEx, false)
|
||||
else -> return this
|
||||
}
|
||||
|
||||
return keys[keyStroke] ?: this
|
||||
}
|
||||
|
||||
private fun isCharEvent(keyEvent: KeyEvent): Boolean {
|
||||
return keyEvent.keyChar != KeyEvent.CHAR_UNDEFINED && (keyEvent.modifiersEx and KeyEvent.CTRL_DOWN_MASK) == 0
|
||||
}
|
||||
|
||||
private fun isCodeEvent(keyEvent: KeyEvent): Boolean {
|
||||
return keyEvent.id == KeyEvent.KEY_PRESSED
|
||||
}
|
||||
|
||||
operator fun plus(other: Parent<T>): Parent<T> {
|
||||
val mergedKeys = HashMap(keys)
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.chylex.intellij.keyboardmaster.feature.vimNavigation
|
||||
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimListNavigation
|
||||
import com.intellij.ui.UiInterceptors.PersistentUiInterceptor
|
||||
import com.intellij.ui.awt.RelativePoint
|
||||
import com.intellij.ui.popup.AbstractPopup
|
||||
import com.intellij.ui.popup.list.ListPopupImpl
|
||||
|
||||
internal object PopupInterceptor : PersistentUiInterceptor<AbstractPopup>(AbstractPopup::class.java) {
|
||||
override fun shouldIntercept(component: AbstractPopup): Boolean {
|
||||
if (component is ListPopupImpl && VimNavigation.isEnabled) {
|
||||
VimListNavigation.install(component.list, component)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun doIntercept(component: AbstractPopup, owner: RelativePoint?) {}
|
||||
}
|
||||
@@ -6,11 +6,15 @@ import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimTa
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimTreeNavigation
|
||||
import com.intellij.ide.ui.UISettings
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.ui.UiInterceptors
|
||||
import com.intellij.openapi.ui.getUserData
|
||||
import com.intellij.openapi.ui.popup.util.PopupUtil
|
||||
import com.intellij.openapi.ui.putUserData
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.util.ui.StartupUiUtil
|
||||
import java.awt.AWTEvent
|
||||
import java.awt.event.FocusEvent
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JList
|
||||
import javax.swing.JTable
|
||||
import javax.swing.JTree
|
||||
@@ -18,6 +22,8 @@ import javax.swing.KeyStroke
|
||||
import javax.swing.UIManager
|
||||
|
||||
object VimNavigation {
|
||||
private val KEY_INSTALLED = Key.create<Boolean>("KeyboardMaster-VimNavigation-Installed")
|
||||
|
||||
private val isEnabledFlag = AtomicBoolean(false)
|
||||
private var originalPopupBindings: Array<*>? = null
|
||||
|
||||
@@ -28,7 +34,6 @@ object VimNavigation {
|
||||
val disposable = ApplicationManager.getApplication().getService(PluginDisposableService::class.java)
|
||||
|
||||
StartupUiUtil.addAwtListener(AWTEvent.FOCUS_EVENT_MASK, disposable, ::handleEvent)
|
||||
UiInterceptors.registerPersistent(disposable, PopupInterceptor)
|
||||
}
|
||||
|
||||
fun setEnabled(enabled: Boolean) {
|
||||
@@ -66,9 +71,19 @@ object VimNavigation {
|
||||
private fun handleEvent(event: AWTEvent) {
|
||||
if (event is FocusEvent && event.id == FocusEvent.FOCUS_GAINED && isEnabled) {
|
||||
when (val source = event.source) {
|
||||
is JList<*> -> VimListNavigation.install(source)
|
||||
is JTree -> VimTreeNavigation.install(source)
|
||||
is JTable -> VimTableNavigation.install(source)
|
||||
is JList<*> -> installTo(source, VimListNavigation::install)
|
||||
is JTree -> installTo(source, VimTreeNavigation::install)
|
||||
is JTable -> installTo(source, VimTableNavigation::install)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T : JComponent> installTo(component: T, installer: (T) -> Unit) {
|
||||
if (component.getUserData(KEY_INSTALLED) == null) {
|
||||
component.putUserData(KEY_INSTALLED, true)
|
||||
|
||||
if (PopupUtil.getPopupContainerFor(component) == null) {
|
||||
installer(component)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut
|
||||
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
@@ -25,6 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.swing.Action
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.KeyStroke
|
||||
import javax.swing.text.JTextComponent
|
||||
|
||||
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 {
|
||||
@@ -135,6 +137,10 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
|
||||
}
|
||||
|
||||
final override fun update(e: AnActionEvent) {
|
||||
if (!isSearching.get() && SpeedSearchSupply.getSupply(component)?.isPopupActive == true) {
|
||||
isSearching.set(true)
|
||||
}
|
||||
|
||||
e.presentation.isEnabled = !ignoreEventDueToActiveSearch(e) && !ignoreEventDueToActiveEditing(e)
|
||||
}
|
||||
|
||||
@@ -144,11 +150,12 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
|
||||
|
||||
private fun ignoreEventDueToActiveEditing(e: AnActionEvent): Boolean {
|
||||
// Avoid stealing keys from inline text fields.
|
||||
return e.dataContext.getData(CommonDataKeys.EDITOR) != null
|
||||
return e.getData(CommonDataKeys.EDITOR) != null
|
||||
|| e.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT) is JTextComponent
|
||||
}
|
||||
|
||||
final override fun getActionUpdateThread(): ActionUpdateThread {
|
||||
return ActionUpdateThread.BGT
|
||||
return ActionUpdateThread.EDT
|
||||
}
|
||||
|
||||
private sealed interface WrappedAction {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chylex.intellij.keyboardmaster.feature.vimNavigation.components
|
||||
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.ActionNode
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.IdeaAction
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.Parent
|
||||
@@ -8,10 +9,14 @@ import com.chylex.intellij.keyboardmaster.feature.vimNavigation.VimNavigationDis
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.wm.ToolWindowId
|
||||
import com.intellij.openapi.wm.ex.ToolWindowManagerEx
|
||||
import com.intellij.ui.ComponentUtil
|
||||
import com.intellij.ui.speedSearch.SpeedSearchActivator
|
||||
import com.intellij.ui.speedSearch.SpeedSearchSupply
|
||||
import java.awt.Point
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JScrollPane
|
||||
import javax.swing.JViewport
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
internal object VimCommonNavigation {
|
||||
@@ -28,6 +33,12 @@ internal object VimCommonNavigation {
|
||||
)
|
||||
)
|
||||
|
||||
inline fun <T> withShiftModifier(keyCode: Int, modifiers: Int, constructor: (Boolean) -> KeyStrokeNode<T>): Array<Pair<KeyStroke, KeyStrokeNode<T>>> {
|
||||
return arrayOf(
|
||||
KeyStroke.getKeyStroke(keyCode, modifiers) to constructor(false),
|
||||
KeyStroke.getKeyStroke(keyCode, modifiers or KeyEvent.SHIFT_DOWN_MASK) to constructor(true),
|
||||
)
|
||||
}
|
||||
|
||||
private class StartSearch<T : JComponent> : ActionNode<VimNavigationDispatcher<T>> {
|
||||
@Suppress("UnstableApiUsage")
|
||||
@@ -63,4 +74,25 @@ internal object VimCommonNavigation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun JComponent.findScrollPane(): JScrollPane? {
|
||||
return ComponentUtil.getParentOfType(JScrollPane::class.java, this)
|
||||
}
|
||||
|
||||
fun JScrollPane.scrollByPages(pages: Float) {
|
||||
scrollBy(this) { (it.height.toFloat() * pages).toInt() }
|
||||
}
|
||||
|
||||
fun JScrollPane.scrollBy(amount: Int) {
|
||||
scrollBy(this) { amount }
|
||||
}
|
||||
|
||||
private inline fun scrollBy(scrollPane: JScrollPane, amount: (JViewport) -> Int) {
|
||||
val viewport = scrollPane.viewport
|
||||
|
||||
val position = viewport.viewPosition
|
||||
val scrollTo = (position.y + amount(viewport)).coerceIn(0, viewport.viewSize.height - viewport.height)
|
||||
|
||||
viewport.viewPosition = Point(position.x, scrollTo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.chylex.intellij.keyboardmaster.feature.vimNavigation.components
|
||||
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.ActionNode
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.IdeaAction
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.Parent
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.VimNavigationDispatcher
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.findScrollPane
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.scrollBy
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.scrollByPages
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.withShiftModifier
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.ui.getUserData
|
||||
import com.intellij.openapi.ui.putUserData
|
||||
@@ -21,12 +27,8 @@ internal object VimListNavigation {
|
||||
private val KEY = Key.create<VimNavigationDispatcher<JList<*>>>("KeyboardMaster-VimListNavigation")
|
||||
|
||||
private val ROOT_NODE = VimCommonNavigation.commonRootNode<JList<*>>() + Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('g') to Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('g') to IdeaAction("List-selectFirstRow"),
|
||||
)
|
||||
),
|
||||
KeyStroke.getKeyStroke('G') to IdeaAction("List-selectLastRow"),
|
||||
KeyStroke.getKeyStroke('h') to IdeaAction("List-selectPreviousColumn"),
|
||||
KeyStroke.getKeyStroke('H') to IdeaAction("List-selectPreviousColumnExtendSelection"),
|
||||
@@ -36,6 +38,10 @@ internal object VimListNavigation {
|
||||
KeyStroke.getKeyStroke('K') to IdeaAction("List-selectPreviousRowExtendSelection"),
|
||||
KeyStroke.getKeyStroke('l') to IdeaAction("List-selectNextColumn"),
|
||||
KeyStroke.getKeyStroke('L') to IdeaAction("List-selectNextColumnExtendSelection"),
|
||||
*withShiftModifier(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = -1.0F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = +0.5F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = +1.0F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = -0.5F, extendSelection = it) },
|
||||
)
|
||||
)
|
||||
|
||||
@@ -59,6 +65,35 @@ internal object VimListNavigation {
|
||||
}
|
||||
}
|
||||
|
||||
private data class ScrollVerticallyAndSelect(private val pages: Float, private val extendSelection: Boolean) : ActionNode<VimNavigationDispatcher<JList<*>>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JList<*>>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val list = holder.component
|
||||
val scrollPane = list.findScrollPane() ?: return
|
||||
|
||||
scrollPane.scrollByPages(pages)
|
||||
|
||||
if (pages < 0F) {
|
||||
val topItemBounds = list.firstVisibleIndex.let { list.getCellBounds(it, it) } ?: return
|
||||
scrollPane.scrollBy(topItemBounds.height - 1)
|
||||
}
|
||||
|
||||
val topItemIndex = list.firstVisibleIndex
|
||||
if (topItemIndex == -1) {
|
||||
return
|
||||
}
|
||||
|
||||
if (extendSelection) {
|
||||
val anchor = list.anchorSelectionIndex.takeIf { it in 0 until list.model.size } ?: 0
|
||||
list.setSelectionInterval(anchor, topItemIndex)
|
||||
}
|
||||
else {
|
||||
list.selectedIndex = topItemIndex
|
||||
}
|
||||
|
||||
list.ensureIndexIsVisible(topItemIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("serial")
|
||||
private class VimPopupListNavigationDispatcher(component: JList<*>, override val popup: WizardPopup) : VimNavigationDispatcher<JList<*>>(component, POPUP_LIST_ROOT_NODE, popup.parent) {
|
||||
init {
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package com.chylex.intellij.keyboardmaster.feature.vimNavigation.components
|
||||
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.ActionNode
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.IdeaAction
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.Parent
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.VimNavigationDispatcher
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.findScrollPane
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.scrollBy
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.scrollByPages
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.withShiftModifier
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.ui.getUserData
|
||||
import com.intellij.openapi.ui.putUserData
|
||||
import com.intellij.openapi.util.Key
|
||||
import java.awt.Rectangle
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JTable
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
@@ -13,12 +21,8 @@ internal object VimTableNavigation {
|
||||
private val KEY = Key.create<VimNavigationDispatcher<JTable>>("KeyboardMaster-VimTableNavigation")
|
||||
|
||||
private val ROOT_NODE = VimCommonNavigation.commonRootNode<JTable>() + Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('g') to Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('g') to IdeaAction("Table-selectFirstRow"),
|
||||
)
|
||||
),
|
||||
KeyStroke.getKeyStroke('G') to IdeaAction("Table-selectLastRow"),
|
||||
KeyStroke.getKeyStroke('h') to IdeaAction("Table-selectPreviousColumn"),
|
||||
KeyStroke.getKeyStroke('H') to IdeaAction("Table-selectPreviousColumnExtendSelection"),
|
||||
@@ -28,6 +32,10 @@ internal object VimTableNavigation {
|
||||
KeyStroke.getKeyStroke('K') to IdeaAction("Table-selectPreviousRowExtendSelection"),
|
||||
KeyStroke.getKeyStroke('l') to IdeaAction("Table-selectNextColumn"),
|
||||
KeyStroke.getKeyStroke('L') to IdeaAction("Table-selectNextColumnExtendSelection"),
|
||||
*withShiftModifier(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = -1.0F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = +0.5F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = +1.0F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = -0.5F, extendSelection = it) },
|
||||
)
|
||||
)
|
||||
|
||||
@@ -36,4 +44,29 @@ internal object VimTableNavigation {
|
||||
component.putUserData(KEY, VimNavigationDispatcher(component, ROOT_NODE))
|
||||
}
|
||||
}
|
||||
|
||||
private data class ScrollVerticallyAndSelect(private val pages: Float, private val extendSelection: Boolean) : ActionNode<VimNavigationDispatcher<JTable>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTable>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val table = holder.component
|
||||
val scrollPane = table.findScrollPane() ?: return
|
||||
|
||||
scrollPane.scrollByPages(pages)
|
||||
|
||||
if (pages < 0F) {
|
||||
scrollPane.scrollBy(table.rowHeight - 1)
|
||||
}
|
||||
|
||||
val visibleRect = table.visibleRect
|
||||
val rowIndexToSelect = table.rowAtPoint(visibleRect.location)
|
||||
if (rowIndexToSelect == -1) {
|
||||
return
|
||||
}
|
||||
|
||||
val rowRect = table.getCellRect(rowIndexToSelect, 0, true)
|
||||
val adjustedRect = Rectangle(visibleRect.x, rowRect.y, visibleRect.width, visibleRect.height)
|
||||
|
||||
table.changeSelection(rowIndexToSelect, table.selectedColumn, false, extendSelection)
|
||||
table.scrollRectToVisible(adjustedRect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.Ac
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.IdeaAction
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.KeyStrokeNode.Parent
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.VimNavigationDispatcher
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.findScrollPane
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.scrollBy
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.scrollByPages
|
||||
import com.chylex.intellij.keyboardmaster.feature.vimNavigation.components.VimCommonNavigation.withShiftModifier
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.ui.getUserData
|
||||
import com.intellij.openapi.ui.putUserData
|
||||
@@ -13,6 +17,7 @@ import com.intellij.ui.tree.ui.DefaultTreeUI
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JTree
|
||||
import javax.swing.KeyStroke
|
||||
import javax.swing.tree.TreeModel
|
||||
import javax.swing.tree.TreePath
|
||||
|
||||
internal object VimTreeNavigation {
|
||||
@@ -20,31 +25,40 @@ internal object VimTreeNavigation {
|
||||
|
||||
private val ROOT_NODE = VimCommonNavigation.commonRootNode<JTree>() + Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('a') to Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('o') to ExpandAll,
|
||||
KeyStroke.getKeyStroke('x') to CollapseAll,
|
||||
)
|
||||
),
|
||||
KeyStroke.getKeyStroke('g') to Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('g') to IdeaAction("Tree-selectFirst"),
|
||||
KeyStroke.getKeyStroke('j') to SelectLastSibling,
|
||||
KeyStroke.getKeyStroke('k') to SelectFirstSibling,
|
||||
KeyStroke.getKeyStroke('o') to ExpandChildrenToNextLevel,
|
||||
KeyStroke.getKeyStroke('j') to IdeaAction("Tree-selectNextSibling"),
|
||||
KeyStroke.getKeyStroke('k') to IdeaAction("Tree-selectPreviousSibling"),
|
||||
)
|
||||
),
|
||||
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 ExpandChildrenToNextLevel,
|
||||
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('s') to SelectFirstSibling,
|
||||
KeyStroke.getKeyStroke('S') to SelectLastSibling,
|
||||
KeyStroke.getKeyStroke('x') to CollapseChildrenToPreviousLevel,
|
||||
KeyStroke.getKeyStroke('X') to CollapseSelf,
|
||||
*withShiftModifier(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = -1.0F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = +0.5F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = +1.0F, extendSelection = it) },
|
||||
*withShiftModifier(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK) { ScrollVerticallyAndSelect(pages = -0.5F, extendSelection = it) },
|
||||
)
|
||||
)
|
||||
|
||||
@@ -54,20 +68,177 @@ internal object VimTreeNavigation {
|
||||
}
|
||||
}
|
||||
|
||||
private data object ExpandOrCollapseTreeNode : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
private data class ScrollVerticallyAndSelect(private val pages: Float, private val extendSelection: Boolean) : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
val scrollPane = tree.findScrollPane() ?: return
|
||||
|
||||
scrollPane.scrollByPages(pages)
|
||||
|
||||
if (pages < 0F) {
|
||||
val topPath = pathOnTop(tree) ?: return
|
||||
val topPathBounds = tree.getPathBounds(topPath) ?: return
|
||||
scrollPane.scrollBy(topPathBounds.height - 1)
|
||||
}
|
||||
|
||||
val pathToSelect = pathOnTop(tree) ?: return
|
||||
|
||||
if (extendSelection) {
|
||||
val anchor = tree.anchorSelectionPath
|
||||
val anchorRow = if (anchor == null) -1 else tree.getRowForPath(anchor)
|
||||
if (anchorRow < 0) {
|
||||
tree.selectionPath = pathToSelect
|
||||
}
|
||||
else {
|
||||
tree.setSelectionInterval(tree.getRowForPath(pathToSelect), anchorRow)
|
||||
tree.setAnchorSelectionPath(anchor)
|
||||
tree.leadSelectionPath = pathToSelect
|
||||
}
|
||||
}
|
||||
else {
|
||||
tree.selectionPath = pathToSelect
|
||||
}
|
||||
|
||||
tree.scrollRectToVisible(tree.getPathBounds(pathToSelect))
|
||||
}
|
||||
|
||||
private fun pathOnTop(tree: JTree): TreePath? {
|
||||
return tree.visibleRect.let { tree.getClosestPathForLocation(it.x, it.y) }
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseSelf : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
val path = tree.selectionPath ?: return
|
||||
|
||||
collapseAndScroll(tree, path)
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
tree.collapsePath(path)
|
||||
collapseAndScroll(tree, path)
|
||||
}
|
||||
else {
|
||||
runWithoutAutoExpand(tree) { tree.expandPath(path) }
|
||||
withParentPath(tree, path) { selectRow(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
|
||||
}
|
||||
|
||||
collapseAndScroll(tree, parentPath)
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseAll : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
|
||||
var row = 0
|
||||
|
||||
while (row < tree.rowCount) {
|
||||
tree.collapseRow(row)
|
||||
row++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseChildrenToPreviousLevel : 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?.takeIf(tree::isExpanded) ?: return
|
||||
|
||||
var currentLevel = mutableListOf(path)
|
||||
|
||||
while (true) {
|
||||
val nextLevel = mutableListOf<TreePath>()
|
||||
|
||||
for (parentPath in currentLevel) {
|
||||
forEachChild(model, parentPath) {
|
||||
val childPath = parentPath.pathByAddingChild(it)
|
||||
if (tree.isExpanded(childPath)) {
|
||||
nextLevel.add(childPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nextLevel.isNotEmpty()) {
|
||||
currentLevel = nextLevel
|
||||
}
|
||||
else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for (parentPath in currentLevel) {
|
||||
tree.collapsePath(parentPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object ExpandAll : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
|
||||
var row = 0
|
||||
|
||||
while (row < tree.rowCount) {
|
||||
tree.expandRow(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) }
|
||||
|
||||
for (path in pathsToExpand) {
|
||||
forEachChild(model, path) { tree.collapsePath(path.pathByAddingChild(it)) }
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
val nextPathsToExpand = mutableListOf<TreePath>()
|
||||
|
||||
for (parentPath in pathsToExpand) {
|
||||
forEachChild(model, parentPath) {
|
||||
if (!model.isLeaf(it)) {
|
||||
nextPathsToExpand.add(parentPath.pathByAddingChild(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pathsToExpand = nextPathsToExpand
|
||||
} while (pathsToExpand.isNotEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
private data object ExpandSelfOrMoveToFirstChildNode : ActionNode<VimNavigationDispatcher<JTree>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
@@ -98,96 +269,6 @@ internal object VimTreeNavigation {
|
||||
}
|
||||
}
|
||||
|
||||
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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data object CollapseSelfOrParentNode : 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) { 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
|
||||
}
|
||||
|
||||
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>> {
|
||||
override fun performAction(holder: VimNavigationDispatcher<JTree>, actionEvent: AnActionEvent, keyEvent: KeyEvent) {
|
||||
val tree = holder.component
|
||||
@@ -226,6 +307,14 @@ internal object VimTreeNavigation {
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun forEachChild(model: TreeModel, path: TreePath, action: (Any) -> Unit) {
|
||||
val lastPathComponent = path.lastPathComponent
|
||||
|
||||
for (i in 0 until model.getChildCount(lastPathComponent)) {
|
||||
action(model.getChild(lastPathComponent, i))
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -247,7 +336,7 @@ internal object VimTreeNavigation {
|
||||
|
||||
private fun collapseAndScroll(tree: JTree, path: TreePath) {
|
||||
tree.collapsePath(path)
|
||||
tree.scrollRowToVisible(tree.getRowForPath(path))
|
||||
tree.scrollPathToVisible(path)
|
||||
}
|
||||
|
||||
private inline fun withParentPath(tree: JTree, path: TreePath, action: (TreePath) -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user