Skip to content

Commit 762e20f

Browse files
committed
VIM-4084 Ensure insert mode respects file's writable state
1 parent ca298b1 commit 762e20f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2003-2023 The IdeaVim authors
2+
* Copyright 2003-2026 The IdeaVim authors
33
*
44
* Use of this source code is governed by an MIT-style
55
* license that can be found in the LICENSE.txt file or at
@@ -77,7 +77,6 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase(
7777
// Be careful: all the EditorActionHandler implementation should correctly process InjectedEditors
7878
// TBH, I don't like the names. Need to think a bit more about this
7979
val editor = editor.getTopLevelEditor()
80-
val originalEditor = editor
8180
override var replaceMask: VimEditorReplaceMask?
8281
get() = editor.replaceMask
8382
set(value) {
@@ -150,6 +149,7 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase(
150149
}
151150
}
152151
}
152+
if (!isWritable()) return
153153
editor.document.insertString(atPosition, text)
154154
}
155155

src/test/java/org/jetbrains/plugins/ideavim/action/change/insert/InsertExitModeActionTest.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2003-2023 The IdeaVim authors
2+
* Copyright 2003-2026 The IdeaVim authors
33
*
44
* Use of this source code is governed by an MIT-style
55
* license that can be found in the LICENSE.txt file or at
@@ -38,6 +38,20 @@ class InsertExitModeActionTest : VimTestCase() {
3838
assertState("12${c}3")
3939
}
4040

41+
@Test
42+
fun `esc with insert should check if file is writable`() {
43+
configureByText("12${c}3")
44+
typeText("10i1")
45+
fixture.editor.document.setReadOnly(true)
46+
47+
// escape trigger write 1 10 times
48+
typeText("<Esc>")
49+
50+
// Should remain in normal mode
51+
assertMode(Mode.NORMAL())
52+
assertState("121${c}3")
53+
}
54+
4155
@Test
4256
fun `test cannot change text in read-only file with c motion`() {
4357
configureByText("12${c}3")

0 commit comments

Comments
 (0)