Skip to content

editor: Fix DeleteToPreviousWordStart and DeleteToNextWordEnd interaction with newlines#16848

Merged
SomeoneToIgnore merged 12 commits intozed-industries:mainfrom
kjzl:fix-del-to-prev-word-start
Sep 5, 2024
Merged

editor: Fix DeleteToPreviousWordStart and DeleteToNextWordEnd interaction with newlines#16848
SomeoneToIgnore merged 12 commits intozed-industries:mainfrom
kjzl:fix-del-to-prev-word-start

Conversation

@kjzl
Copy link
Contributor

@kjzl kjzl commented Aug 25, 2024

Closes #5285, #14389

Changes:

  • DeleteToPreviousWordStart now deletes '\n' separately from preceding words and whitespace.
  • DeleteToNextWordEnd now deletes '\n' and any following whitespace separately from subsequent words.
  • Added an ignore_newlines flag to both actions to optionally retain the old behavior.

These modifications align the behavior more closely with other popular editors like VSCode and Sublime:

  • DeleteToPreviousWordStart now matches the default <Ctrl+Backspace> action in those editors.
  • DeleteToNextWordEnd becomes more intuitive and closely resembles the default <Ctrl+Delete> behavior in those editors.

Release Notes:

  • Improved DeleteToPreviousWordStart and DeleteToNextWordEnd interactions around newlines. You can opt-in into the previous behavior by adding {"ignore_newlines": true} to either action's binds in your keymap. (#5285, #14389)

…previous line

Added the action DeleteToPreviousWordStartIgnoringNewlines for
situations in which the old behaviour might be desired.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Aug 25, 2024
@SomeoneToIgnore
Copy link
Contributor

Can we add another test into editor_tests.rs?

kjzl added 4 commits August 26, 2024 01:00
…s_word_start_or_newline

This reverts the modification I made to the function movement::previous_word_start.
This way we avoid the side-effects this commit caused
for the actions SelectToPreviousWordStart and MoveToPreviousWordStart.
Also the function names better represent the outcome.
@kjzl
Copy link
Contributor Author

kjzl commented Aug 26, 2024

Feedback is welcome.
I am not sure if keeping the old behavior through DeleteToPreviousWordStartIgnoringNewlines really is necessary - The way I see it this is a bug and I don't know of any editors which replicate this behavior or why this would be useful.

If this commit gets merged I would be open to also tackle a similar issue with DeleteToNextWordEnd to match the behavior of VSCode/Sublime. This Issue was raised in #14389 which also contains a video showing the problem in that particular case.

@mikayla-maki
Copy link
Member

mikayla-maki commented Aug 29, 2024

I am not sure if keeping the old behavior through DeleteToPreviousWordStartIgnoringNewlines really is necessary

I don't really think it is personally, I'd prefer to just fix the bug and remove the old behavior entirely. cc: @SomeoneToIgnore, lmk if you disagree :)

Otherwise, this PR looks great!

@mikayla-maki
Copy link
Member

This PR also wants to fix this issue: ref: #16963

Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally add this as a parameter into the DeleteToPreviousWordStart, there could be a

struct DeleteToPreviousWordStart {
    include_newlines: bool,
}

definition, and its default include_newlines = false will keep the current behavior for everyone.

But if it already looks nice to everybody, why not merge it.
Any follow-ups to make it more ergonomic are good too.

I'll leave the decision to Mikayla, as the reviewer with most context here.

@kjzl
Copy link
Contributor Author

kjzl commented Aug 30, 2024

(edited)
The other PR's new actions do not match the default behavior we are used to from VsCode/Sublime and others, which my PR will.

You could merge both PR's as the behavior of the commands will differ slightly, but It might add confusion when there are so many variants of this command to choose from.

I would rather merge my PR after I remove the extra command keeping the old behavior and instead add a flag which would activate the old behavior ignoring the newlines (opposed to activating the new behavior via the flag). If the old behaviour is indeed coming from vim, as the author of the other PR says, we should then update the default keymap for vim to use the flag.

@kjzl kjzl changed the title editor: Fix DeleteToPreviousWordStart deleting the last word of the previous line editor: Fix DeleteToPreviousWordStart and DeleteToNextWordEnd interaction with newlines Aug 31, 2024
@kjzl
Copy link
Contributor Author

kjzl commented Aug 31, 2024

I believe this PR is now ready for merge with the implemented changes.

  1. Compatibility for Vim-Mode users:

    • The default Vim behavior can be retained by setting ignore_newlines to true for these actions.
  2. Consideration for default Vim keymap:

    • The only reference to these actions in the default Vim keymap is here.
    • We should review if the actual Vim default behavior is intended for that specific vim mode key bind, and if so, we may need to update it accordingly.

I would appreciate any feedback.

@kjzl
Copy link
Contributor Author

kjzl commented Sep 4, 2024

@SomeoneToIgnore

Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I hoped for @mikayla-maki to step in, but let's merge this: for me, this looks fine and all my feedback is incorporated.

Thank you for working on this!

@zed-industries-bot

This comment was marked as outdated.

@SomeoneToIgnore SomeoneToIgnore merged commit 96b592f into zed-industries:main Sep 5, 2024
@kjzl kjzl deleted the fix-del-to-prev-word-start branch September 6, 2024 09:24
SomeoneToIgnore pushed a commit that referenced this pull request Jan 11, 2026
…nteraction with newlines (#46235)

Closes #40110

  Changes:
- `DeleteToPreviousSubwordStart` now deletes `\n` separately from
preceding subwords and whitespace.
- `DeleteToNextSubwordEnd` now deletes `\n` and any following whitespace
separately from subsequent subwords.
- Added an `ignore_newlines` flag to both actions to optionally retain
the old behavior.

These modifications align the subword commands with their word
counterparts and with other popular editors like VSCode and Sublime.

Related to: #16848

  Release Notes:

- Improved `DeleteToPreviousSubwordStart` and `DeleteToNextSubwordEnd`
interactions around newlines. You can opt-in into the previous behavior
by adding `{"ignore_newlines": true}` to either action's binds in your
keymap.

  ---

This is my first contribution to Zed! If anything should be done
differently, please let me know. Happy to learn :)
Leoyzen pushed a commit to Leoyzen/zed that referenced this pull request Jan 11, 2026
…nteraction with newlines (zed-industries#46235)

Closes zed-industries#40110

  Changes:
- `DeleteToPreviousSubwordStart` now deletes `\n` separately from
preceding subwords and whitespace.
- `DeleteToNextSubwordEnd` now deletes `\n` and any following whitespace
separately from subsequent subwords.
- Added an `ignore_newlines` flag to both actions to optionally retain
the old behavior.

These modifications align the subword commands with their word
counterparts and with other popular editors like VSCode and Sublime.

Related to: zed-industries#16848

  Release Notes:

- Improved `DeleteToPreviousSubwordStart` and `DeleteToNextSubwordEnd`
interactions around newlines. You can opt-in into the previous behavior
by adding `{"ignore_newlines": true}` to either action's binds in your
keymap.

  ---

This is my first contribution to Zed! If anything should be done
differently, please let me know. Happy to learn :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A bit counterintuitive delete word behavior

4 participants