helix icon indicating copy to clipboard operation
helix copied to clipboard

For removing empty scratch buffers, check that a buffer is empty rather than unmodified

Open Omnikar opened this issue 2 years ago • 8 comments

This should fix #3305, although I am on a Mac, so I cannot test it myself.

Omnikar avatar Aug 02 '22 19:08 Omnikar

Actually, I feel like we should instead be marking buffers created from stdin as modified, since they contain unsaved content and should be protected from being lost, right?

Omnikar avatar Aug 02 '22 19:08 Omnikar

I'm not sure how useful it would be (for example for undoing) but it's intuitive to me that the text from stdin would be a revision in the history as well

the-mikedavis avatar Aug 02 '22 21:08 the-mikedavis

I'm not sure how useful it would be (for example for undoing) but it's intuitive to me that the text from stdin would be a revision in the history as well

There's of course also the aspect of preventing exiting the editor if the content isn't saved somewhere.

Omnikar avatar Aug 02 '22 21:08 Omnikar

How should I go about marking stdin scratch buffers as modified? Create them as an empty scratch buffer then add the text given by stdin as a change?

Omnikar avatar Aug 02 '22 21:08 Omnikar

In the new_file_from_stdin function in helix_view::editor, creating an empty Document using Document::default() rather than the current document creation via Document::from does not take the encoding value, and the .set_encoding method seems to take a different type.

Omnikar avatar Aug 02 '22 22:08 Omnikar

I think you should just be able to use doc.line_ending = encoding, no?

the-mikedavis avatar Aug 03 '22 12:08 the-mikedavis

I think you should just be able to use doc.line_ending = encoding, no?

encoding is of type &encoding::Encoding. Document::set_encoding takes type &str. Document::line_ending is of type helix_core::line_ending::LineEnding.

Omnikar avatar Aug 06 '22 03:08 Omnikar

Oh whoops I meant doc.encoding 😅. Looks like that's a private field though and set_encoding doesn't take an encoding type as you say. Given that set_encoding is only used by helix_term::commands::typed::set_encoding, I think it's best to refactor that function to do the encoding::Encoding::for_label call and have helix_view::document::Document::set_encoding just take an Encoding (and then it doesn't need to return a result).

IMO it's really helix_term::commands::typed::set_encoding's responsibility to parse the encoding anyways.

the-mikedavis avatar Aug 06 '22 11:08 the-mikedavis