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
46.84k stars 2.68k forks source link

Auto-indent causes issues with YAML files #9441

Open pat-s opened 6 months ago

pat-s commented 6 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

(Thanks for this editor! I was finally able to replace VSCode with it and save a ton of battery 😄 )

When copying a YAML code part from one YAML file to another one, the auto-indent feature automatically adjusts the indent (to the worse) and nests it below the parent key.

This is quite annoying as I'd expect a YAML block sitting in the root of the document to be indented in the same way in the other document when pasting it. Especially when the block is larger, I have to adjust the indent for XX amount of lines.

I suspect that https://github.com/zed-industries/zed/pull/2035 is responsible for that but I might be wrong. I haven't found a way to turn auto-indent off in any way.

Environment

Zed: v0.126.2 (Zed) OS: macOS 14.4.0 Memory: 32 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

nwalke commented 4 months ago

Thank you for raising this. I've been trying desperately to find some sort of language config that would make yaml not the most annoying language to edit on zed, but alas. Since auto-indent is always on, there isn't much to do.

jeffcox commented 4 months ago

This has driven me away from using Zed in the short term.

Copy and paste this entire block into a Zed pane with YAML syntax, it works fine.

list:
  - of
  - things

another:
  - list

Copy and paste each list separately and it will forcibly indent the second pasted list, resulting in this:

list:
  - of
  - things
  another:
    - list
d1y commented 4 months ago

This has driven me away from using Zed in the short term.

Copy and paste this entire block into a Zed pane with YAML syntax, it works fine.

list:
  - of
  - things

another:
  - list

Copy and paste each list separately and it will forcibly indent the second pasted list, resulting in this:

list:
  - of
  - things
  another:
    - list

I also have this problem

jeffcox commented 3 months ago

I tried setting "languages": {"YAML": {"enable_language_server": false } } today while wondering about this bug, the issue persists.

nwalke commented 3 months ago

It's even worse when you see it with the yaml errors:

image

Here I copied the first block, entered twice, backspaced to get to the beginning of the line, and pasted.

notpeter commented 2 months ago

I think we may have pushed a fix for this today, can you download the preview release and verify if your issue is solved?

See also:

azriel91 commented 2 months ago

Heya, I tried pasting the two lists on zed preview 0.141.2, and the issue is partially fixed.

Pasting the two lists individually when the caret is at column 1 (index 0) works nicely:

list:
  - of
  - things

another:
  - list

But when pasting nested maps, where the caret is not on column 1, the inner maps are indented by the number of spaces before the caret:

outer:
  inner1:
    - item

  # <- place caret at column 3 (two spaces)

paste in inner2, but don't select the leading two spaces:

  inner2:
    - item

expected:

outer:
  inner1:
    - item

  inner2:
    - item

actual:

outer:
  inner1:
    - item

  inner2:
      - item
  # ^^ extra spaces

Notably it only happens when the second list is copied from outside Zed, so presumably there's extra context that tells zed whether what's being pasted has indentation.

Arguably it could be "expected behaviour" since zed doesn't know if the externally copied text is meant to be indented with the additional spaces from the caret's position, but I think in YAML, it's more likely that it shouldn't.

jeffcox commented 2 months ago

I am still able to replicate this issue when pasting the lists directly below one another. As I understand it while this is a bit of an eyesore, it is valid YAML:

list_one:
  - one
  - two
list_two:
  - three
  - four

Trying to paste list_two directly below list_one, even after de-indenting back to column 0, results in the same undesirable behavior:

list_one:
  - one
  - two
  list_two:
    - three
    - four

The partial fix is a HUGE improvement and I am excited to give Zed another try.