zed icon indicating copy to clipboard operation
zed copied to clipboard

Make `alt-left` and `alt-right` skip punctuation like macOS default behavior

Open remorses opened this issue 6 months ago • 4 comments

Closes https://github.com/zed-industries/zed/discussions/25526 Follow up of #29872

Release Notes:

  • Make alt-left and alt-right skip punctuation on Mac OS to respect the Mac default behaviour. When pressing alt-left and the first character is a punctuation character like a dot, this character should be skipped. For example: hello.| goes to |hello.

This change makes the editor feels much snappier, it now follows the same behaviour as VSCode and any other Mac OS native application.

@ConradIrwin

remorses avatar Jun 03 '25 14:06 remorses

Great, thank you!

I think we should do this on all platforms, and can you please add a test

ConradIrwin avatar Jun 03 '25 14:06 ConradIrwin

Added some tests and enabled this new behaviour for all platforms.

remorses avatar Jun 03 '25 15:06 remorses

Ok turns out different apps behave differently on Mac:

  • The default Mac OS behaviour for apps like Notes is very weird, it skips a full sequence of punctuation characters, for example pressing alt+left on |...word goes to ...word| which can be unexpected
  • VSCode instead only skips the first punctuation character, for example |...word goes to ...|word (just like Zed now) but |.word goes to .word| (not like Zed)

I decided to go with VSCode behaviour which is the most popular and familiar one. It still makes the IDE feels much snappier but does not do unexptected things like skip a long series of punctuation characters

remorses avatar Jun 03 '25 21:06 remorses

I fixed the tests to align to the new behaviour

remorses avatar Jun 04 '25 11:06 remorses

not sure if intended, but the behavior diverges from VSCode?

pub struct Example {
    first: u32|,
    second: u32,
}

goes to

pub struct Example {
    first: u32,
    second|: u32,
}

whereas VSCode would have

pub struct Example {
    first: u32,|
    second: u32,
}

npm-hater avatar Jun 07 '25 23:06 npm-hater

@npm-hater can you open an issue, i can open a PR later, the code needs an additional \n check

remorses avatar Jun 08 '25 14:06 remorses