From c22545243282c1c60560df51a92049ce1e9ad640 Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Wed, 18 Dec 2024 13:19:14 +0200 Subject: [PATCH] [VIM-3577] Store the information if the editor was initialized in insert mode --- .../com/maddyhome/idea/vim/listener/IJEditorFocusListener.kt | 5 +++-- .../src/main/kotlin/com/maddyhome/idea/vim/KeyHandler.kt | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/maddyhome/idea/vim/listener/IJEditorFocusListener.kt b/src/main/java/com/maddyhome/idea/vim/listener/IJEditorFocusListener.kt index a3616b4285..28932d87fb 100644 --- a/src/main/java/com/maddyhome/idea/vim/listener/IJEditorFocusListener.kt +++ b/src/main/java/com/maddyhome/idea/vim/listener/IJEditorFocusListener.kt @@ -59,15 +59,16 @@ class IJEditorFocusListener : EditorListener { val ijEditor = editor.ij val isCurrentEditorTerminal = isTerminal(ijEditor) - KeyHandler.getInstance().lastUsedEditorInfo = LastUsedEditorInfo(currentEditorHashCode, isCurrentEditorTerminal) + KeyHandler.getInstance().lastUsedEditorInfo = LastUsedEditorInfo(currentEditorHashCode, false) val switchToInsertMode = Runnable { val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor) VimPlugin.getChange().insertBeforeCursor(editor, context) + KeyHandler.getInstance().lastUsedEditorInfo = LastUsedEditorInfo(currentEditorHashCode, true) } if (isCurrentEditorTerminal && !ijEditor.inInsertMode) { switchToInsertMode.run() - } else if (ijEditor.isInsertMode && (oldEditorInfo.isTerminal || !ijEditor.document.isWritable)) { + } else if (ijEditor.isInsertMode && (oldEditorInfo.isInsertModeForced || !ijEditor.document.isWritable)) { val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor) val mode = injector.vimState.mode when (mode) { diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/KeyHandler.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/KeyHandler.kt index e9b2306189..289f55a4aa 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/KeyHandler.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/KeyHandler.kt @@ -479,5 +479,8 @@ typealias KeyProcessing = (KeyHandlerState, VimEditor, ExecutionContext) -> Unit data class LastUsedEditorInfo( val hash: Int, - val isTerminal: Boolean, + /** + * If true, this editor was initialized in insert mode + */ + val isInsertModeForced: Boolean, ) \ No newline at end of file