-
-
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
bug: insert-final-newline
should only insert if file non-empty
#11967
Comments
I don't have a strong opinion on this - I would usually use |
I would like to see this fix, as I’ve noticed that Helix sometimes adds an extra line to |
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index c7d7a757..1c59340c 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -375,7 +375,7 @@ fn write_impl(
fn insert_final_newline(doc: &mut Document, view_id: ViewId) {
let text = doc.text();
- if line_ending::get_line_ending(&text.slice(..)).is_none() {
+ if text.len_chars() > 0 && line_ending::get_line_ending(&text.slice(..)).is_none() {
let eof = Selection::point(text.len_chars());
let insert = Transaction::insert(text, &eof, doc.line_ending.as_str().into());
doc.apply(&insert, view_id); the fix is pretty simple and straightforward ↑ |
@Axlefublr Would you like to prepare PR with these changes? |
only if I get some certainty it will get accepted. I despise keeping a PR branch up to date only for it to be ignored for 3 years and then get rejected |
I have the solution ready and am ready to PR it, but I'd want to first ensure this is wanted by the maintainers;
The
insert-final-newline
option ensures the final newline always, even if the file is empty otherwise.With this option enabled, you effectively cannot save an empty file, which is silly.
Do you also consider it a bug? Or is it somehow intended behavior?
The text was updated successfully, but these errors were encountered: