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.78k stars 2.67k forks source link

Exclude dashes when selecting text #15606

Closed dimitrisnl closed 1 week ago

dimitrisnl commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

In the following example I want to select the white part, and replace it with red.

339485270-e99df0da-b812-4074-93d2-422d7eb9ba78

Zed will select the whole world, and instead of bg-red I'll find myself having written red,

In other editors like VSCode, I can select the substring just fine on a double click. This is a common issue when using Tailwind. CleanShot 2024-08-01 at 14 42 06

Environment

Zed: v0.145.1 (Zed) OS: macOS 14.4.1 Memory: 18 GiB Architecture: aarch64


I've also opened a discussion couple months ago, but nothing came out of it, so I'm opening this ticket instead.

notpeter commented 1 month ago

I believe this is language dependent (for example this doesn't happen in JSON) based on the tree-sitter queries. Which language(s) are you seeing this issue?

dimitrisnl commented 1 month ago

I can confirm that this doesn't happen in JSON!

This happens in Elixir (.ex & .heex) and Javascript (.js & .jsx)

notpeter commented 1 month ago

This happens in Elixir (.ex & .heex) and Javascript (.js & .jsx)

I believe this was done to support easy-selecting of kebab-case css things and is controlled by these lines:

https://github.com/zed-industries/zed/blob/80594cc7f823ad7324ba2578fd38c2225c9aa0b5/extensions/elixir/languages/heex/config.toml#L12 https://github.com/zed-industries/zed/blob/80594cc7f823ad7324ba2578fd38c2225c9aa0b5/extensions/elixir/languages/elixir/config.toml#L16-L17 https://github.com/zed-industries/zed/blob/80594cc7f823ad7324ba2578fd38c2225c9aa0b5/crates/languages/src/tsx/config.toml#L26-L27

I (personally) would prefer consistent behavior across filetypes, but I'm not sure.

seasonedfish commented 1 month ago

Seconding this issue. I was annoyed by Zed's unique behavior here when I was editing a filepath containing dashes in a CSS file.

iamnbutler commented 2 weeks ago

I started looking in to this today – Here is the problem. I'll use tsx as an example here.

If we remove overrides.string.word_characters for tsx it does fix the selection problem:

https://github.com/user-attachments/assets/02bec82e-b6ae-4cf1-a4d0-c47b930e97f6

However it creates a larger problem: All completions stop working after the first - in a class/className. In the case of Typescript/Javascript this completely breaks completions from the TailwindLSP.

It seems like we need a way to opt out of overrides.string.word_characters for selections, but not for related LSPs.

Here is the PR that introduce this: https://github.com/zed-industries/zed/commit/fc457d45f5f529fa4d0ade52c48b62516baa388c

In terms of next steps, I'll see if someone here who is more familiar with selections & completions can weigh in on what to do next.