diff --git a/build.gradle.kts b/build.gradle.kts index 8dd0b07ad..527264a2b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -139,6 +139,8 @@ dependencies { "LATEST-EAP-SNAPSHOT", "2024.3" -> bundledPlugins("com.intellij.modules.json") else -> error("Unsupported version: $ideaVersion") } + + bundledPlugins("org.jetbrains.plugins.terminal") } moduleSources(project(":vim-engine", "sourcesJarArtifacts")) diff --git a/src/main/java/com/maddyhome/idea/vim/customization/feature/terminal/IdeaVimTerminalDisablerExtension.kt b/src/main/java/com/maddyhome/idea/vim/customization/feature/terminal/IdeaVimTerminalDisablerExtension.kt new file mode 100644 index 000000000..b39b5989a --- /dev/null +++ b/src/main/java/com/maddyhome/idea/vim/customization/feature/terminal/IdeaVimTerminalDisablerExtension.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2003-2025 The IdeaVim authors + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE.txt file or at + * https://opensource.org/licenses/MIT. + */ + +package com.maddyhome.idea.vim.customization.feature.terminal + +import com.intellij.openapi.editor.Editor +import com.maddyhome.idea.vim.key.IdeaVimDisablerExtensionPoint +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isAlternateBufferEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isOutputEditor +import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isPromptEditor + +/** + * The only implementation is defined right here. + */ +// [VERSION UPDATE] 2025.1+ Add 2 new predicates +internal class IdeaVimTerminalDisablerExtension : IdeaVimDisablerExtensionPoint { + override fun isDisabledForEditor(editor: Editor): Boolean { + return editor.isPromptEditor || editor.isOutputEditor || editor.isAlternateBufferEditor +// || editor.isOutputModelEditor || editor.isAlternateBufferModelEditor + } +} 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 f09e46b44..1b68c2a20 100644 --- a/src/main/java/com/maddyhome/idea/vim/helper/EditorHelper.kt +++ b/src/main/java/com/maddyhome/idea/vim/helper/EditorHelper.kt @@ -19,6 +19,7 @@ import com.intellij.util.ui.table.JBTableRowEditor import com.maddyhome.idea.vim.api.StringListOptionValue import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.group.IjOptionConstants +import com.maddyhome.idea.vim.key.IdeaVimDisablerExtensionPoint import com.maddyhome.idea.vim.newapi.globalIjOptions import java.awt.Component import javax.swing.JComponent @@ -37,7 +38,8 @@ internal val Editor.isIdeaVimDisabledHere: Boolean val ideaVimSupportValue = injector.globalIjOptions().ideavimsupport return (ideaVimDisabledInDialog(ideaVimSupportValue) && isInDialog()) || !ClientId.isCurrentlyUnderLocalId || // CWM-927 - (ideaVimDisabledForSingleLine(ideaVimSupportValue) && isSingleLine()) + (ideaVimDisabledForSingleLine(ideaVimSupportValue) && isSingleLine()) || + IdeaVimDisablerExtensionPoint.isDisabledForEditor(this) } private fun ideaVimDisabledInDialog(ideaVimSupportValue: StringListOptionValue): Boolean { diff --git a/src/main/java/com/maddyhome/idea/vim/key/IdeaVimDisablerExtensionPoint.kt b/src/main/java/com/maddyhome/idea/vim/key/IdeaVimDisablerExtensionPoint.kt new file mode 100644 index 000000000..35ca69ad4 --- /dev/null +++ b/src/main/java/com/maddyhome/idea/vim/key/IdeaVimDisablerExtensionPoint.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2003-2025 The IdeaVim authors + * + * Use of this source code is governed by an MIT-style + * license that can be found in the LICENSE.txt file or at + * https://opensource.org/licenses/MIT. + */ + +package com.maddyhome.idea.vim.key + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.extensions.ExtensionPointName + +/** + * This extension point is available only for the IdeaVim internally + */ +internal interface IdeaVimDisablerExtensionPoint { + fun isDisabledForEditor(editor: Editor): Boolean + + companion object { + private val EP_NAME = ExtensionPointName.create<IdeaVimDisablerExtensionPoint>("IdeaVIM.internal.disabler") + + fun isDisabledForEditor(editor: Editor): Boolean { + return EP_NAME.extensionList.any { it.isDisabledForEditor(editor) } + } + } +} diff --git a/src/main/resources/META-INF/features/ideavim-withTerminal.xml b/src/main/resources/META-INF/features/ideavim-withTerminal.xml new file mode 100644 index 000000000..ed500cbbf --- /dev/null +++ b/src/main/resources/META-INF/features/ideavim-withTerminal.xml @@ -0,0 +1,13 @@ +<!-- + ~ Copyright 2003-2025 The IdeaVim authors + ~ + ~ Use of this source code is governed by an MIT-style + ~ license that can be found in the LICENSE.txt file or at + ~ https://opensource.org/licenses/MIT. + --> + +<idea-plugin> + <extensions defaultExtensionNs="IdeaVIM"> + <internal.disabler implementation="com.maddyhome.idea.vim.customization.feature.terminal.IdeaVimTerminalDisablerExtension"/> + </extensions> +</idea-plugin> diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 91e9acf98..ecba5060d 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -36,6 +36,7 @@ <!--suppress PluginXmlValidity --> <depends optional="true" config-file="ides/ideavim-withAppCode.xml">com.intellij.modules.appcode</depends> <depends optional="true" config-file="ideavim-withAceJump.xml">AceJump</depends> + <depends optional="true" config-file="features/ideavim-withTerminal.xml">org.jetbrains.plugins.terminal</depends> <applicationListeners> <listener class="com.maddyhome.idea.vim.PyNotebooksCloseWorkaround" @@ -53,6 +54,8 @@ </extensionPoint> <extensionPoint interface="com.maddyhome.idea.vim.ide.ClionNovaProvider" dynamic="true" name="clionNovaProvider"/> + <extensionPoint interface="com.maddyhome.idea.vim.key.IdeaVimDisablerExtensionPoint" dynamic="true" + name="internal.disabler"/> </extensionPoints> <extensions defaultExtensionNs="com.intellij">