Skip to content

Commit

Permalink
Fix(VIM-3159): Shift-enter now works in normal mode again
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Nov 14, 2023
1 parent 1dc6045 commit 3db31e9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/main/java/com/maddyhome/idea/vim/handler/VimEnterHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
private fun isNotActualKeyPress(dataContext: DataContext?): Boolean {
if (dataContext != null) {
// This flag is set when the enter handlers are executed as a part of moving the comment on the new line
if (DataManager.getInstance()
.loadFromDataContext(dataContext, AutoHardWrapHandler.AUTO_WRAP_LINE_IN_PROGRESS_KEY) == true
) {
val dataManager = DataManager.getInstance()
if (dataManager.loadFromDataContext(dataContext, AutoHardWrapHandler.AUTO_WRAP_LINE_IN_PROGRESS_KEY) == true) {
return true
}

if (dataManager.loadFromDataContext(dataContext, ShiftEnterDetector.Util.key) == true) {
return true
}
}
Expand Down Expand Up @@ -240,6 +243,30 @@ internal class VimEscLoggerHandler(private val nextHandler: EditorActionHandler)
}
}

/**
* Workaround to support shift-enter in normal mode.
* IJ executes enter handler on shift-enter. This causes an issue that IdeaVim thinks that this is just an enter key.
* This thing should be refactored, but for now we'll use this workaround VIM-3159
*/
internal class ShiftEnterDetector(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
DataManager.getInstance().saveInDataContext(dataContext, Util.key, true)
nextHandler.execute(editor, caret, dataContext)
}

override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean {
return nextHandler.isEnabled(editor, caret, dataContext)
}

object Util {
val key = Key.create<Boolean>("vim.is.shift.enter")
}

companion object {
val LOG = logger<VimEscLoggerHandler>()
}
}

/**
* Empty logger for enter presses
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
<editorActionHandler action="EditorEnter" implementationClass="com.maddyhome.idea.vim.handler.VimEnterLoggerHandler"
id="ideavim-enter-logger"
order="first"/>
<editorActionHandler action="EditorStartNewLine"
implementationClass="com.maddyhome.idea.vim.handler.ShiftEnterDetector"
id="ideavim-shift-enter-detector"
order="first"/>
</extensions>

<xi:include href="/META-INF/includes/ApplicationServices.xml" xpointer="xpointer(/idea-plugin/*)"/>
Expand Down

0 comments on commit 3db31e9

Please sign in to comment.