summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:52:25 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:16:28 -0300
commit3fb44f4b53eed3e3a592091009bf1149ebf9316d (patch)
treec0f59fe4631c783c05b7ace18d7847a410d2459a
parent4523ad87cae6b31e1db67043ec5b3ba9a995b6ea (diff)
downloadpardes-3fb44f4b53eed3e3a592091009bf1149ebf9316d.tar.gz
pardes-3fb44f4b53eed3e3a592091009bf1149ebf9316d.zip
edit: normalDelete's bare cursor is the 1-wide selection on its cell and goes through the selection's path, whose cursor is clamped into the text after the delete (a d of a text's last newline left it one row past the end)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/edit.zig60
1 files changed, 23 insertions, 37 deletions
diff --git a/src/edit.zig b/src/edit.zig
index a2faec39..42fc0eaa 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -1097,6 +1097,9 @@ fn yankRows(p: *Pardes, t: *Text, r0: i32, r1: i32) []const u8 {
pub fn normalDelete(p: *Pardes, t: *Text, yank: bool) void {
t.select = false; // helix delete exits select mode
t.sticky_col = -1;
+ // A bare cursor is the 1-wide selection on its cell (helix), a '\n'
+ // cell too, where the delete joins the lines.
+ if (!t.vsel.active and !t.msel.active) t.vsel = .{ .active = true, .row = t.cur_row, .col = t.cur_col, .explicit = false };
if (t.vsel.active) {
const b = vselBounds(t);
if (yank) setYank(p, vselText(p, t)); // read the range before the move
@@ -1116,44 +1119,27 @@ pub fn normalDelete(p: *Pardes, t: *Text, yank: bool) void {
t.clampCursor(d.content, eb.row0);
return;
}
- if (t.msel.active) {
- const r0 = @min(t.msel.r0, t.msel.r1);
- const r1 = @max(t.msel.r0, t.msel.r1);
- pushUndo(p, t);
- // linewise: a line's newline lives on the row below it
- const eb = editText(p, t, r0, r1 + 1, -1) orelse {
- t.msel.active = false;
- return;
- };
- const d = modal.deleteLines(p.gpa, eb.text, @intCast(@max(0, r0 - eb.row0)), @intCast(@max(0, r1 - eb.row0))) catch {
- t.msel.active = false;
- return;
- };
- setEditText(p, t, d.content);
- if (yank) setYank(p, d.deleted);
- p.gpa.free(d.deleted);
- const n = modal.lineCount(d.content);
- t.cur_row = @as(i32, @intCast(@min(@as(usize, @intCast(@max(0, r0 - eb.row0))), if (n == 0) 0 else n - 1))) + eb.row0;
- t.cur_col = 0;
+ const r0 = @min(t.msel.r0, t.msel.r1);
+ const r1 = @max(t.msel.r0, t.msel.r1);
+ pushUndo(p, t);
+ // linewise: a line's newline lives on the row below it
+ const eb = editText(p, t, r0, r1 + 1, -1) orelse {
t.msel.active = false;
- t.cur_pinned = true;
- t.show();
- } else {
- pushUndo(p, t);
- const eb = editTextEol(p, t, .{ .lo_row = t.cur_row, .lo_col = t.cur_col, .hi_row = t.cur_row, .hi_col = t.cur_col }) orelse return;
- const c = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - eb.row0)), .col = @intCast(@max(0, t.cur_col)) };
- if (yank) {
- const arena = p.scratch.allocator();
- setYank(p, modal.rangeText(arena, eb.text, c, c) catch return);
- }
- // deleteRange (not deleteChar): the cursor may sit ON a '\n'
- // cell, where a delete joins the lines (helix 1-wide selection)
- const d = modal.deleteRange(p.gpa, eb.text, c, c) catch return;
- setEditText(p, t, d.content);
- p.gpa.free(d.deleted);
- const llen = modal.lineSlice(d.content, c.row).len;
- t.cur_col = @min(t.cur_col, @as(i32, @intCast(llen)));
- }
+ return;
+ };
+ const d = modal.deleteLines(p.gpa, eb.text, @intCast(@max(0, r0 - eb.row0)), @intCast(@max(0, r1 - eb.row0))) catch {
+ t.msel.active = false;
+ return;
+ };
+ setEditText(p, t, d.content);
+ if (yank) setYank(p, d.deleted);
+ p.gpa.free(d.deleted);
+ const n = modal.lineCount(d.content);
+ t.cur_row = @as(i32, @intCast(@min(@as(usize, @intCast(@max(0, r0 - eb.row0))), if (n == 0) 0 else n - 1))) + eb.row0;
+ t.cur_col = 0;
+ t.msel.active = false;
+ t.cur_pinned = true;
+ t.show();
}
pub fn normalYank(p: *Pardes, t: *Text) void {