From 83b92d84a64cbfaddf7c79d14c968b43463e947b Mon Sep 17 00:00:00 2001 From: Alex Plate <aleksei.plate@jetbrains.com> Date: Fri, 14 Feb 2025 17:59:06 +0200 Subject: [PATCH] Disable IdeaVim listeners in places where IdeaVim is disabled This is needed for the new terminal. Before this change, it was impossible to put the caret at the line end, even taking the fact the IdeaVim is disabled in the new terminal. --- .../com/maddyhome/idea/vim/listener/RiderSpecifics.kt | 9 ++++++--- .../maddyhome/idea/vim/listener/VimListenerManager.kt | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/maddyhome/idea/vim/listener/RiderSpecifics.kt b/src/main/java/com/maddyhome/idea/vim/listener/RiderSpecifics.kt index 883a8abfb..e860be3d6 100644 --- a/src/main/java/com/maddyhome/idea/vim/listener/RiderSpecifics.kt +++ b/src/main/java/com/maddyhome/idea/vim/listener/RiderSpecifics.kt @@ -22,6 +22,7 @@ import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.group.visual.IdeaSelectionControl import com.maddyhome.idea.vim.group.visual.moveCaretOneCharLeftFromSelectionEnd import com.maddyhome.idea.vim.helper.getTopLevelEditor +import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere internal class RiderActionListener : AnActionListener { @@ -45,9 +46,11 @@ internal class RiderActionListener : AnActionListener { editor?.caretModel?.addCaretListener(object : CaretListener { override fun caretPositionChanged(event: CaretEvent) { val eventEditor = event.editor.getTopLevelEditor() - val predictedMode = - IdeaSelectionControl.predictMode(eventEditor, VimListenerManager.SelectionSource.OTHER) - moveCaretOneCharLeftFromSelectionEnd(eventEditor, predictedMode) + if (!eventEditor.isIdeaVimDisabledHere) { + val predictedMode = + IdeaSelectionControl.predictMode(eventEditor, VimListenerManager.SelectionSource.OTHER) + moveCaretOneCharLeftFromSelectionEnd(eventEditor, predictedMode) + } eventEditor.caretModel.removeCaretListener(this) } }) diff --git a/src/main/java/com/maddyhome/idea/vim/listener/VimListenerManager.kt b/src/main/java/com/maddyhome/idea/vim/listener/VimListenerManager.kt index c8cee2f56..07fd5a2b6 100644 --- a/src/main/java/com/maddyhome/idea/vim/listener/VimListenerManager.kt +++ b/src/main/java/com/maddyhome/idea/vim/listener/VimListenerManager.kt @@ -87,6 +87,7 @@ import com.maddyhome.idea.vim.helper.exitVisualMode import com.maddyhome.idea.vim.helper.forceBarCursor import com.maddyhome.idea.vim.helper.inVisualMode import com.maddyhome.idea.vim.helper.isEndAllowed +import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset import com.maddyhome.idea.vim.helper.resetVimLastColumn import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes @@ -642,7 +643,9 @@ internal object VimListenerManager { private var cutOffFixed = false override fun mouseDragged(e: EditorMouseEvent) { - val caret = e.editor.caretModel.primaryCaret + val editor = e.editor + if (editor.isIdeaVimDisabledHere) return + val caret = editor.caretModel.primaryCaret clearFirstSelectionEvents(e) @@ -734,6 +737,7 @@ internal object VimListenerManager { } override fun mousePressed(event: EditorMouseEvent) { + if (event.editor.isIdeaVimDisabledHere) return MouseEventsDataHolder.dragEventCount = MouseEventsDataHolder.allowedSkippedDragEvents SelectionVimListenerSuppressor.reset() } @@ -745,6 +749,7 @@ internal object VimListenerManager { * - Click-hold and switch editor (ctrl-tab) */ override fun mouseReleased(event: EditorMouseEvent) { + if (event.editor.isIdeaVimDisabledHere) return SelectionVimListenerSuppressor.unlock() clearFirstSelectionEvents(event) @@ -768,6 +773,7 @@ internal object VimListenerManager { } override fun mouseClicked(event: EditorMouseEvent) { + if (event.editor.isIdeaVimDisabledHere) return logger.debug("Mouse clicked") if (event.area == EditorMouseEventArea.EDITING_AREA) { @@ -829,6 +835,7 @@ internal object VimListenerManager { override fun mousePressed(e: MouseEvent?) { val editor = (e?.component as? EditorComponentImpl)?.editor ?: return + if (editor.isIdeaVimDisabledHere) return val predictedMode = IdeaSelectionControl.predictMode(editor, SelectionSource.MOUSE) when (e.clickCount) { 1 -> {