1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-23 22:34:02 +02:00

Fix(VIM-3640): Enable IdeaVim only in the editor context component

As the GitHub Copilot is placed right in the editor component, the IdeaVim's actions are also collected. Action promoter promotes the IdeaVim's action and, since the data context has the editor, executes a Vim's actions like backspace.
Now we make sure that IdeaVim works only in the actual editor.
Since this change may affect some places where the IdeaVim used to work, but won't work now (this will be a surprise), a registry key is introduced to help the users that face this problem.
This commit is contained in:
Alex Plate 2025-01-24 13:34:08 +02:00
parent 7573d83898
commit e358dc9cee
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
3 changed files with 20 additions and 0 deletions
src/main
java/com/maddyhome/idea/vim
resources/META-INF

View File

@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.util.Key import com.intellij.openapi.util.Key
import com.intellij.openapi.util.registry.Registry
import com.intellij.ui.KeyStrokeAdapter import com.intellij.ui.KeyStrokeAdapter
import com.maddyhome.idea.vim.KeyHandler import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin 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.inInsertMode
import com.maddyhome.idea.vim.helper.inNormalMode import com.maddyhome.idea.vim.helper.inNormalMode
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere 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.isPrimaryEditor
import com.maddyhome.idea.vim.helper.isTemplateActive import com.maddyhome.idea.vim.helper.isTemplateActive
import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes 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) { if (editor.isIdeaVimDisabledHere) {
return ActionEnableStatus.no("IdeaVim is disabled in this place", LogLevel.INFO) return ActionEnableStatus.no("IdeaVim is disabled in this place", LogLevel.INFO)
} }

View File

@ -11,9 +11,12 @@
package com.maddyhome.idea.vim.helper package com.maddyhome.idea.vim.helper
import com.intellij.codeWithMe.ClientId 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.Caret
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.util.EditorUtil 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.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.util.ui.table.JBTableRowEditor import com.intellij.util.ui.table.JBTableRowEditor
import com.maddyhome.idea.vim.api.StringListOptionValue import com.maddyhome.idea.vim.api.StringListOptionValue
@ -98,3 +101,9 @@ internal val Caret.vimLine: Int
*/ */
internal val Editor.vimLine: Int internal val Editor.vimLine: Int
get() = this.caretModel.currentCaret.vimLine get() = this.caretModel.currentCaret.vimLine
internal val DataContext.isNotEditorContextComponent: Boolean
get() {
val contextComponent = this.getData(PlatformDataKeys.CONTEXT_COMPONENT) ?: return true
return contextComponent !is EditorComponentImpl
}

View File

@ -131,6 +131,8 @@
order="first"/> order="first"/>
<editorFactoryDocumentListener <editorFactoryDocumentListener
implementation="com.maddyhome.idea.vim.listener.VimListenerManager$VimDocumentListener"/> 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> </extensions>
<xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/> <xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/>