diff --git a/src/main/java/com/maddyhome/idea/vim/action/VimShortcutKeyAction.kt b/src/main/java/com/maddyhome/idea/vim/action/VimShortcutKeyAction.kt index 8a5c1d534..a5655bc6a 100644 --- a/src/main/java/com/maddyhome/idea/vim/action/VimShortcutKeyAction.kt +++ b/src/main/java/com/maddyhome/idea/vim/action/VimShortcutKeyAction.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.project.DumbAware import com.intellij.openapi.util.Key +import com.intellij.openapi.util.registry.Registry import com.intellij.ui.KeyStrokeAdapter import com.maddyhome.idea.vim.KeyHandler import com.maddyhome.idea.vim.VimPlugin @@ -35,6 +36,7 @@ import com.maddyhome.idea.vim.helper.HandlerInjector import com.maddyhome.idea.vim.helper.inInsertMode import com.maddyhome.idea.vim.helper.inNormalMode import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere +import com.maddyhome.idea.vim.helper.isNotEditorContextComponent import com.maddyhome.idea.vim.helper.isPrimaryEditor import com.maddyhome.idea.vim.helper.isTemplateActive import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes @@ -127,6 +129,13 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ { ) } } + if (e.dataContext.isNotEditorContextComponent && Registry.`is`("ideavim.only.in.editor.component")) { + // Note: Currently, IdeaVim works ONLY in the editor component. However, the presence of the + // PlatformDataKeys.EDITOR in the data context does not mean that the current focused component is editor. + // Note2: The registry key is needed for quick disabling in case something gets broken. It can be removed after + // some time if no issues are found. + return ActionEnableStatus.no("Context component is not editor", LogLevel.INFO) + } if (editor.isIdeaVimDisabledHere) { return ActionEnableStatus.no("IdeaVim is disabled in this place", LogLevel.INFO) } diff --git a/src/main/java/com/maddyhome/idea/vim/helper/EditorHelper.kt b/src/main/java/com/maddyhome/idea/vim/helper/EditorHelper.kt index 1b68c2a20..66d10f9b2 100644 --- a/src/main/java/com/maddyhome/idea/vim/helper/EditorHelper.kt +++ b/src/main/java/com/maddyhome/idea/vim/helper/EditorHelper.kt @@ -11,9 +11,12 @@ package com.maddyhome.idea.vim.helper import com.intellij.codeWithMe.ClientId +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.editor.Caret import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.ex.util.EditorUtil +import com.intellij.openapi.editor.impl.EditorComponentImpl import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx import com.intellij.util.ui.table.JBTableRowEditor import com.maddyhome.idea.vim.api.StringListOptionValue @@ -98,3 +101,9 @@ internal val Caret.vimLine: Int */ internal val Editor.vimLine: Int get() = this.caretModel.currentCaret.vimLine + +internal val DataContext.isNotEditorContextComponent: Boolean + get() { + val contextComponent = this.getData(PlatformDataKeys.CONTEXT_COMPONENT) ?: return true + return contextComponent !is EditorComponentImpl + } \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index ecba5060d..924345942 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -131,6 +131,8 @@ order="first"/> <editorFactoryDocumentListener implementation="com.maddyhome.idea.vim.listener.VimListenerManager$VimDocumentListener"/> + <registryKey defaultValue="true" description="Enable IdeaVim only in editor component and project tree" + key="ideavim.only.in.editor.component"/> </extensions> <xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/>