summaryrefslogtreecommitdiff
path: root/src/edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit.zig')
-rw-r--r--src/edit.zig19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/edit.zig b/src/edit.zig
index fb8681d8..b548c7c6 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -1452,9 +1452,12 @@ pub fn normalAdjustNumber(p: *Pardes, t: *Text, delta: i64) void {
/// `]Space` / `[Space`: add blank lines below/above, the cursor staying
/// on its text line (the selection rides along)
pub fn addNewline(p: *Pardes, t: *Text, below: bool, cnt: usize) void {
- const eb = editText(p, t, t.cur_row, t.cur_row, -1) orelse return;
+ // above the selection's first line, below its last (helix line_range)
+ const sr = selRows(t);
+ const at = if (below) sr.hi_row else sr.lo_row;
+ const eb = editText(p, t, at, at, -1) orelse return;
pushUndo(p, t);
- const row: usize = @intCast(@max(0, t.cur_row - eb.row0));
+ const row: usize = @intCast(@max(0, at - eb.row0));
const arena = p.scratch.allocator();
const nl = arena.alloc(u8, cnt) catch return;
@memset(nl, '\n');
@@ -1462,10 +1465,14 @@ pub fn addNewline(p: *Pardes, t: *Text, below: bool, cnt: usize) void {
const new = modal.insertAt(p.gpa, eb.text, .{ .row = row, .col = if (below) llen else 0 }, nl) catch return;
setEditText(p, t, new);
if (!below) {
- t.cur_row += @intCast(cnt); // the line moved down; stay on it
- if (t.vsel.active and t.vsel.row >= @as(i32, @intCast(row))) t.vsel.row += @intCast(cnt);
- } else if (t.vsel.active and t.vsel.row > @as(i32, @intCast(row))) {
- t.vsel.row += @intCast(cnt);
+ // the whole selection moved down; stay on it
+ const n: i32 = @intCast(cnt);
+ t.cur_row += n;
+ if (t.vsel.active) t.vsel.row += n;
+ if (t.msel.active) {
+ t.msel.r0 += n;
+ t.msel.r1 += n;
+ }
}
t.cur_pinned = true;
t.show();