zed icon indicating copy to clipboard operation
zed copied to clipboard

Auto-indent causes issues with YAML files

Open pat-s opened this issue 1 year ago • 3 comments
trafficstars

Check for existing issues

  • [X] Completed

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

pat-s avatar Mar 16 '24 14:03 pat-s

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.

nwalke avatar Apr 23 '24 16:04 nwalke

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

jeffcox avatar May 01 '24 06:05 jeffcox

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

d1y avatar May 01 '24 06:05 d1y

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

jeffcox avatar May 23 '24 22:05 jeffcox

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.

nwalke avatar Jun 05 '24 21:06 nwalke

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:

  • https://github.com/zed-industries/zed/issues/13338
  • https://github.com/zed-industries/zed/pull/13351

notpeter avatar Jun 21 '24 17:06 notpeter

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.

azriel91 avatar Jun 24 '24 03:06 azriel91

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.

jeffcox avatar Jun 26 '24 18:06 jeffcox