summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 15:35:52 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commitccd3075cac77044498a8c35d2482c8b4cb8f56e7 (patch)
tree54d43d65ad3e8c124c3eb6b9114d240e6b0eccbc /src
parent122281b0ea3473f8950910765c487ef3fc82e7d4 (diff)
downloadpardes-ccd3075cac77044498a8c35d2482c8b4cb8f56e7.tar.gz
pardes-ccd3075cac77044498a8c35d2482c8b4cb8f56e7.zip
Backspace in a line's leading blanks goes back to the previous indent stop
helix's delete_char_backward dedents: when everything before the cursor on its line is blank, it deletes back to the previous multiple of the indent width, a whole unit when already on one (a tab before the cursor still goes alone). pardes deleted one space, so O<backspace> under an indented line left three of four, which is where helix-golf's function_into_class ended up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/edit.zig15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/edit.zig b/src/edit.zig
index 2dc79ab5..5ba46ca7 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -694,8 +694,19 @@ pub fn insertKey(p: *Pardes, t: *Text, key: Key) void {
Key.backspace => {
if (t.cur_col > 0) {
const line = modal.lineSlice(text, c.row);
- const prev = modal.prevGrapheme(line, c.col);
- const new = modal.deleteChar(p.gpa, text, .{ .row = c.row, .col = prev }) catch return;
+ var prev = modal.prevGrapheme(line, c.col);
+ // in leading blanks, back to the previous indent stop (helix
+ // dedent): a whole unit when on one, else the part past it
+ const lead = line[0..@min(c.col, line.len)];
+ if (std.mem.indexOfNone(u8, lead, " \t") == null and prev < line.len and line[prev] != '\t') {
+ var width: usize = 0;
+ for (lead) |ch| width += if (ch == '\t') modal.INDENT_W else 1;
+ var drop = width % modal.INDENT_W;
+ if (drop == 0) drop = modal.INDENT_W;
+ prev = c.col;
+ while (drop > 0 and prev > 0 and line[prev - 1] == ' ') : (drop -= 1) prev -= 1;
+ }
+ const new = modal.deleteSpan(p.gpa, text, .{ .row = c.row, .col = prev }, c) catch return;
setEditText(p, t, new);
t.cur_col = @intCast(prev);
t.cur_pinned = true;