mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-13 06:16:58 +02:00
Set up a mechanism to define the KeyStrokes that should work with active lookup
This commit is contained in:
@@ -107,6 +107,16 @@ The following `:set` commands can appear in `~/.ideavimrc` or be set manually in
|
||||
|
||||
If false, IdeaVim icon won't be shown in the status bar.
|
||||
Works only from `~/.ideavimrc` after the IDE restart.
|
||||
|
||||
`lookupkeys` `lookupkeys` List of strings [To Be Released]
|
||||
|
||||
List of keys that should be processed by the IDE during the active lookup (autocompletion).
|
||||
For example, <Tab> and <Enter> are used by the IDE to finish the lookup,
|
||||
but <C-W> should be passed to IdeaVim.
|
||||
Default value:
|
||||
"<Tab>", "<Down>", "<Up>", "<Enter>", "<Left>", "<Right>",
|
||||
"<C-Down>", "<C-Up>", "<PageUp>", "<PageDown>",
|
||||
"<C-J>", "<C-Q>"
|
||||
|
||||
----------
|
||||
[1] - cursor keys, <End>, <Home>, <PageUp> and <PageDown>
|
||||
|
@@ -34,7 +34,6 @@ import com.intellij.openapi.util.Key
|
||||
import com.intellij.ui.KeyStrokeAdapter
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase.Companion.parseKeysSet
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
@@ -42,7 +41,7 @@ import com.maddyhome.idea.vim.helper.inInsertMode
|
||||
import com.maddyhome.idea.vim.helper.inNormalMode
|
||||
import com.maddyhome.idea.vim.key.ShortcutOwner
|
||||
import com.maddyhome.idea.vim.listener.IdeaSpecifics.aceJumpActive
|
||||
import com.maddyhome.idea.vim.option.OptionsManager.lookupKeys
|
||||
import com.maddyhome.idea.vim.option.OptionsManager
|
||||
import java.awt.event.InputEvent
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.KeyStroke
|
||||
@@ -90,7 +89,7 @@ class VimShortcutKeyAction : AnAction(), DumbAware {
|
||||
if (aceJumpActive()) return false
|
||||
val keyCode = keyStroke.keyCode
|
||||
if (LookupManager.getActiveLookup(editor) != null) {
|
||||
return isEnabledForLookup(keyStroke)
|
||||
return LookupKeys.isEnabledForLookup(keyStroke)
|
||||
}
|
||||
if (keyCode == KeyEvent.VK_ESCAPE) {
|
||||
return isEnabledForEscape(editor)
|
||||
@@ -136,29 +135,6 @@ class VimShortcutKeyAction : AnAction(), DumbAware {
|
||||
return fileEditorManager.allEditors.any { fileEditor -> editor == EditorUtil.getEditorEx(fileEditor) }
|
||||
}
|
||||
|
||||
private fun isEnabledForLookup(keyStroke: KeyStroke): Boolean {
|
||||
val notAllowedKeys = parseKeysSet(
|
||||
"<Tab>", "<Down>", "<Up>", "<Enter>", "<Left>", "<Right>",
|
||||
// New line in vim, but QuickDoc on MacOs
|
||||
"<C-J>"
|
||||
)
|
||||
for (keys in notAllowedKeys) {
|
||||
if (keyStroke == keys[0]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
// We allow users to set custom keys that will work with lookup in case devs forgot something
|
||||
val popupActions = lookupKeys
|
||||
val values = popupActions.values()
|
||||
for (value in values) {
|
||||
val keys = StringHelper.parseKeys(value)
|
||||
if (keys.size >= 1 && keyStroke == keys[0]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun isShortcutConflict(keyStroke: KeyStroke): Boolean {
|
||||
return VimPlugin.getKey().getKeymapConflicts(keyStroke).isNotEmpty()
|
||||
}
|
||||
@@ -189,6 +165,31 @@ class VimShortcutKeyAction : AnAction(), DumbAware {
|
||||
|
||||
private fun getEditor(e: AnActionEvent): Editor? = e.getData(PlatformDataKeys.EDITOR)
|
||||
|
||||
/**
|
||||
* Every time the key pressed with an active lookup, there is a decision:
|
||||
* should this key be processed by IdeaVim, or by IDE. For example, dot and enter should be processed by IDE, but
|
||||
* <C-W> by IdeaVim.
|
||||
*
|
||||
* The list of keys that should be processed by IDE is stored in [OptionsManager.lookupKeys]. So, we should search
|
||||
* if the pressed key is presented in this list. The caches are used to speedup the process.
|
||||
*/
|
||||
private object LookupKeys {
|
||||
private var parsedLookupKeys: List<KeyStroke> = parseLookupKeys()
|
||||
private val lookupKeysCache = mutableMapOf<KeyStroke, Boolean>()
|
||||
|
||||
init {
|
||||
OptionsManager.lookupKeys.addOptionChangeListener { _, _ ->
|
||||
parsedLookupKeys = parseLookupKeys()
|
||||
lookupKeysCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun isEnabledForLookup(keyStroke: KeyStroke): Boolean = lookupKeysCache.getOrPut(keyStroke) { keyStroke !in parsedLookupKeys }
|
||||
|
||||
private fun parseLookupKeys() = OptionsManager.lookupKeys.values()
|
||||
.map { StringHelper.parseKeys(it) }.filter { it.isNotEmpty() }.map { it.first() }
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val VIM_ONLY_EDITOR_KEYS: Set<KeyStroke> = ImmutableSet.builder<KeyStroke>().addAll(getKeyStrokes(KeyEvent.VK_ENTER, 0)).addAll(getKeyStrokes(KeyEvent.VK_ESCAPE, 0))
|
||||
|
@@ -58,7 +58,7 @@ object OptionsManager {
|
||||
val incsearch = addOption(ToggleOption("incsearch", "is", false))
|
||||
val iskeyword = addOption(KeywordOption("iskeyword", "isk", arrayOf("@", "48-57", "_")))
|
||||
val keymodel = addOption(KeyModelOptionData.option)
|
||||
val lookupKeys = addOption(ListOption("lookupkeys", "lookupkeys", arrayOf(), null))
|
||||
val lookupKeys = addOption(ListOption(LookupKeysData.name, LookupKeysData.name, LookupKeysData.defaultValues, null))
|
||||
val matchpairs = addOption(ListOption("matchpairs", "mps", arrayOf("(:)", "{:}", "[:]"), ".:."))
|
||||
val more = addOption(ToggleOption("more", "more", true))
|
||||
val nrformats = addOption(BoundListOption("nrformats", "nf", arrayOf("octal", "hex"), arrayOf("octal", "hex", "alpha")))
|
||||
@@ -506,3 +506,17 @@ object IdeaRefactorMode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object LookupKeysData {
|
||||
val name = "lookupkeys"
|
||||
val defaultValues = arrayOf(
|
||||
"<Tab>", "<Down>", "<Up>", "<Enter>", "<Left>", "<Right>",
|
||||
"<C-Down>", "<C-Up>",
|
||||
"<PageUp>", "<PageDown>",
|
||||
// New line in vim, but QuickDoc on MacOs
|
||||
"<C-J>",
|
||||
// QuickDoc for non-mac layouts.
|
||||
// Vim: Insert next non-digit literally (same as <Ctrl-V>). Not yet supported (19.01.2020)
|
||||
"<C-Q>"
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user