helix
helix copied to clipboard
For removing empty scratch buffers, check that a buffer is empty rather than unmodified
This should fix #3305, although I am on a Mac, so I cannot test it myself.
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?
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
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.
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?
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.
I think you should just be able to use doc.line_ending = encoding, no?
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.
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.