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

After python autosave, cursor moves to beginning of line #9787

Closed
1 task done
dacort opened this issue Mar 25, 2024 · 6 comments
Closed
1 task done

After python autosave, cursor moves to beginning of line #9787

dacort opened this issue Mar 25, 2024 · 6 comments
Labels
defect [core label] language An umbrella label for all programming languages syntax behaviors python Python programming language support setting Feedback for preferences, configuration, etc

Comments

@dacort
Copy link

dacort commented Mar 25, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

When autosave is enabled, saving a Python file with an empty method definition results in the cursor moving from an indented position to the beginning of the line, resulting in a frustrating dev experience.

Autosave setting:

  "autosave": {
    "after_delay": {
      "milliseconds": 1000
    }
  }

To reproduce:

  1. Create a new python file
  2. Start to populate with some Python class
class TestClass:
    def some_method(self):
        
  1. Wait for autosave
  2. Observe the cursor moving to the beginning of the line

Note that this happens even if the method definition is in the middle of a file. It appears to be related to the remove_trailing_whitespace_on_save setting - if I disable that, then the cursor remains in the same/correct position.

Similar to #7570 and #392

Environment

Zed: v0.127.4 (Zed)
OS: macOS 14.3.1
Memory: 36 GiB
Architecture: aarch64

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

@dacort dacort added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels Mar 25, 2024
@JosephTLyons JosephTLyons added python Python programming language support language An umbrella label for all programming languages syntax behaviors setting Feedback for preferences, configuration, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Mar 25, 2024
@JosephTLyons
Copy link
Collaborator

Hey @dacort, can you capture a screen video? I haven't been able to reproduce this on my end.

@dacort
Copy link
Author

dacort commented Mar 25, 2024

Sure thing!

zed_repro.mov

Note that the file must already exist - in an unsaved buffer, this doesn't happen.

@JosephTLyons
Copy link
Collaborator

Sure thing!

zed_repro.mov

Note that the file must already exist - in an unsaved buffer, this doesn't happen.

Oh ok, I see what you are experiencing now, I was typing before the autosave triggered, so the line was non-empty for me. Yeah this is sort of a tricky situation because that setting is meant to strip the trailing whitespace off all lines. What would be a good fix to this? An option in the autosaver to not run those operations that trim newlines and whitespace?

@dacort
Copy link
Author

dacort commented Mar 25, 2024

What would be a good fix to this?

This is a tough one since it's also language-dependent. I can think of a couple things off-hand:

  1. Don't modify the line the cursor is on, since it's likely the user is actively editing that line. A similar thing happens if I start to add a code comment (# ), pause to think, and then keep typing. But the strip trailing whitespace feature removes my space while I'm thinking.
  2. If the user has enabled their own external formatter, should this setting be disabled?
  3. As you mentioned, don't run autoformat on autosave

I kind of like option 3 or a variant of it as it seems the most flexible / least confusing. This is a workflow I use in other editors as well - I prefer the delayed autosave, particularly if I'm reloading something in the background, but like that I can manually trigger a format by saving manually. FWIW, this is the setting in VS Code. It doesn't run format on save if autosave with a delay is enabled.

image

@iamraphson
Copy link

It is happening in SQL autosave too.

@JosephTLyons JosephTLyons added python Python programming language support language An umbrella label for all programming languages syntax behaviors and removed python Python programming language support language An umbrella label for all programming languages syntax behaviors labels Mar 26, 2024
Dageus added a commit to Dageus/zed that referenced this issue Apr 4, 2024
…nless manually saved

Autosave with delay will not format code when triggered, unless the user manually saves the code; added additional docs to the format_on_save setting. Previously autosave with delay would format the code, including the line the cursor was on, causing a poor user experience, as mentioned in the issue.
Dageus added a commit to Dageus/zed that referenced this issue May 9, 2024
…nless manually saved

Autosave with delay will not format code when triggered, unless the user manually saves the code; added additional docs to the format_on_save setting. Previously autosave with delay would format the code, including the line the cursor was on, causing a poor user experience, as mentioned in the issue.
ConradIrwin added a commit that referenced this issue May 12, 2024
Implemented autosave functionality with a delay, which now refrains from
formatting the code upon triggering unless the user manually saves it.
Additionally, enhanced documentation for the `format_on_save` setting
has been added. This resolves the issue where autosave with delay would
inadvertently format the code, disrupting the user experience, as
reported in the corresponding issue.

Release Notes:

- Fixed a bug where autosave after_delay would auto-format the buffer
([#9787](#9787)).

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
@JosephTLyons
Copy link
Collaborator

This is now available in Zed v0.136.0-pre.

osiewicz pushed a commit to RemcoSmitsDev/zed that referenced this issue May 18, 2024
Implemented autosave functionality with a delay, which now refrains from
formatting the code upon triggering unless the user manually saves it.
Additionally, enhanced documentation for the `format_on_save` setting
has been added. This resolves the issue where autosave with delay would
inadvertently format the code, disrupting the user experience, as
reported in the corresponding issue.

Release Notes:

- Fixed a bug where autosave after_delay would auto-format the buffer
([zed-industries#9787](zed-industries#9787)).

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] language An umbrella label for all programming languages syntax behaviors python Python programming language support setting Feedback for preferences, configuration, etc
Projects
None yet
Development

No branches or pull requests

3 participants