-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix :w in insert mode #2883
Fix :w in insert mode #2883
Conversation
Nice fix, thanks. I was unable to bind anything to ":w" in insert, was unsure if I was doing it wrong or if it was not currently possible with keybinds in The following
|
I can't reproduce that - running exactly that configuration file on 22.05 works and |
That is correct. I think we are all describing the same behavior. Maybe I wasn't clear. As described by you and xDarksome. v22.05 does not clear the dirty bit (It does save the file). Didn't actually check to see if it saved the file, because that wasn't the bug. ...checking now. With my config and v22.05, file is saved, but file is still shown as dirty. With minimal config I'm pretty sure that is the same behavior the-mikedavis is describing. If we still conflict, more info about my build:
|
Oh I see, I mis-parsed your comment as saying that helix was rejecting that keybinding config 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helix-view/src/document.rs
Outdated
if let Some(view_id) = view_id { | ||
transaction = transaction.with_selection(self.selection(view_id).clone()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this isn't correct, the code assumes there's always a selection so we have the previous selection stored when undoing. The editor will probably panic otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @archseer. I assume this was done because in the save function call, you don't have a view associated with it. The solution isn't to just do whatever you can without it and hope it works out. This will leave the last edit in the history without a selection, which at best will make a very confusing and invisible undo operation, and at worst make the editor crash.
#2267 will not fix this either. The reason this is happening is because the modified flag is controlled by the revision number, which gets changed every time we commit changes to the history of edits for the purposes of tracking undos, and then make further changes. When the document's revision number is equal to the last revision number we saved to disk, the state is unmodified.
The way helix works as a modal editor is that you make your edits by going into insert mode, making your edits, and then leaving insert mode to go back to normal mode. This cycle of normal mode → insert mode → normal mode is the unit of discrete state changes to the text, and it's during the state transition from insert mode to normal mode that changes are recorded.
By trying to commit the changes while still in insert mode, you are breaking some key assumptions about how state changes are tracked. You shouldn't do it.
Your life would be made easier if you actually adopted the modal editing paradigm, instead of trying to make a modal editor into a non-modal editor.
Workaround:
|
Fixed by #11062 |
Currently, when you bind
"C-s" = ":w"
in insert mode and try to use it, the file is being written, but changes are considered not committed yet. Because of that helix complains on:q
and still shows[+]
in the status bar.Tell me if there is better way to fix this.