[VIM-3541]Can't escape out of insert mode in read-only files #1296
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug description
Steps to reproduce
"http request", hit Enteri)Expected result (correct behavior)
If you navigate to a read-only file while in insert mode, you should either:
Actual result (faulty behavior)
If you navigate to a read-only file while in insert mode, you remain in insert mode.
You cannot escape into normal mode. To get around this, you must:
Solution
I opted for limiting the command executed in read-only files to the ones that do not change, or allow to change its contents.
I have noticed that this bug was actually happening in more situations that the one described. As the mode always changes automatically to Normal when focusing in a non writable editor, all that is really needed is to prevent any command that changes or allows content changing (like switching to insert mode, pasting, etc).
What I did is a simply one-line change that blocks the execution of any command with an action that extends from ChangeEditorActionHandler class when the editor is not writable. Simple but effective