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 625d5a3017..fd8a8f3852 100644 --- a/src/main/java/com/maddyhome/idea/vim/listener/VimListenerManager.kt +++ b/src/main/java/com/maddyhome/idea/vim/listener/VimListenerManager.kt @@ -91,6 +91,7 @@ import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset import com.maddyhome.idea.vim.helper.resetVimLastColumn import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes import com.maddyhome.idea.vim.helper.vimDisabled +import com.maddyhome.idea.vim.helper.vimInitialised import com.maddyhome.idea.vim.newapi.IjVimEditor import com.maddyhome.idea.vim.newapi.InsertTimeRecorder import com.maddyhome.idea.vim.newapi.ij @@ -276,6 +277,11 @@ internal object VimListenerManager { // editor's disposable individually. val disposable = editor.project?.vimDisposable ?: return + // Protect against double initialisation + if (editor.getUserData(editorListenersDisposableKey) != null) { + return + } + val listenersDisposable = Disposer.newDisposable(disposable) editor.putUserData(editorListenersDisposableKey, listenersDisposable) @@ -468,6 +474,9 @@ internal object VimListenerManager { (it.fileEditor as? TextEditor)?.editor?.let { editor -> if (vimDisabled(editor)) return@let + // Protect against double initialisation, in case the editor was already initialised in editorCreated + if (editor.vimInitialised) return@let + val openingEditor = editor.removeUserData(openingEditorKey) val owningEditorWindow = getOwningEditorWindow(editor) val isInSameSplit = owningEditorWindow == openingEditor?.owningEditorWindow