zed icon indicating copy to clipboard operation
zed copied to clipboard

Newline inserted randomly when saving a file

Open tarek101 opened this issue 1 year ago • 5 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

When I save a file, sometimes newlines are inserted randomly in a line of code such as the one in the video https://github.com/zed-industries/zed/assets/45533264/b0fb1604-49a4-43b8-84d4-12b28a91c086

Environment

MacOS Ventura 13.2.1

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

tarek101 avatar Apr 11 '24 23:04 tarek101

~~There is a setting "ensure_final_newline_on_save" which adds an empty line to the end of the file on save if there isn't one and defaults to true. I'm pretty sure that is what you are seeing?~~

NVM this looks more like the autoformatter deciding to split the code for... some reason?

jansol avatar Apr 12 '24 00:04 jansol

Looks like auto-formatting. You can try to adjust your formatter configuration https://zed.dev/docs/javascript.

Congyuwang avatar Apr 12 '24 04:04 Congyuwang

My file is c++ (extension .cxx) not javascript and the auto-formatting was not a good experience adding newlines everywhere in a large code file, sometimes unnecessarily breaking code comments into multiple lines with or without adding the comment symbol with each line and overwriting my edits. Even worse, there is no simple way to disable it. As a newbie to Zed, the impression I got is that saving is not a reliable operation and I immediately started to look for other editors. Auto-formatting should be an option disabled by default, even if it makes the code look better, with a simple way to enable/disable it from the settings page and a user should be able to do it for a portion of the code in the right-click menu of a selected code.

tarek101 avatar Apr 13 '24 01:04 tarek101

  "format_on_save": "off"

Seems pretty simple to me. Unless by "simple" you meant a checkbox on a graphical settings page.

Either way, formatting is disabled by default for C and C++ code starting from version 0.132.0.

jansol avatar Apr 13 '24 01:04 jansol

A new user would naturally use CMD+, to open the settings page, to find only the two options about the font sizes with a comment to open another page to see a full list of options (the comment might not be even read by some users). In the other page, the user finds a ton of other flags, and without asking here, he will have to read every line to reach a flag for auto-formatting, but he/she should know beforehand that such an option exists in the first place! It seems Zed is designed for power users.

tarek101 avatar Apr 13 '24 18:04 tarek101

"format_on_save": "off" doesn't solve the issue for html...

cristian-5 avatar Aug 05 '24 12:08 cristian-5