diff --git a/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt b/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt index fc7e425f31..5b3a28ad7b 100644 --- a/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt +++ b/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2003-2023 The IdeaVim authors + * Copyright 2003-2026 The IdeaVim authors * * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE.txt file or at @@ -77,7 +77,6 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase( // Be careful: all the EditorActionHandler implementation should correctly process InjectedEditors // TBH, I don't like the names. Need to think a bit more about this val editor = editor.getTopLevelEditor() - val originalEditor = editor override var replaceMask: VimEditorReplaceMask? get() = editor.replaceMask set(value) { @@ -150,6 +149,7 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase( } } } + if (!isWritable()) return editor.document.insertString(atPosition, text) } diff --git a/src/test/java/org/jetbrains/plugins/ideavim/action/change/insert/InsertExitModeActionTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/action/change/insert/InsertExitModeActionTest.kt index c65fe84af8..637bcca63b 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/action/change/insert/InsertExitModeActionTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/action/change/insert/InsertExitModeActionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2003-2023 The IdeaVim authors + * Copyright 2003-2026 The IdeaVim authors * * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE.txt file or at @@ -38,6 +38,20 @@ class InsertExitModeActionTest : VimTestCase() { assertState("12${c}3") } + @Test + fun `esc with insert should check if file is writable`() { + configureByText("12${c}3") + typeText("10i1") + fixture.editor.document.setReadOnly(true) + + // escape trigger write 1 10 times + typeText("") + + // Should remain in normal mode + assertMode(Mode.NORMAL()) + assertState("121${c}3") + } + @Test fun `test cannot change text in read-only file with c motion`() { configureByText("12${c}3")