diff --git a/README.md b/README.md index dce4fdbfa..4c0f18197 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ IdeaVim is a Vim engine for JetBrains IDEs. #### Compatibility -IntelliJ IDEA, PyCharm, CLion, PhpStorm, WebStorm, RubyMine, AppCode, DataGrip, GoLand, Rider, Cursive, +IntelliJ IDEA, PyCharm, CLion, PhpStorm, WebStorm, RubyMine, DataGrip, GoLand, Rider, Cursive, Android Studio and other IntelliJ platform based IDEs. Setup 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 70875f754..ea4b12ecc 100644 --- a/src/main/java/com/maddyhome/idea/vim/action/VimShortcutKeyAction.kt +++ b/src/main/java/com/maddyhome/idea/vim/action/VimShortcutKeyAction.kt @@ -44,7 +44,6 @@ import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes import com.maddyhome.idea.vim.key.ShortcutOwner import com.maddyhome.idea.vim.key.ShortcutOwnerInfo import com.maddyhome.idea.vim.listener.AceJumpService -import com.maddyhome.idea.vim.listener.AppCodeTemplates.appCodeTemplateCaptured import com.maddyhome.idea.vim.newapi.globalIjOptions import com.maddyhome.idea.vim.newapi.initInjector import com.maddyhome.idea.vim.newapi.vim @@ -182,10 +181,6 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ { return ActionEnableStatus.no("The key is tab and the template is active", LogLevel.INFO) } - if ((keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ENTER) && editor.appCodeTemplateCaptured()) { - return ActionEnableStatus.no("App code template is active", LogLevel.INFO) - } - if (editor.inInsertMode) { if (keyCode == KeyEvent.VK_TAB) { // TODO: This stops VimEditorTab seeing <Tab> in insert mode and correctly scrolling the view diff --git a/src/main/java/com/maddyhome/idea/vim/group/MotionGroup.kt b/src/main/java/com/maddyhome/idea/vim/group/MotionGroup.kt index 187caf058..4a343582b 100755 --- a/src/main/java/com/maddyhome/idea/vim/group/MotionGroup.kt +++ b/src/main/java/com/maddyhome/idea/vim/group/MotionGroup.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.fileEditor.impl.EditorWindow import com.maddyhome.idea.vim.KeyHandler import com.maddyhome.idea.vim.api.ExecutionContext import com.maddyhome.idea.vim.api.ImmutableVimCaret -import com.maddyhome.idea.vim.api.VimCaret import com.maddyhome.idea.vim.api.VimChangeGroupBase import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.VimMotionGroupBase @@ -48,7 +47,6 @@ import com.maddyhome.idea.vim.helper.getNormalizedSideScrollOffset import com.maddyhome.idea.vim.helper.isEndAllowed import com.maddyhome.idea.vim.helper.vimLastColumn import com.maddyhome.idea.vim.impl.state.VimStateMachineImpl -import com.maddyhome.idea.vim.listener.AppCodeTemplates import com.maddyhome.idea.vim.newapi.IjEditorExecutionContext import com.maddyhome.idea.vim.newapi.ij import com.maddyhome.idea.vim.newapi.vim @@ -62,10 +60,6 @@ import kotlin.math.min */ @Service internal class MotionGroup : VimMotionGroupBase() { - override fun onAppCodeMovement(editor: VimEditor, caret: VimCaret, offset: Int, oldOffset: Int) { - AppCodeTemplates.onMovement(editor.ij, caret.ij, oldOffset < offset) - } - override fun moveCaretToFirstDisplayLine( editor: VimEditor, caret: ImmutableVimCaret, diff --git a/src/main/java/com/maddyhome/idea/vim/listener/AppCodeTemplates.kt b/src/main/java/com/maddyhome/idea/vim/listener/AppCodeTemplates.kt deleted file mode 100644 index 6700ce8a6..000000000 --- a/src/main/java/com/maddyhome/idea/vim/listener/AppCodeTemplates.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2003-2023 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.listener - -import com.intellij.openapi.actionSystem.ActionManager -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.AnActionResult -import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.actionSystem.IdeActions -import com.intellij.openapi.actionSystem.ex.AnActionListener -import com.intellij.openapi.editor.Caret -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.Key -import com.maddyhome.idea.vim.KeyHandler -import com.maddyhome.idea.vim.VimPlugin -import com.maddyhome.idea.vim.api.injector -import com.maddyhome.idea.vim.group.visual.VimVisualTimer -import com.maddyhome.idea.vim.helper.fileSize -import com.maddyhome.idea.vim.helper.inVisualMode -import com.maddyhome.idea.vim.newapi.vim - -/** - * A collection of hacks to improve the interaction with fancy AppCode templates - */ -internal object AppCodeTemplates { - private val facedAppCodeTemplate = Key.create<IntRange>("FacedAppCodeTemplate") - - private const val TEMPLATE_START = "<#T##" - private const val TEMPLATE_END = "#>" - - class ActionListener : AnActionListener { - - private var editor: Editor? = null - - override fun beforeActionPerformed(action: AnAction, event: AnActionEvent) { - if (VimPlugin.isNotEnabled()) return - - val hostEditor = event.dataContext.getData(CommonDataKeys.HOST_EDITOR) - if (hostEditor != null) { - editor = hostEditor - } - } - - override fun afterActionPerformed(action: AnAction, event: AnActionEvent, result: AnActionResult) { - if (VimPlugin.isNotEnabled()) return - - if (ActionManager.getInstance().getId(action) == IdeActions.ACTION_CHOOSE_LOOKUP_ITEM) { - val myEditor = editor - if (myEditor != null) { - VimVisualTimer.doNow() - if (myEditor.inVisualMode) { - injector.visualMotionGroup.toggleSelectVisual(myEditor.vim) - KeyHandler.getInstance().partialReset(myEditor.vim) - } - } - } - } - } - - @JvmStatic - fun onMovement( - editor: Editor, - caret: Caret, - toRight: Boolean, - ) { - val offset = caret.offset - val offsetRightEnd = offset + TEMPLATE_START.length - val offsetLeftEnd = offset - 1 - val templateRange = caret.getUserData(facedAppCodeTemplate) - if (templateRange == null) { - if (offsetRightEnd < editor.fileSize && - editor.document.charsSequence.subSequence(offset, offsetRightEnd).toString() == TEMPLATE_START - ) { - caret.shake() - - val templateEnd = editor.findTemplateEnd(offset) ?: return - - caret.putUserData(facedAppCodeTemplate, offset..templateEnd) - } - if (offsetLeftEnd >= 0 && - offset + 1 <= editor.fileSize && - editor.document.charsSequence.subSequence(offsetLeftEnd, offset + 1).toString() == TEMPLATE_END - ) { - caret.shake() - - val templateStart = editor.findTemplateStart(offsetLeftEnd) ?: return - - caret.putUserData(facedAppCodeTemplate, templateStart..offset) - } - } else { - if (offset in templateRange) { - if (toRight) { - caret.moveToOffset(templateRange.last + 1) - } else { - caret.moveToOffset(templateRange.first) - } - } - caret.putUserData(facedAppCodeTemplate, null) - caret.shake() - } - } - - fun Editor.appCodeTemplateCaptured(): Boolean { - return this.caretModel.allCarets.any { it.getUserData(facedAppCodeTemplate) != null } - } - - private fun Caret.shake() { - moveCaretRelatively(1, 0, false, false) - moveCaretRelatively(-1, 0, false, false) - } - - private fun Editor.findTemplateEnd(start: Int): Int? { - val charSequence = this.document.charsSequence - val length = charSequence.length - for (i in start until length - 1) { - if (charSequence[i] == TEMPLATE_END[0] && charSequence[i + 1] == TEMPLATE_END[1]) { - return i + 1 - } - } - return null - } - - private fun Editor.findTemplateStart(start: Int): Int? { - val charSequence = this.document.charsSequence - val templateLastIndex = TEMPLATE_START.length - for (i in start downTo templateLastIndex) { - if (charSequence.subSequence(i - templateLastIndex, i).toString() == TEMPLATE_START) { - return i - templateLastIndex - } - } - return null - } -} diff --git a/src/main/resources/META-INF/ides/ideavim-withAppCode.xml b/src/main/resources/META-INF/ides/ideavim-withAppCode.xml deleted file mode 100644 index 9c92949b3..000000000 --- a/src/main/resources/META-INF/ides/ideavim-withAppCode.xml +++ /dev/null @@ -1,14 +0,0 @@ -<!-- - ~ Copyright 2003-2023 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> - <projectListeners> - <listener class="com.maddyhome.idea.vim.listener.AppCodeTemplates$ActionListener" - topic="com.intellij.openapi.actionSystem.ex.AnActionListener"/> - </projectListeners> -</idea-plugin> \ 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 924345942..068f55374 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -33,8 +33,6 @@ <depends optional="true" config-file="ides/ideavim-withRider.xml">com.intellij.modules.rider</depends> <!--suppress PluginXmlValidity --> <depends optional="true" config-file="ides/ideavim-withClionNova.xml">org.jetbrains.plugins.clion.radler</depends> - <!--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> diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt index 999577a74..835d32fa1 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt @@ -116,7 +116,6 @@ per-caret marks. editor.exitVisualMode() updatedCaret } - injector.motion.onAppCodeMovement(editor, this, offset, oldOffset) return updatedCaret } diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimMotionGroup.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimMotionGroup.kt index cde5a4cfc..d66414ffb 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimMotionGroup.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimMotionGroup.kt @@ -157,5 +157,4 @@ interface VimMotionGroup { // TODO: These aren't caret motions. Should be moved to VimWindowGroup? fun moveCaretGotoNextTab(editor: VimEditor, context: ExecutionContext, rawCount: Int): Int fun moveCaretGotoPreviousTab(editor: VimEditor, context: ExecutionContext, rawCount: Int): Int - fun onAppCodeMovement(editor: VimEditor, caret: VimCaret, offset: Int, oldOffset: Int) }