Skip to content

Commit

Permalink
Disable IdeaVim listeners in places where IdeaVim is disabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlexPl292 committed Feb 14, 2025
1 parent 693bb50 commit 83b92d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -734,6 +737,7 @@ internal object VimListenerManager {
}

override fun mousePressed(event: EditorMouseEvent) {
if (event.editor.isIdeaVimDisabledHere) return
MouseEventsDataHolder.dragEventCount = MouseEventsDataHolder.allowedSkippedDragEvents
SelectionVimListenerSuppressor.reset()
}
Expand All @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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 -> {
Expand Down

0 comments on commit 83b92d8

Please sign in to comment.