Skip to content
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

Possible to icorrectly remove dirty buffer state and so quit under certain conditions #9619

Closed
scimas opened this issue Feb 12, 2024 · 5 comments · Fixed by #9625
Closed
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@scimas
Copy link
Contributor

scimas commented Feb 12, 2024

Summary

It is possible to get helix to forget that the buffer is dirty and it shouldn't allow quitting without saving under certain conditions. Works with both scratch buffer and when editing a file.

Reproduction Steps

Follow the exact keystrokes:
hx

Inside helix:
i -> h (any single character insert is fine) -> <esc> -> :clipboard-paste-replace<CR> -> u -> u (at this point the dirty buffer indicator (the plus sign in the status line) goes away -> :q<CR>

This allows you to quit, even though the h character is still in the buffer. The steps work for editing a file also with an additional keystroke after the <esc> to move the cursor onto the h character.

Helix log

~/.cache/helix/helix.log
2024-02-12T18:37:33.260 helix_view::clipboard [DEBUG] Using xsel to interact with the system and selection (primary) clipboard
2024-02-12T18:37:33.263 helix_tui::backend::crossterm [DEBUG] The keyboard enhancement protocol is not supported in this terminal (checked in 2.711014ms)
2024-02-12T18:37:33.263 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:33.511 helix_term::application [DEBUG] received editor event: IdleTimer
2024-02-12T18:37:34.604 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:35.451 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:35.702 helix_term::application [DEBUG] received editor event: IdleTimer
2024-02-12T18:37:35.703 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:36.597 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:36.598 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:36.956 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:37.208 helix_term::application [DEBUG] received editor event: IdleTimer
2024-02-12T18:37:37.418 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:37.493 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:37.674 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:37.762 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:37.869 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:38.895 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 1
2024-02-12T18:37:40.500 helix_view::editor [DEBUG] editor status: Already at oldest change
2024-02-12T18:37:40.501 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 2
2024-02-12T18:37:40.752 helix_term::application [DEBUG] received editor event: IdleTimer
2024-02-12T18:37:41.104 helix_view::view [DEBUG] Syncing view ViewId(2v1) between 2 and 0
2024-02-12T18:37:41.104 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:41.354 helix_term::application [DEBUG] received editor event: IdleTimer
2024-02-12T18:37:41.940 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:42.136 helix_term::commands::typed [DEBUG] quitting...
2024-02-12T18:37:42.136 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:42.192 helix_term::application [DEBUG] received editor event: IdleTimer
2024-02-12T18:37:42.705 helix_term::commands::typed [DEBUG] quitting...
2024-02-12T18:37:42.705 helix_view::document [DEBUG] id 1 modified - last saved: 0, current: 0
2024-02-12T18:37:42.705 helix_term::job [DEBUG] waiting on jobs...
2024-02-12T18:37:42.705 helix_term::job [DEBUG] waiting on jobs...

Platform

Linux

Terminal Emulator

Konsole 23.08.4

Installation Method

Fedora dnf through varlad/helix

Helix Version

helix 23.10 (f6021dd)

@scimas scimas added the C-bug Category: This is a bug label Feb 12, 2024
@kirawi kirawi added the A-helix-term Area: Helix term improvements label Feb 13, 2024
@the-mikedavis
Copy link
Member

#5733 (comment) is related. We need to call Document::append_changes_to_history after modifying the document so that the change is saved in history. Currently clipboard replacement doesn't call that.

@scimas
Copy link
Contributor Author

scimas commented Feb 13, 2024

Is that as simple as calling doc.append_... after the apply?

@the-mikedavis
Copy link
Member

Yep that should do it. See here in paste where we do the same:

doc.apply(&transaction, view.id);
doc.append_changes_to_history(view);

@pascalkuthe
Copy link
Member

I think I simply missed that function in #5790 (so you should call ensure_cursor_in_view too)

@scimas
Copy link
Contributor Author

scimas commented Feb 13, 2024

Thanks for the feedback! Opened a PR with those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants