Skip to content

Unindent leading whitespace on backspace - #792

Merged
Leonard Hecker (lhecker) merged 3 commits into
microsoft:mainfrom
kx0101:fix/hungry-backspace
Sep 17, 2026
Merged

Leonard Hecker (lhecker) merged 3 commits into
microsoft:mainfrom
kx0101:fix/hungry-backspace

Conversation

@kx0101

Copy link
Copy Markdown
Member

Problem

pressing Backspace in leading whitespace only deletes one character. You end up pressing it multiple times just to unindent a line

Closes #84

Solution

If the cursor is in leading whitespace, Backspace now jumps to the previous indent stop instead of deleting one char. Normal behavior everywhere else

@lhecker Leonard Hecker (lhecker) changed the title feat: unindent on backspace within leading whitespace Unindent leading whitespace on backspace Sep 17, 2026

@lhecker Leonard Hecker (lhecker) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I rewrote it in the same spirit but:

  • with more comments
  • Ctrl+Backspace support
  • avoid redundant measure_indent_internal search
  • fixed single_line input fields (e.g. Search & Replace box)
  • self.cursor.offset is the absolute byte offset in the text buffer, not the column (this meant backspacing across newlines didn't short-circuit)

Thanks!

@lhecker
Leonard Hecker (lhecker) merged commit 650edc1 into microsoft:main Sep 17, 2026
3 checks passed
Comment on lines +2614 to +2617
// If there's a selection backspace deletes it.
if self.selection.is_some() {
break 'unindent;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@lhecker Leonard Hecker (lhecker) Sep 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unindent when backspacing at the start of an indentation

2 participants