mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2026-10-16 23:33:57 +02:00
Compare commits
5
Commits
055b118f59
...
b616326357
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b616326357
|
||
|
|
e182b19428
|
||
|
|
10fe579ad2
|
||
|
|
209c1d8bfa
|
||
|
|
936faedf78
|
+3
-1
@@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.chylex.intellij.keyboardmaster"
|
||||
version = "0.6.7"
|
||||
version = "0.6.8"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -26,6 +26,8 @@ dependencies {
|
||||
|
||||
bundledPlugin("com.intellij.java")
|
||||
|
||||
compatiblePlugin("com.intellij.classic.ui")
|
||||
|
||||
if (System.getenv("IDEAVIM") == "1") {
|
||||
plugin("IdeaVIM", "2.10.2")
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,14 +22,14 @@ internal interface KeyStrokeNode<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fun getChild(keyEvent: KeyEvent): KeyStrokeNode<T> {
|
||||
fun getChild(keyEvent: KeyEvent): KeyStrokeNode<T>? {
|
||||
val keyStroke = when {
|
||||
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
|
||||
else -> return null
|
||||
}
|
||||
|
||||
return keys[keyStroke] ?: this
|
||||
return keys[keyStroke]
|
||||
}
|
||||
|
||||
private fun isCharEvent(keyEvent: KeyEvent): Boolean {
|
||||
|
||||
+3
-2
@@ -106,13 +106,14 @@ internal open class VimNavigationDispatcher<T : JComponent>(final override val c
|
||||
|
||||
protected inline fun handleKeyPress(actionEvent: AnActionEvent, keyEvent: KeyEvent, fallback: () -> Unit) {
|
||||
when (val nextNode = currentNode.getChild(keyEvent)) {
|
||||
is KeyStrokeNode.Parent<VimNavigationDispatcher<T>> -> currentNode = nextNode
|
||||
is KeyStrokeNode.Parent<VimNavigationDispatcher<T>> -> {
|
||||
currentNode = nextNode
|
||||
}
|
||||
is KeyStrokeNode.ActionNode<VimNavigationDispatcher<T>> -> {
|
||||
nextNode.performAction(this, actionEvent, keyEvent)
|
||||
currentNode = rootNode
|
||||
}
|
||||
else -> {
|
||||
currentNode = rootNode
|
||||
fallback()
|
||||
}
|
||||
}
|
||||
|
||||
+20
-14
@@ -13,6 +13,7 @@ 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 com.intellij.openapi.vcs.changes.ui.ChangesListView
|
||||
import com.intellij.openapi.vcs.changes.ui.ChangesTree
|
||||
import com.intellij.ui.ClientProperty
|
||||
import com.intellij.ui.tree.ui.DefaultTreeUI
|
||||
@@ -73,22 +74,37 @@ internal object VimTreeNavigation {
|
||||
)
|
||||
)
|
||||
|
||||
private val GIT_CHANGES_ROOT_NODE = BASIC_ROOT_NODE + Parent(
|
||||
private val GIT_CHANGES_BASIC_ROOT_NODE = BASIC_ROOT_NODE + Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('d') to IdeaAction("Vcs.ShowDiffWithLocal"),
|
||||
KeyStroke.getKeyStroke('e') to IdeaAction("EditSource"),
|
||||
)
|
||||
)
|
||||
|
||||
private val GIT_LOCAL_CHANGES_ROOT_NODE = GIT_CHANGES_BASIC_ROOT_NODE + Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('r') to IdeaAction("ChangesView.Revert"),
|
||||
)
|
||||
)
|
||||
|
||||
private val GIT_OTHER_CHANGES_ROOT_NODE = GIT_CHANGES_BASIC_ROOT_NODE + Parent(
|
||||
mapOf(
|
||||
KeyStroke.getKeyStroke('c') to IdeaAction("Vcs.ApplySelectedChanges"),
|
||||
KeyStroke.getKeyStroke('r') to IdeaAction("Vcs.RevertSelectedChanges"),
|
||||
)
|
||||
)
|
||||
|
||||
fun install(component: JTree) {
|
||||
if (component.getUserData(KEY) == null) {
|
||||
component.putUserData(KEY, VimNavigationDispatcher(component, pickRootNode(component)))
|
||||
ClientProperty.put(component, DefaultTreeUI.AUTO_EXPAND_ALLOWED, false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pickRootNode(component: JTree) = when (component) {
|
||||
is ProjectViewTree -> PROJECT_FILE_TREE_ROOT_NODE
|
||||
is ChangesTree -> GIT_CHANGES_ROOT_NODE
|
||||
is ChangesListView -> GIT_LOCAL_CHANGES_ROOT_NODE
|
||||
is ChangesTree -> GIT_OTHER_CHANGES_ROOT_NODE
|
||||
else -> BASIC_ROOT_NODE
|
||||
}
|
||||
|
||||
@@ -239,7 +255,7 @@ internal object VimTreeNavigation {
|
||||
|
||||
do {
|
||||
if (pathsToExpand.any(tree::isCollapsed)) {
|
||||
runWithoutAutoExpand(tree) { pathsToExpand.forEach(tree::expandPath) }
|
||||
pathsToExpand.forEach(tree::expandPath)
|
||||
|
||||
for (path in pathsToExpand) {
|
||||
forEachChild(model, path) { tree.collapsePath(path.pathByAddingChild(it)) }
|
||||
@@ -272,7 +288,7 @@ internal object VimTreeNavigation {
|
||||
selectRow(tree, getFirstChild(tree, path))
|
||||
}
|
||||
else {
|
||||
runWithoutAutoExpand(tree) { tree.expandPath(path) }
|
||||
tree.expandPath(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -339,16 +355,6 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user