editor: Fix DeleteToPreviousSubwordStart and DeleteToNextSubwordEnd interaction with newlines #46235
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @RubenFricke on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Looks like a great first contributions, thank you for fixing this.
…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 :)
|
while this issue is till "warm" in your mind: In python, "word separators" for symbols are "underscores"; How hard would it be to extend your PR for By exposing action params, like Or by handling this issue on per-language basis via settings.json? |
|
Thanks for the question @Andrei-Pozolotin! I believe the current implementation should already handle long_symbol_names_like_this correctly. Underscores are treated as subword separators in the boundary logic: // is_subword_start: underscore→letter transitions
left == '_' && right != '_'
// is_subword_boundary_end: letter→underscore transitions
left != '_' && right == '_'So DeleteToPreviousSubwordStart on long_symbol_names_like_this should stop at: this → like → names → symbol → long. Regarding configurable regex or per-language settings: as far as I see, this would introduce complexity and would likely need some additional direction. Happy to discuss if there's a specific use case the current behavior doesn't cover. |
|
Thank you so much getting back. Well, the reason "I am here" because "that does not work for me." :-) What I observe in python code editor with zed: Using "context": "Editor",
"bindings": {
"ctrl-backspace": ["editor::DeleteToPreviousWordStart", { "ignore_newlines": false, "ignore_brackets": false }],To reproduce:
May be there is a difference: "main edit mode" vs "symbol edit mode"? Since I see no unit tests for this in the code, Perhaps just have to chalk this up this issue to "me, being a zed newbie". Thanks again. |
|
Sorry for the late reaction @Andrei-Pozolotin , but I think I’ve spotted the issue! In your keymap, you are using In Zed, Word actions treat the entire symbol (including underscores) as a single unit. To get the behavior you're looking for where it stops at underscores, you need to use the Subword variant that I've changed in this PR: "ctrl-backspace": ["editor::DeleteToPreviousSubwordStart", { "ignore_newlines": false }]
The "Subword" actions are specifically designed to respect Regarding the unit tests: you should be able to find the logic and test cases for these boundaries in |
|
Thank you, Final curiosity: short of using: What is an easy/simple way to trace from action |
Closes #40110
Changes:
DeleteToPreviousSubwordStartnow deletes\nseparately from preceding subwords and whitespace.DeleteToNextSubwordEndnow deletes\nand any following whitespace separately from subsequent subwords.ignore_newlinesflag 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:
DeleteToPreviousSubwordStartandDeleteToNextSubwordEndinteractions 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 :)