Skip to content

Commit

Permalink
Fix rider issues with the new handler
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Oct 20, 2023
1 parent 69af9ae commit af7bdb5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/handler/VimEnterHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.maddyhome.idea.vim.handler

import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater
Expand Down Expand Up @@ -119,6 +120,7 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
* - Lookup - doesn't intersect with enter anymore
* - App code - set handler after
* - Template - doesn't intersect with enter anymore
* - rd.client.editor.enter - set handler before. Otherwise, rider will add new line on enter even in normal mode
*/
internal class VimEnterHandler(nextHandler: EditorActionHandler?) : VimKeyHandler(nextHandler) {
override val key: String = "<CR>"
Expand All @@ -136,7 +138,7 @@ internal class VimEnterHandler(nextHandler: EditorActionHandler?) : VimKeyHandle
* Known conflicts & solutions:
*
* - Smart step into - set handler after
* - Python notebooks - set handler before - yes, we have <CR> as "after" and <esc> as before. I'm not completely sure
* - Python notebooks - set handler before - yes, we have `<CR>` as "after" and `<esc>` as before. I'm not completely sure
* why this combination is correct, but other versions don't work.
* - Ace jump - set handler after
* - Lookup - It disappears after putting our esc before templateEscape. But I'm not sure why it works like that
Expand All @@ -156,6 +158,24 @@ internal class VimEscHandler(nextHandler: EditorActionHandler) : VimKeyHandler(n
}
}

/**
* Rider uses a separate handler for esc to close the completion. IdeaOnlyEscapeHandlerAction is especially
* designer to get all the esc presses, and if there is a completion close it and do not pass the execution further.
* This doesn't work the same as in IJ.
* In IdeaVim, we'd like to exit insert mode on closing completion. This is a requirement as the change of this
* behaviour causes a lot of complaining from users. Since the rider handler gets execution control, we don't
* receive an event and don't exit the insert mode.
* To fix it, this special handler exists only for rider and stands before the rider's handler. We don't execute the
* handler from rider because the autocompletion is closed automatically anyway.
*/
internal class VimEscForRiderHandler(nextHandler: EditorActionHandler) : VimKeyHandler(nextHandler) {
override val key: String = "<Esc>"

override fun isHandlerEnabled(editor: Editor, dataContext: DataContext?): Boolean {
return LookupManager.getActiveLookup(editor) != null
}
}

internal abstract class VimKeyHandler(nextHandler: EditorActionHandler?) : OctopusHandler(nextHandler) {

abstract val key: String
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/ides/ideavim-withRider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@
<listener class="com.maddyhome.idea.vim.listener.RiderActionListener"
topic="com.intellij.openapi.actionSystem.ex.AnActionListener"/>
</projectListeners>

<extensions defaultExtensionNs="com.intellij">
<editorActionHandler action="EditorEscape"
implementationClass="com.maddyhome.idea.vim.handler.VimEscForRiderHandler"
id="ideavim-rider-esc"
order="first, before idea.only.escape"/>
</extensions>
</idea-plugin>
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<!-- Do not care about red handlers in order. They are necessary for proper ordering, and they'll be resolved when needed -->
<editorActionHandler action="EditorEnter" implementationClass="com.maddyhome.idea.vim.handler.VimEnterHandler"
id="ideavim-enter"
order="before editorEnter, after smart-step-into-enter, after AceHandlerEnter, after jupyterCommandModeEnterKeyHandler, after swift.placeholder.enter"/>
order="before editorEnter, before rd.client.editor.enter, after smart-step-into-enter, after AceHandlerEnter, after jupyterCommandModeEnterKeyHandler, after swift.placeholder.enter"/>
<editorActionHandler action="EditorEnter" implementationClass="com.maddyhome.idea.vim.handler.CaretShapeEnterEditorHandler"
id="ideavim-enter-shape"
order="before jupyterCommandModeEnterKeyHandler"/>
Expand Down

0 comments on commit af7bdb5

Please sign in to comment.