Unindent leading whitespace on backspace - #792
Merged
Leonard Hecker (lhecker) merged 3 commits intoSep 17, 2026
Merged
Conversation
Leonard Hecker (lhecker)
approved these changes
Sep 17, 2026
Member
There was a problem hiding this comment.
I rewrote it in the same spirit but:
- with more comments
- Ctrl+Backspace support
- avoid redundant
measure_indent_internalsearch - fixed
single_lineinput fields (e.g. Search & Replace box) self.cursor.offsetis the absolute byte offset in the text buffer, not the column (this meant backspacing across newlines didn't short-circuit)
Thanks!
Comment on lines
+2614
to
+2617
| // If there's a selection backspace deletes it. | ||
| if self.selection.is_some() { | ||
| break 'unindent; | ||
| } |
There was a problem hiding this comment.
If you squint, the approach is identical to your previous version above (in commit 2a84ff4).
Comment on lines
+2638
to
+2639
| line_start.offset + from_pos as usize, | ||
| self.cursor.column - from_col, |
There was a problem hiding this comment.
Here I avoid the redundant work.
| let prev_column = if granularity == CursorMovement::Grapheme { | ||
| self.tab_size_prev_column(self.cursor.column) | ||
| } else { | ||
| 0 // Ctrl+Backspace (Word) = line start |
Member
There was a problem hiding this comment.
Oooh... right and I added Ctrl+Backspace support! I'll edit my summary above.
| }; | ||
| self.edit_begin(HistoryType::Delete, from); | ||
| self.edit_delete(to); | ||
| self.edit_end(); |
There was a problem hiding this comment.
And this is kinda complicated, pointless wankery. Technically, your call to self.delete(Grapheme, -delta) is pretty much almost as efficient (certainly a negligible difference). Maybe I'll change this in the future.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pressing
Backspacein leading whitespace only deletes one character. You end up pressing it multiple times just to unindent a lineCloses #84
Solution
If the cursor is in leading whitespace,
Backspacenow jumps to the previous indent stop instead of deleting one char. Normal behavior everywhere else