Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -150,6 +149,7 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor, VimEditorBase(
}
}
}
if (!isWritable()) return
editor.document.insertString(atPosition, text)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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("<Esc>")

// 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")
Expand Down
Loading