-
Notifications
You must be signed in to change notification settings - Fork 798
[VIM-3541] Prevent entering insert mode in read-only files #1283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Personally, I consider it reasonable for the "Clear Read-Only Status" dialog to pop up when attempting to enter insert mode, rather than preventing the user from entering it. Furthermore, checking solely upon entering insert mode is insufficient to resolve the issue entirely. The user could switch to another read-only file while in insert mode on a writable file, causing the mode to persist (as described in VIM-3563). |
@wxh06 |
Thank you for the review, and I apologize for overlooking the test case involving a manually made read-only file. I would like to ask for clarification on a few points. As I understand, the “Clear Read-Only Status” dialog is already implemented. However, it appears that this dialog does not appear immediately upon entering insert mode, but rather after a subsequent action. In this context, I see two possible scenarios:
Additionally, regarding VIM-3563: Once I hear your thoughts on the scenarios above, I will take them into consideration, along with VIM-3563, to ensure the implementation avoids reintroducing similar issues. Can you comment on this? @wxh06 |
@NaMinhyeok Thank you for your efforts; there's no need to apologise for this, as discussion is welcome. My apologies, I was mistaken about the behavior in VIM-3563 earlier. You were correct—it has been fully resolved. The scenario I attempted to describe earlier should be precisely what you mentioned: setting a writable file to read-only. I have no particular expectations regarding the behaviour in IdeaVim. Might @AlexPl292 have some expectations on this? Personally, I consider the inability to exit insert mode within read-only files to be a bug in itself. The primary fix should ensure that users can exit insert mode regardless of how they inadvertently entered it. |
Thanks for the thoughtful review. I agree that because the IntelliJ Platform prevents actual edits in read-only files, full parity with Vim isn't always attainable. Regarding the inconsistent dialog behavior I raised earlier (appearing immediately for This approach also solves the main concern you raised: being unable to exit insert mode. However, if IdeaVim prefers to follow Vim's default of allowing entry into insert mode, I am happy to adapt the patch to ensure I’ll also wait for @AlexPl292’s comment. |
Hello everyone, thank you for an interesting discussion to read. Now, let's split this question into two: Exiting the insert mode in read-only filesEven if we prohibit entering the insert mode in the read-only files, I believe we should properly support exiting the insert mode. The reason is that if the user appears in the insert mode by some magic reason, they should have the ability to exit it. Putting a read-only status in insert mode is a good example of such a magical reason. The esc and
Entering the insert mode in the read-only filesI've tried to enter insert mode for the help files in Vim, and it didn't allow me. So, I didn't see the case when we can enter the insert mode for the read-only files. But generally, this looks weird for me as the insert mode implies some kind of modification. I think, it makes sence to show a dialog right on Thank you for your interest in the question! If I missed some questions, please let me know. |
Thank you for the detailed review and guidance. Based on your feedback, I've summarized my understanding of the desired behavior into two cases. Could you please confirm if this is correct? Not Allow Writable Case (like Vim help files)
Writable Case (temporarily read-only files)
Just to clarify, in the writable case, if the file becomes writable by confirming the dialog, pressing ESC should only return to normal mode — not revert the file back to read-only, right? Additionally, I have reviewed and understood your proposal for the more complex but proper fix for the Esc key behavior, specifically regarding changing InsertExitModeAction to OTHER_SELF_SYNCHRONIZED and handling the write locks manually. I will attempt to implement a solution based on this direction and will share my progress. |
It is gratifying to learn that Vim also prevents users from entering insert mode, providing factual grounds for us to prohibit such actions (for instance, in decompiled files).
The warning message I mentioned earlier appears in files that are editable but lack write permissions. Upon attempting to save, an additional error message indicating the file cannot be saved will appear.
|
@NaMinhyeok Yes, I confirm.
Yes, I think not reverting the read-only is a better way. Thank you! |
@AlexPl292 Thank you for the guidance! I've implemented the solution following your suggestions:
The ESC key now works properly in read-only files without hanging, while preserving all existing functionality for writable files. I've also added tests to cover the read-only file scenarios. Sorry, I realized there are still some parts I need to refine further — I’ll update the patch soon. |
Signed-off-by: NaMinhyeok <[email protected]>
… ensure ESC functionality Signed-off-by: NaMinhyeok <[email protected]>
… operations Signed-off-by: NaMinhyeok <[email protected]>
Follow-up UpdateWhile refining the patch further, I realized there was another important case that needed attention. To make sure Key Issue Resolved:
|
Thank you for the updates and the detailed description! However, I would like to point out some concerns regarding the current changes:
Thank you! |
@claude /review |
Claude encountered an error —— View job
I'll analyze this and get back to you. |
I'm not sure about the change to The way More specifically, the argument is what comes after the operator, so Can you explain a bit more what this change is about, please? |
BTW, a good file to test this with would be |
Thank you both @AlexPl292 and @citizenmatt for the detailed feedback. I realize that both of my approaches were fundamentally flawed, and I appreciate you taking the time to explain the proper architecture and concerns. You're absolutely right that:
This is clearly not as easy as I initially thought, and I need to take a step back and understand the proper workflow and architecture better. I'll take the time to properly:
The core goal remains ensuring ESC always works in read-only files, but I need to do this properly within the existing architecture rather than working around it. I'll come back with a cleaner, more targeted approach once I've done the proper analysis. |
Fixes a bug where the
ESC
key does not properly exit insert mode in read-only files.This happens when users attempt insert commands (
i
,a
,o
) in read-only files (e.g.,.http
requests).Commands appear to succeed but leave the editor in an inconsistent state.
Root Cause
ESC
handler became confused, leaving the editor stuck.Solution
I considered two approaches:
Approach 1: Fix ESC behavior only
InsertExitModeAction
type fromINSERT
→MODE_CHANGE
Approach 2: Prevent insert mode entry in read-only files (chosen)
I'd appreciate feedback on whether this approach aligns with IdeaVim’s overall design philosophy.
Specifically:
Happy to add more test coverage or adjust the approach based on your feedback. Thanks in advance for reviewing!
Fixes VIM-3541 this issue has ideaVim-bounty tag