zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.74k stars 3.06k forks source link

Format on save loses cursor position #5143

Open henrydaggett opened 2 years ago

henrydaggett commented 2 years ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I'm writing an HTML document, and I have autosave every 2000ms with format on save enabled. Often when I click to add a class or something to an existing tag or try to move tags around the format might reformat and then move the cursor to the start of the next line of HTML

Expected behavior

The cursor should never be moved without user input

Environment

Zed 0.62.7 – /Applications/Zed.app macOS 12.6.1 architecture x86_64

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

SteveLauC commented 6 months ago

I am experiencing this with both Markdown and Rust files

https://github.com/zed-industries/zed/assets/96880612/96393247-b45f-4c27-979d-2f1af64ceb83

To reproduce:

  1. enter insert mode (I have vim mode enabled)
  2. input 1. (note there is a blank space after the dot)
  3. wait for auto save
  4. you got it

My env:

$ zed --version
Zed 0.133.7 – /Applications/Zed.app
$ uname -a
Darwin Steves-MacBook-Air.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64

My config:

{
  "theme": "Ayu Light",
  "vim_mode": true,
  "ui_font_size": 16,
  "buffer_font_size": 16,
  "autosave":  {
    "after_delay": {
      "milliseconds": 1000
    }
  },
  "format_on_save": "off",
  "remove_trailing_whitespace_on_save": false,
  "relative_line_numbers": true,
  "inlay_hints": {
    "enabled": true,
    "show_type_hints": true,
    "show_parameter_hints": true,
    "show_other_hints": true
  }
}

If I enable remove_trailing_whitespace_on_save, then the cursor won't be moved to the next line, it will be set to the last character in the current line.

Update: I fixed this issue by disabling ensure_final_newline_on_save:)

github-actions[bot] commented 1 week ago

Hi there! 👋 We're working to clean up our issue tracker by closing older issues that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Zed, please let us know by commenting on this issue, and we will keep it open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, we'll close it in 7 days. Thanks for your help!