diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/File.zig | 3 | ||||
| -rw-r--r-- | src/Output.zig | 1 | ||||
| -rw-r--r-- | src/Pipe.zig | 2 | ||||
| -rw-r--r-- | src/Places.zig | 2 | ||||
| -rw-r--r-- | src/Query.zig | 8 | ||||
| -rw-r--r-- | src/Text.zig | 23 | ||||
| -rw-r--r-- | src/body_layer.zig | 17 | ||||
| -rw-r--r-- | src/edit.zig | 189 | ||||
| -rw-r--r-- | src/exec.zig | 13 | ||||
| -rw-r--r-- | src/look.zig | 10 | ||||
| -rw-r--r-- | src/mouse.zig | 8 | ||||
| -rw-r--r-- | src/ninep/pane.zig | 1 | ||||
| -rw-r--r-- | src/normal.zig | 15 | ||||
| -rw-r--r-- | src/pardes.zig | 10 | ||||
| -rw-r--r-- | src/pdf_view.zig | 4 | ||||
| -rw-r--r-- | src/tagline.zig | 2 | ||||
| -rw-r--r-- | src/terminal.zig | 20 | ||||
| -rw-r--r-- | src/views.zig | 3 |
18 files changed, 68 insertions, 263 deletions
diff --git a/src/File.zig b/src/File.zig index 962c17e7..d1636852 100644 --- a/src/File.zig +++ b/src/File.zig @@ -926,7 +926,6 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { t.sel[button].state = .none; } t.body.vsel.active = false; - t.body.msel.active = false; t.body.nsel = 0; const cursor = positionIn(p.gpa, tf, moved[i].cursor); t.body.cur_row = @intCast(cursor.row); @@ -972,7 +971,6 @@ const ParkedPlaces = struct { v.body.cur_row = @intCast(cursor.row); v.body.cur_col = @intCast(cursor.col); v.body.vsel.active = false; - v.body.msel.active = false; v.body.nsel = 0; v.scroll = positionIn(p.gpa, tf, @min(a.scroll, tf.content.len)).row; } @@ -1221,7 +1219,6 @@ pub fn restoreSnap(pane: *Pane, f: *State, snap: Snapshot) void { pane.body.cur_row = @intCast(row); pane.body.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, snap.cur_col))), llen)); pane.body.vsel = snap.vsel; - pane.body.msel.active = false; pane.body.cur_pinned = true; pane.body.sticky_col = -1; pane.ensureCursorVisible(); diff --git a/src/Output.zig b/src/Output.zig index 3d8d713c..bc61dc11 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -1056,7 +1056,6 @@ pub fn resetBody(p: *Pardes, pane: *Pane) void { pane.body.cur_pinned = true; pane.hscroll = 0; pane.geometry_key = 0; - pane.body.msel = .{}; pane.body.vsel = .{}; pane.body.nsel = 0; pane.nsel_snap = 0; diff --git a/src/Pipe.zig b/src/Pipe.zig index af500665..c6e53162 100644 --- a/src/Pipe.zig +++ b/src/Pipe.zig @@ -153,7 +153,7 @@ pub fn submitPipe(p: *Pardes, id: usize) void { .inputs = inputs, .ranges = ranges, .primary = @intCast(got.pri), - .explicit = (t.vsel.active and t.vsel.explicit) or t.msel.active, + .explicit = t.vsel.active and t.vsel.explicit, .how = how, .nranges = @intCast(got.n), }; diff --git a/src/Places.zig b/src/Places.zig index 6df0ed74..82595e2a 100644 --- a/src/Places.zig +++ b/src/Places.zig @@ -622,7 +622,7 @@ pub fn remember(set: *Places, p: *Pardes, pane: *Pane) void { p.gpa.free(set.snap); set.snap = p.gpa.dupe(modal.Selection, ranges[0..got.n]) catch &.{}; set.snap_pri = got.pri; - set.snap_expl = (pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active; + set.snap_expl = pane.body.vsel.active and pane.body.vsel.explicit; set.snap_scroll = f.scroll; set.snap_hscroll = pane.hscroll; } diff --git a/src/Query.zig b/src/Query.zig index 84725085..cb14df2b 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -1752,8 +1752,12 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void else => {}, } if (selectPlace(p, pane, qp.serial, at)) return; - if (at.end_line == 0 or at.end_col <= at.col) - pane.body.msel = .{ .active = true, .r0 = @intCast(at.line - 1), .r1 = @intCast(at.line - 1) }; + if (at.end_line == 0 or at.end_col <= at.col) { + // the place's whole line, selected back from its end + pane.body.vsel = .{ .active = true, .row = @intCast(at.line - 1), .col = @intCast(File.textLine(&pane.body, f.content, at.line - 1).len), .explicit = true }; + pane.body.cur_row = @intCast(at.line - 1); + pane.body.cur_col = 0; + } } /// The +Preview becomes the file's pane where it stands: same slot, same diff --git a/src/Text.zig b/src/Text.zig index 1d0df183..5e36467f 100644 --- a/src/Text.zig +++ b/src/Text.zig @@ -23,13 +23,6 @@ pub const Mode = enum { normal, insert, tty }; /// characters live and whether moving the cursor scrolls a body. pub const What = enum { body, tag, input, column, workspace }; -/// A modal line selection (helix `x`): whole rows [r0, r1], absolute. -pub const LineSel = struct { - active: bool = false, - r0: i32 = 0, - r1: i32 = 0, -}; - pub const CharSel = struct { active: bool = false, row: i32 = 0, @@ -62,7 +55,6 @@ mode: Mode = .normal, cur_pinned: bool = false, cur_row: i32 = 0, cur_col: i32 = 0, -msel: LineSel = .{}, vsel: CharSel = .{}, /// The ranges beside the primary, `nsel` of them: room for max_selections - 1 /// made when a second range appears and given back when the selection is one @@ -178,14 +170,6 @@ pub fn insertVerticalCursor(lines: []const []const u8, c: modal.Cursor, down: bo pub fn primaryRange(t: *Text, text: []const u8, row0: i32) modal.Selection { const c = File.textOffset(t, text, .{ .row = @intCast(@max(0, t.cur_row - row0)), .col = @intCast(@max(0, t.cur_col)) }); - if (t.msel.active) { - // legacy line selection (file-search results highlight): linewise - const r0: usize = @intCast(@max(0, @min(t.msel.r0, t.msel.r1) - row0)); - const r1: usize = @intCast(@max(0, @max(t.msel.r0, t.msel.r1) - row0)); - const s = modal.lineStartOffset(text, r0); - const e = if (r1 + 1 >= modal.cursorLineCount(text)) text.len else modal.lineStartOffset(text, r1 + 1); - return .{ .anchor = s, .head = @max(e, modal.nextGrapheme(text, c)) }; - } // Both ends through the line index, as the cursor's: cellRange counts // lines from the top for each, a pass over a big file per call (the // places' settle and every insert-mode key asked it). @@ -230,7 +214,6 @@ pub fn setRange(t: *Text, text: []const u8, row0: i32, r0: modal.Selection, expl .col = @intCast(ac.col), .explicit = explicit or t.select, }; - t.msel.active = false; t.dropSels(); // writing ONE range means the selection IS that range t.cur_pinned = true; t.sticky_col = -1; @@ -332,7 +315,7 @@ pub fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: var rs: [max_selections]modal.Selection = undefined; const got = ranges(t, text, 0, &rs); const n = got.n; - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; if (role == .remove_primary_sel) { if (n < 2) return; // helix: "no selections remaining" var out: [max_selections]modal.Selection = undefined; @@ -690,7 +673,7 @@ pub fn shrinkSelToLineBounds(t: *Text, text: []const u8, range: modal.Selection) var end = lineStartOrEof(text, span.end + 1); if (start != from) start = lineStartOrEof(text, span.start + 1); if (end != to) end = modal.lineStartOffset(text, span.end); - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; const r: modal.Selection = if (range.head < range.anchor) .{ .anchor = end, .head = start } else @@ -708,7 +691,6 @@ pub fn clampCursor(t: *Text, text: []const u8, row0: i32) void { t.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, t.cur_col))), llen)); t.cur_pinned = true; t.vsel.active = false; - t.msel.active = false; t.show(); } @@ -756,6 +738,5 @@ pub fn step(t: *Text, gpa: std.mem.Allocator, current: ?terminal.EditBuffer, bac t.cur_col = back_to.cur_col; t.cur_pinned = true; t.vsel = back_to.vsel; - t.msel.active = false; return back_to; } diff --git a/src/body_layer.zig b/src/body_layer.zig index 7b1be4f7..027dfffb 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -318,23 +318,6 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane if (b == pardes.sel_slot and @min(sl.r0, sl.r1) < pane.tag_rows) continue; paintPointerSelection(p, s, pane, r, tx, tw, tag_y, body_y, sl, pane.tag_rows, sel_btn[b], buttonInks(th)[b]); } - // modal line selection (helix `x`): whole body rows, normal mode only - if ((pane.body.mode == .normal or modal_hover) and pane.body.msel.active) { - const hover_only = modal_hover and pane.body.mode != .normal; - const modal_bg = if (hover_only) - colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg)) - else - th.sel_bg; - const lo = @min(pane.body.msel.r0, pane.body.msel.r1); - const hi = @max(pane.body.msel.r0, pane.body.msel.r1); - var row: u16 = pane.tag_rows; // never paint the tag row - while (row < body_bottom) : (row += 1) { - const ar = pane.wrapAt(@as(i32, row) - @as(i32, pane.tag_rows)).line; - if (ar < lo or ar > hi) continue; - const col: u16 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; - if (col < tw) s.tint(tx + col, body_y + row - pane.tag_rows, tw - col, modal_bg, if (hover_only) null else th.sel_fg); - } - } const preview = normal.selRegexArmed(pane) != null; const show_prim = (pane.body.mode == .normal and pane.body.vsel.active) or preview or (modal_hover and pane.body.vsel.active); diff --git a/src/edit.zig b/src/edit.zig index 93a6f308..964cda79 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -62,7 +62,6 @@ pub fn registerValue(p: *Pardes, t: *Text, name: u21) ?[]const u8 { /// the text of the range under the cursor: the selection, or the cursor's /// own character fn selText(p: *Pardes, t: *Text) []const u8 { - if (t.msel.active) return yankRows(p, t, @min(t.msel.r0, t.msel.r1), @max(t.msel.r0, t.msel.r1)); const save = t.vsel; defer t.vsel = save; if (!t.vsel.active) t.vsel = .{ .active = true, .row = t.cur_row, .col = t.cur_col, .explicit = false }; @@ -160,14 +159,14 @@ fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void { if (bytes.len == 0) return; const typed: pardes.Key = .{ .cp = bytes[0], .text = bytes }; if (t.what == .tag and t.mode == .insert) if (t.pane()) |pane| if (tagline.typedIntoName(p, pane, typed)) return; - const kept = .{ t.cur_row, t.cur_col, t.vsel, t.msel }; + const kept = .{ t.cur_row, t.cur_col, t.vsel }; var kept_sels: [Text.max_selections - 1]Text.SelRange = undefined; const kept_n = t.nsel; @memcpy(kept_sels[0..kept_n], t.sels[0..kept_n]); t.refused = false; if (t.mode == .insert) insertKey(p, t, typed) else pasteText(p, t, bytes, false, 1); if (t.refused) { - t.cur_row, t.cur_col, t.vsel, t.msel = kept; + t.cur_row, t.cur_col, t.vsel = kept; t.restoreSels(kept_sels[0..kept_n]); } } @@ -349,25 +348,23 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool { return (r > sr or (r == sr and c >= sc)) and (r < er or (r == er and c <= ec)); } -/// the active modal selection as text (v range or x lines), if any +/// the active modal selection as text, if any pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 { if (comptime pdf_enabled) if (p.native_images) if (pane.pdf) |pv| if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; - if (pane.body.vsel.active) return vselText(p, &pane.body); - if (!pane.body.msel.active) return null; - return yankRows(p, &pane.body, @min(pane.body.msel.r0, pane.body.msel.r1), @max(pane.body.msel.r0, pane.body.msel.r1)); + if (!pane.body.vsel.active) return null; + return vselText(p, &pane.body); } pub fn exitInsert(p: *Pardes, t: *Text) void { t.mode = .normal; t.reg_wait = false; - t.msel.active = false; t.normal.clear(); if (!t.restore_cursor) return; t.restore_cursor = false; // helix enter_normal_mode: every range, from its start to the char // before its end when it points forward, else to its end - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; const text = flatSurface(p, t) catch return; var rs: [Text.max_selections]modal.Selection = undefined; const got = t.ranges(text, 0, &rs); @@ -584,7 +581,6 @@ pub fn enterInsert(p: *Pardes, t: *Text, where: InsertAt, cnt: usize) void { t.sticky_col = -1; const text = flatSurface(p, t) catch { t.mode = .insert; - t.msel.active = false; t.vsel.active = false; t.normal.clear(); return; @@ -681,7 +677,6 @@ pub fn enterInsert(p: *Pardes, t: *Text, where: InsertAt, cnt: usize) void { }, } t.mode = .insert; - t.msel.active = false; t.normal.clear(); t.show(); } @@ -1063,80 +1058,28 @@ fn vselText(p: *Pardes, t: *Text) []const u8 { return modal.rangeText(arena, text, .{ .row = @intCast(@max(0, b.lo_row)), .col = @intCast(@max(0, b.lo_col)) }, .{ .row = @intCast(@max(0, b.hi_row)), .col = @intCast(@max(0, b.hi_col)) }) catch ""; } -/// join surface rows [r0, r1] (absolute) with '\n'; scratch-owned -fn yankRows(p: *Pardes, t: *Text, r0: i32, r1: i32) []const u8 { - const arena = p.scratch.allocator(); - const lines = paneCursorLines(p, t) catch return ""; - const rows_count: usize = @intCast(@max(0, r1 - r0 + 1)); - var total: usize = rows_count -| 1; - var i = r0; - while (i <= r1) : (i += 1) { - if (i >= 0 and @as(usize, @intCast(i)) < lines.len) - total += lines[@intCast(i)].len; - } - const out = arena.alloc(u8, total) catch return ""; - var at: usize = 0; - i = r0; - while (i <= r1) : (i += 1) { - if (i > r0) { - out[at] = '\n'; - at += 1; - } - if (i >= 0 and @as(usize, @intCast(i)) < lines.len) { - const line = lines[@intCast(i)]; - @memcpy(out[at..][0..line.len], line); - at += line.len; - } - } - return out; -} - 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 - pushUndo(p, t); - const eb = editTextEol(p, t, b) orelse { - t.vsel.active = false; - return; - }; - const d = modal.deleteRange(p.gpa, eb.text, .{ .row = @intCast(@max(0, b.lo_row - eb.row0)), .col = @intCast(@max(0, b.lo_col)) }, .{ .row = @intCast(@max(0, b.hi_row - eb.row0)), .col = @intCast(@max(0, b.hi_col)) }) catch { - t.vsel.active = false; - return; - }; - setEditText(p, t, d.content); - p.gpa.free(d.deleted); - t.cur_row = b.lo_row; - t.cur_col = b.lo_col; - t.clampCursor(d.content, eb.row0); - return; - } - const r0 = @min(t.msel.r0, t.msel.r1); - const r1 = @max(t.msel.r0, t.msel.r1); + if (!t.vsel.active) t.vsel = .{ .active = true, .row = t.cur_row, .col = t.cur_col, .explicit = false }; + const b = vselBounds(t); + if (yank) setYank(p, vselText(p, t)); // read the range before the move 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; + const eb = editTextEol(p, t, b) orelse { + t.vsel.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; + const d = modal.deleteRange(p.gpa, eb.text, .{ .row = @intCast(@max(0, b.lo_row - eb.row0)), .col = @intCast(@max(0, b.lo_col)) }, .{ .row = @intCast(@max(0, b.hi_row - eb.row0)), .col = @intCast(@max(0, b.hi_col)) }) catch { + t.vsel.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(); + t.cur_row = b.lo_row; + t.cur_col = b.lo_col; + t.clampCursor(d.content, eb.row0); } pub fn normalYank(p: *Pardes, t: *Text) void { @@ -1209,7 +1152,6 @@ pub fn pasteText(p: *Pardes, t: *Text, y0: []const u8, before: bool, count: usiz t.cur_col = @intCast(modal.lineSlice(out, end.row -| 1).len); } } - t.msel.active = false; t.cur_pinned = true; t.show(); } @@ -1237,7 +1179,6 @@ pub fn normalChange(p: *Pardes, t: *Text) void { t.cur_row = @as(i32, @intCast(row)) + eb.row0; t.cur_col = @intCast(ind.len); t.vsel.active = false; - t.msel.active = false; t.cur_pinned = true; t.mode = .insert; t.normal.clear(); @@ -1259,54 +1200,21 @@ pub fn normalChange(p: *Pardes, t: *Text) void { t.normal.clear(); 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); - const eb = editText(p, t, r0, r1 + 1, -1) orelse return; - const lo: usize = @intCast(@max(0, r0 - eb.row0)); - const hi: usize = @intCast(@max(0, r1 - eb.row0)); - // the lines are adjacent in the text already, their newlines and all - setYank(p, eb.text[modal.lineStartOffset(eb.text, lo)..modal.lineEndOffset(eb.text, hi)]); - var body: []u8 = eb.text; - if (hi > lo) { - const d = modal.deleteLines(p.gpa, body, lo + 1, hi) catch { - t.msel.active = false; - return; - }; - setEditText(p, t, d.content); - p.gpa.free(d.deleted); - body = d.content; - } - const cl = modal.clearLine(p.gpa, body, lo) catch { - t.msel.active = false; - return; - }; - setEditText(p, t, cl); - t.cur_row = r0; - t.cur_col = 0; - t.msel.active = false; - t.cur_pinned = true; - t.mode = .insert; - t.normal.clear(); - 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)) }; - const arena = p.scratch.allocator(); - setYank(p, modal.rangeText(arena, eb.text, c, c) catch return); - 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))); - t.mode = .insert; - t.normal.clear(); - } + 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)) }; + const arena = p.scratch.allocator(); + setYank(p, modal.rangeText(arena, eb.text, c, c) catch return); + 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))); + t.mode = .insert; + t.normal.clear(); } -fn selRange(t: *Text, content: []const u8, row0: i32) modal.Range { +fn selRange(t: *Text, row0: i32) modal.Range { if (t.vsel.active) { const b = vselBounds(t); return .{ @@ -1314,12 +1222,6 @@ fn selRange(t: *Text, content: []const u8, row0: i32) modal.Range { .b = .{ .row = @intCast(@max(0, b.hi_row - row0)), .col = @intCast(@max(0, b.hi_col)) }, }; } - if (t.msel.active) { - const r0: usize = @intCast(@max(0, @min(t.msel.r0, t.msel.r1) - row0)); - const r1: usize = @intCast(@max(0, @max(t.msel.r0, t.msel.r1) - row0)); - const llen = modal.lineSlice(content, r1).len; - return .{ .a = .{ .row = r0, .col = 0 }, .b = .{ .row = r1, .col = if (llen == 0) 0 else modal.prevGrapheme(modal.lineSlice(content, r1), llen) } }; - } const c = modal.Cursor{ .row = @intCast(@max(0, t.cur_row - row0)), .col = @intCast(@max(0, t.cur_col)) }; return .{ .a = c, .b = c }; } @@ -1327,12 +1229,6 @@ fn selRange(t: *Text, content: []const u8, row0: i32) modal.Range { /// the rows an op's selection spans, absolute (what editText must cover) fn selRows(t: *Text) Bounds { if (t.vsel.active) return vselBounds(t); - if (t.msel.active) return .{ - .lo_row = @min(t.msel.r0, t.msel.r1), - .lo_col = 0, - .hi_row = @max(t.msel.r0, t.msel.r1), - .hi_col = 0, - }; return .{ .lo_row = t.cur_row, .lo_col = t.cur_col, .hi_row = t.cur_row, .hi_col = t.cur_col }; } @@ -1376,7 +1272,7 @@ pub fn normalReplaceChar(p: *Pardes, t: *Text, ch: u21) void { while (at < hi) : (graphemes += 1) at = modal.nextGrapheme(eb.text, at); var encoded: [4]u8 = undefined; const encoded_len = std.unicode.utf8Encode(ch, &encoded) catch return; - const r = selRange(t, eb.text, eb.row0); + const r = selRange(t, eb.row0); pushUndo(p, t); const new = modal.replaceChars(p.gpa, eb.text, r.a, r.b, ch) catch return; setEditText(p, t, new); @@ -1402,12 +1298,11 @@ fn replaceWithText(p: *Pardes, t: *Text, y: []const u8) void { if (y.len == 0) return; t.select = false; const eb = editTextEol(p, t, selRows(t)) orelse return; - const r = selRange(t, eb.text, eb.row0); + const r = selRange(t, eb.row0); const back = t.vsel.active and (t.cur_row < t.vsel.row or (t.cur_row == t.vsel.row and t.cur_col < t.vsel.col)); pushUndo(p, t); const new = modal.replaceRange(p.gpa, eb.text, r.a, r.b, y) catch return; setEditText(p, t, new); - t.msel.active = false; const end = modal.advanceBy(r.a, y); var last_row: i32 = undefined; var last_col: i32 = undefined; @@ -1439,7 +1334,7 @@ fn replaceWithText(p: *Pardes, t: *Text, y: []const u8) void { pub fn normalCase(p: *Pardes, t: *Text, op: modal.CaseOp) void { t.select = false; const eb = editTextEol(p, t, selRows(t)) orelse return; - const r = selRange(t, eb.text, eb.row0); + const r = selRange(t, eb.row0); pushUndo(p, t); const new = modal.changeCase(p.gpa, eb.text, r.a, r.b, op) catch return; setEditText(p, t, new); @@ -1466,7 +1361,7 @@ fn mapThroughChanges(chs: []const sam.Op, pos: usize) usize { /// become one space, or nothing when that line is blank, and a line two /// ranges share is joined once. `Alt-J` then selects the spaces it put in. pub fn normalJoin(p: *Pardes, t: *Text, select_space: bool) void { - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; // a join always eats the newline of its last line, so the buffer has // to reach one row PAST every range const b = allSelRows(t); @@ -1535,7 +1430,7 @@ pub fn normalJoin(p: *Pardes, t: *Text, select_space: bool) void { /// Each range comes back over the text it now holds, in its own direction, /// and the primary moves with the text it had. pub fn normalRotateContents(p: *Pardes, t: *Text, forward: bool, cnt: usize) void { - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; const eb = editTextEol(p, t, allSelRows(t)) orelse return; const text = eb.text; var rs: [Text.max_selections]modal.Selection = undefined; @@ -1570,7 +1465,7 @@ pub fn normalRotateContents(p: *Pardes, t: *Text, forward: bool, cnt: usize) voi /// before each range so its head lands on the column's widest head, measured /// in display cells. A range over several lines aligns nothing. pub fn normalAlign(p: *Pardes, t: *Text) void { - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; const eb = editTextEol(p, t, allSelRows(t)) orelse return; const text = eb.text; var rs: [Text.max_selections]modal.Selection = undefined; @@ -1692,14 +1587,13 @@ pub fn normalIndent(p: *Pardes, t: *Text, cnt: usize, add: bool) void { t.vsel.row = @as(i32, @intCast(ac.row)) + eb.row0; t.vsel.col = @intCast(ac.col); } - t.msel.active = false; t.cur_pinned = true; t.sticky_col = -1; t.show(); } pub fn normalToggleComment(p: *Pardes, t: *Text) void { - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; t.select = false; // helix exit_select_mode // the buffer must cover every cursor's rows, not just the primary's const b = allSelRows(t); @@ -1780,7 +1674,7 @@ pub fn normalToggleComment(p: *Pardes, t: *Text) void { pub fn normalAdjustNumber(p: *Pardes, t: *Text, delta: i64) void { const eb = editTextEol(p, t, selRows(t)) orelse return; - const r = selRange(t, eb.text, eb.row0); + const r = selRange(t, eb.row0); const arena = p.scratch.allocator(); const frag = modal.rangeText(arena, eb.text, r.a, r.b) catch return; const rep = (modal.incrementDecimal(arena, frag, delta) catch null) orelse return; @@ -1791,7 +1685,6 @@ pub fn normalAdjustNumber(p: *Pardes, t: *Text, delta: i64) void { const start = modal.lineStartOffset(new, r.a.row) + r.a.col; const cc = modal.positionAt(new, modal.prevGrapheme(new, start + rep.len)); t.vsel = .{ .active = modal.nextGrapheme(rep, 0) < rep.len, .row = @as(i32, @intCast(r.a.row)) + eb.row0, .col = @intCast(r.a.col), .explicit = false }; - t.msel.active = false; t.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; t.cur_col = @intCast(cc.col); t.cur_pinned = true; @@ -1819,10 +1712,6 @@ pub fn addNewline(p: *Pardes, t: *Text, below: bool, cnt: usize) void { 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(); @@ -1900,7 +1789,7 @@ pub fn surroundAdd(p: *Pardes, t: *Text, ch: u21) void { const pr = pairFor(ch) orelse return; t.select = false; const eb = editTextEol(p, t, selRows(t)) orelse return; - const r = selRange(t, eb.text, eb.row0); + const r = selRange(t, eb.row0); // the wrapped range keeps the direction it had (helix with_direction) const back = t.vsel.active and (t.cur_row < t.vsel.row or (t.cur_row == t.vsel.row and t.cur_col < t.vsel.col)); pushUndo(p, t); @@ -1913,7 +1802,6 @@ pub fn surroundAdd(p: *Pardes, t: *Text, ch: u21) void { const open_col: i32 = @intCast(r.a.col); const close_row = @as(i32, @intCast(r.b.row)) + eb.row0; const close_at: i32 = @intCast(close_col + @as(usize, if (r.a.row == r.b.row) 1 else 0)); - t.msel.active = false; t.vsel = .{ .active = true, .row = if (back) close_row else open_row, .col = if (back) close_at else open_col, .explicit = false }; t.cur_row = if (back) open_row else close_row; t.cur_col = if (back) open_col else close_at; @@ -1954,7 +1842,6 @@ pub fn surroundDelete(p: *Pardes, t: *Text, ch: u21) void { t.cur_row = @as(i32, @intCast(cc.row)) + eb.row0; t.cur_col = @intCast(cc.col); t.vsel.active = false; - t.msel.active = false; t.cur_pinned = true; t.show(); } diff --git a/src/exec.zig b/src/exec.zig index 4706d11a..b1ee55d4 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -67,7 +67,6 @@ pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool { const id = p.active; const serial = pane.serial; pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.select = false; pane.body.nsel = 0; // the chord consumed them, exactly as it consumes one @@ -104,7 +103,7 @@ pub const PointerOperand = struct { /// The body's explicit selection, else what a look at its cursor takes. pub fn currentOperand(p: *Pardes, pane: *Pane) ?[]const u8 { if (pane.file == null and !pane.isTerminal()) return null; - if ((pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active) return edit.currentSelText(p, pane); + if (pane.body.vsel.active and pane.body.vsel.explicit) return edit.currentSelText(p, pane); return operandAt(p, pane, look.cursorWordSel(p, pane), false, true).text; } @@ -172,12 +171,6 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l result.text = edit.currentSelText(p, pane); return result; } - if (pane.body.msel.active and row >= @min(pane.body.msel.r0, pane.body.msel.r1) and - row <= @max(pane.body.msel.r0, pane.body.msel.r1)) - { - result.text = edit.currentSelText(p, pane); - return result; - } } // In a diff, a file or hunk header, and a hunk line pointed at on its // `+`/`-`/` ` prefix, expand to the whole line (the hover shows it) and @@ -283,7 +276,7 @@ pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { }; if (t.sel[sel_slot].state == .done) { if (edit.selectionText(p, t, t.sel[sel_slot]) catch null) |tx| return tx; - } else if ((t.body.vsel.active and t.body.vsel.explicit) or t.body.msel.active) { + } else if (t.body.vsel.active and t.body.vsel.explicit) { if (edit.currentSelText(p, t)) |tx| return tx; } } @@ -296,7 +289,7 @@ pub fn heldSelectionPlace(p: *Pardes, first: usize, buf: []u8) ?[]const u8 { for (0..p.panes.len + 2) |k| { const t = heldPane(p, first, k) orelse continue; if (t.sel[sel_slot].state == .done) return null; // a pointer selection: no byte range kept - if ((t.body.vsel.active and t.body.vsel.explicit) or t.body.msel.active) { + if (t.body.vsel.active and t.body.vsel.explicit) { const f = t.file orelse return null; const d = @import("ninep/pane.zig").dotOf(t); return std.fmt.bufPrint(buf, "{s}:#{d},#{d}", .{ f.path, d.q0, d.q1 }) catch null; diff --git a/src/look.zig b/src/look.zig index f6095fb9..f47f0b15 100644 --- a/src/look.zig +++ b/src/look.zig @@ -567,7 +567,6 @@ fn lookFirstHit(p: *Pardes, id: usize) void { const txt = edit.currentSelText(p, rp) orelse return; // spent, exactly as the look chord spends it (handleKey) rp.body.vsel.active = false; - rp.body.msel.active = false; rp.body.select = false; exec.runBuiltin(p, config.look_cmd, rid, "", txt); } @@ -678,8 +677,8 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { if (ln.len == 0) return false; const r: i32 = @intCast(row); pane.search_row = row; - rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; - rp.body.vsel.active = false; + // the visited result, selected back from its line's end + rp.body.vsel = .{ .active = true, .row = r, .col = @intCast(ln.len), .explicit = true }; rp.body.nsel = 0; rp.body.cur_row = r; rp.body.cur_pinned = true; @@ -714,7 +713,7 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool { lookAt(p, rid, ln[selected.start..selected.end]); // This is the newly visited result, not a selection carried into // the destination. Look cleared the previous source selection. - rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; + rp.body.vsel = .{ .active = true, .row = r, .col = @intCast(ln.len), .explicit = true }; } armLookWalk(p, rid); return true; @@ -884,7 +883,6 @@ pub fn lookWalk(p: *Pardes, delta: i32) void { fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { edit.pinPaneCursor(p, &pane.body); // fresh out of tty mode the cursor still tracks the shell pane.body.vsel = .{ .active = true, .row = spot.row, .col = spot.col1, .explicit = true }; - pane.body.msel.active = false; pane.body.nsel = 0; pane.body.cur_row = spot.row; pane.body.cur_col = spot.col0; @@ -1065,7 +1063,6 @@ fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { /// Navigation starts a new selection at the destination. pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { pane.body.vsel = .{}; - pane.body.msel = .{}; pane.body.nsel = 0; pane.body.select = false; pane.body.normal.clear(); @@ -2491,7 +2488,6 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5 p.active = 0; pane.body.mode = .normal; pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.cur_row = case.row; pane.body.cur_col = case.col; pane.body.cur_pinned = true; diff --git a/src/mouse.zig b/src/mouse.zig index 69d1456e..32f7c716 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -807,7 +807,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { pane.tag.mode = .normal; pane.tag.normal.clear(); pane.tag.vsel.active = false; - pane.tag.msel.active = false; pane.tag.nsel = 0; pane.tag.cur_pinned = true; const at = tagline.tagOffsetAt(p, pane, @intCast(@max(0, pointed.sel.r0)), @intCast(@max(0, pointed.sel.c0))) orelse modal.Cursor{ .row = 0, .col = 0 }; @@ -1144,7 +1143,6 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { } pane.body.cur_col = @intCast(modal.graphemeStart(shown, @min(shown.len, byte -| endpoint.prompt_bytes))); pane.body.cur_pinned = true; - pane.body.msel.active = false; pane.body.vsel.active = false; pane.body.nsel = 0; pane.body.select = false; @@ -1308,7 +1306,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { ); pane.body.cur_pinned = true; if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); - pane.body.msel.active = false; pane.body.normal.clear(); pane.body.vsel.active = false; pane.body.nsel = 0; // a click says WHERE the one cursor is @@ -1353,7 +1350,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { // must not stretch to it; borrowed selections retain // their original cursor and extent. pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.nsel = 0; pane.body.select = false; pane.body.cur_row = operand.row; @@ -1427,7 +1423,6 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { t.cur_col = @intCast(to.col); t.cur_pinned = true; t.vsel = .{ .active = from.row != to.row or from.col != to.col, .row = @intCast(from.row), .col = @intCast(from.col), .explicit = false }; - t.msel.active = false; t.nsel = 0; } if (cut) { @@ -1479,7 +1474,6 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { pane.body.cur_row = row1; pane.body.cur_col = col1; pane.body.cur_pinned = true; - pane.body.msel.active = false; pane.body.normal.clear(); if (!pane.isTerminal()) pane.body.mode = .normal; pane.body.vsel = .{ .active = row0 != row1 or col0 != col1, .row = row0, .col = col0, .explicit = false }; @@ -1522,7 +1516,6 @@ test "plain left click clears explicit modal selection" { pane.body.cur_row = 0; pane.body.cur_col = 5; pane.body.vsel = .{ .active = true, .row = 0, .col = 1, .explicit = true }; - pane.body.msel = .{ .active = true, .r0 = 0, .r1 = 0 }; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -1535,7 +1528,6 @@ test "plain left click clears explicit modal selection" { try std.testing.expectEqual(@as(i32, 3), pane.body.cur_col); try std.testing.expect(!pane.body.vsel.active); - try std.testing.expect(!pane.body.msel.active); try std.testing.expectEqual(.none, pane.sel[@backingInt(config.select_button)].state); } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index df0c7975..2faa4466 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -239,7 +239,6 @@ pub fn setDot(pane: *Pane, r: State.Range) void { pane.body.cur_col = @intCast(h.col); pane.body.cur_pinned = true; pane.body.sticky_col = -1; - pane.body.msel.active = false; pane.ensureCursorVisible(); } diff --git a/src/normal.zig b/src/normal.zig index 8b1cf545..6b9508f8 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -57,7 +57,7 @@ fn startSelRegex(p: *Pardes, pane: *Pane, t: *Text, mode: modal.Normal.RegexMode const got = t.ranges(text, 0, &pane.sel_snap); pane.nsel_snap = @intCast(got.n); pane.sel_snap_pri = @intCast(got.pri); - pane.sel_snap_expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + pane.sel_snap_expl = t.vsel.active and t.vsel.explicit; p.startPrompt(pane, t, .{ .search = regexMarker(mode) }); } @@ -346,7 +346,7 @@ pub fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk const f = if (pane.file) |*file| file else return; const tree = fileTree(p, f) orelse return; const text = f.content; - const expl = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const expl = t.vsel.active and t.vsel.explicit; const arena = p.scratch.allocator(); const rs = arena.alloc(modal.Selection, Text.max_selections) catch return; const got = t.ranges(text, 0, rs[0..Text.max_selections]); @@ -545,7 +545,6 @@ pub fn replaySels(p: *Pardes, t: *Text, what: Replay) void { .col = list[i].acol, .explicit = explicit, }; - t.msel.active = false; t.sticky_col = list[i].sticky; switch (what) { .normal => |normal_action| executeNormalAction(p, t, normal_action), @@ -612,8 +611,8 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void { // acts for the pane the text belongs to; a header's is the active one. const pane = t.pane() orelse p.panes[p.active] orelse return; const raw_selection = t.what == .body and pane.rawPointerText(pane.sel[sel_slot]) != null; - const before = .{ t.cur_row, t.cur_col, t.vsel, t.msel, t.select, t.nsel, t.mode }; - defer if (raw_selection and !std.meta.eql(before, .{ t.cur_row, t.cur_col, t.vsel, t.msel, t.select, t.nsel, t.mode })) { + const before = .{ t.cur_row, t.cur_col, t.vsel, t.select, t.nsel, t.mode }; + defer if (raw_selection and !std.meta.eql(before, .{ t.cur_row, t.cur_col, t.vsel, t.select, t.nsel, t.mode })) { pane.clearPointerSelection(sel_slot); pane.sel[sel_slot].state = .none; }; @@ -773,9 +772,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void { t.select = false; } else { t.select = true; - if (t.msel.active) { - t.setRange(text, 0, range, true); - } else if (!t.vsel.active) { + if (!t.vsel.active) { t.vsel = .{ .active = true, .row = t.cur_row, .col = t.cur_col, .explicit = true }; } else { t.vsel.explicit = true; @@ -788,7 +785,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void { .shrink_to_line_bounds => return t.shrinkSelToLineBounds(text, range), .collapse_selection => return t.setRange(text, 0, .{ .anchor = cur, .head = cur }, false), .flip_selection => { - const explicit = (t.vsel.active and t.vsel.explicit) or t.msel.active; + const explicit = t.vsel.active and t.vsel.explicit; return t.setRange(text, 0, .{ .anchor = range.head, .head = range.anchor }, explicit); }, .select_all => return t.setRange(text, 0, .{ .anchor = 0, .head = text.len }, false), diff --git a/src/pardes.zig b/src/pardes.zig index e46eb5f7..2335711f 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -6177,7 +6177,7 @@ pub const Pardes = struct { const range = t.primaryRange(shown, 0); const lo = @min(range.anchor, range.head); const hi = @max(range.anchor, range.head); - const span: [2]usize = if ((t.vsel.active and t.vsel.explicit) or t.msel.active) + const span: [2]usize = if (t.vsel.active and t.vsel.explicit) .{ lo, hi } else word: { const b = config.wordBounds(shown, modal.selectionCursor(shown, range)); @@ -6202,12 +6202,11 @@ pub const Pardes = struct { } edit.pinPaneCursor(p, &pane.body); const explicit = (p.native_images and pane.hasPdfSelection()) or - (pane.body.vsel.active and pane.body.vsel.explicit) or pane.body.msel.active; + (pane.body.vsel.active and pane.body.vsel.explicit); if (explicit) { if (exec.chordEachSel(p, pane, cmd)) return; if (edit.currentSelText(p, pane)) |txt| { pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.select = false; // The execute key on a body: text a bound REPL may take. exec.runBuiltinFrom(p, cmd, p.active, "", txt, true); @@ -6225,13 +6224,13 @@ pub const Pardes = struct { if (t.what == .tag and t.mode == .insert and tagline.typedIntoName(p, pane, key)) return; // A tag's prefix is read-only: a key whose edit reached into it // changes nothing, not even where the cursor is. - const kept = .{ t.cur_row, t.cur_col, t.vsel, t.msel }; + const kept = .{ t.cur_row, t.cur_col, t.vsel }; var kept_sels: [Text.max_selections - 1]Text.SelRange = undefined; const kept_n = t.nsel; @memcpy(kept_sels[0..kept_n], t.sels[0..kept_n]); t.refused = false; defer if (t.refused) { - t.cur_row, t.cur_col, t.vsel, t.msel = kept; + t.cur_row, t.cur_col, t.vsel = kept; t.restoreSels(kept_sels[0..kept_n]); }; const was = t.mode; @@ -6623,7 +6622,6 @@ pub const Pardes = struct { pane.body.cur_row = @intCast(cursor.row); pane.body.cur_col = @intCast(cursor.col); pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.select = false; pane.body.sticky_col = -1; pane.ensureCursorVisible(); diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 7f9c7b55..42d923ac 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -2758,7 +2758,6 @@ fn refreshCleanSections(core: *pardes.Pardes, state: *State) void { @as(usize, @intCast(@max(0, result.body.cur_col))), modal.lineSlice(file.content, row).len, )); - result.body.msel.active = false; result.body.vsel.active = false; result.body.nsel = 0; state.sections_output.?.revision = file.revision; @@ -2793,7 +2792,6 @@ fn rearmCleanSections( file.scroll = 0; result.body.cur_row = 0; result.body.cur_col = 0; - result.body.msel.active = false; result.body.vsel.active = false; result.body.nsel = 0; pane.search_pane = remembered.pane; @@ -2919,7 +2917,6 @@ pub fn resetPageChrome(pane: *pardes.Pane) void { pane.body.cur_row = 0; pane.body.cur_col = 0; pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.nsel = 0; } @@ -3290,7 +3287,6 @@ pub fn pointerRelease( if (!dragged) state.clearSelection(core.pdf_gpa); pane.body.cur_pinned = true; pane.body.mode = .normal; - pane.body.msel.active = false; pane.body.vsel.active = false; pane.body.normal.clear(); pane.body.nsel = 0; diff --git a/src/tagline.zig b/src/tagline.zig index e7194981..66a037f2 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -233,7 +233,6 @@ pub fn enterTag(p: *Pardes, pane: *Pane) void { const line = modal.lineSlice(whole, @intCast(t.cur_row)); t.cur_col = @intCast(modal.graphemeStart(line, @min(line.len, @as(usize, @intCast(@max(0, t.cur_col)))))); t.vsel.active = false; - t.msel.active = false; t.nsel = 0; t.select = false; t.restore_cursor = false; @@ -415,7 +414,6 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { t.cur_col = @intCast(modal.graphemeStart(line, @min(line.len, @as(usize, @intCast(@max(0, t.cur_col)))))); t.cur_pinned = true; t.vsel.active = false; - t.msel.active = false; t.nsel = 0; t.select = false; t.restore_cursor = false; diff --git a/src/terminal.zig b/src/terminal.zig index e8ab7a09..7cb429d9 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -1195,7 +1195,7 @@ pub fn feedOutput(p: *Pardes, pane: *Pane, bytes: []const u8) void { if (pane.terminal == null) return; if (authorityOnly("a terminal's output")) return; const has_positions = pane.ovl != null or pane.body.cur_pinned or pane.body.vsel.active or - pane.body.msel.active or pane.body.nsel > 0 or pane.body.last_edit != null or pane.look_at != null or + pane.body.nsel > 0 or pane.body.last_edit != null or pane.look_at != null or pane.body.ed_undo_len > 0 or pane.body.ed_redo_len > 0 or pointerRowCount(pane) > 0; // A replica's emulator is what the authority's deltas make it; what // pardes keeps over it moves as the authority's ingest told it. @@ -1339,15 +1339,9 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) bool { // Where the live pane's own selections sit in `positions`: one whose // row the program erased goes (below), as the edited copy does. const vsel_at: ?usize = if (pane.body.vsel.active) 1 else null; - const msel_at: ?usize = if (pane.body.msel.active) npositions else null; - const sels_at = npositions + @as(usize, if (pane.body.msel.active) 2 else 0); - var extra: [panes.Text.max_selections * 2 + 4]*i32 = undefined; + const sels_at = npositions; + var extra: [panes.Text.max_selections * 2 + 2]*i32 = undefined; var nextra: usize = 0; - if (pane.body.msel.active) { - extra[nextra] = &pane.body.msel.r0; - extra[nextra + 1] = &pane.body.msel.r1; - nextra += 2; - } for (pane.body.sels[0..pane.body.nsel]) |*selection| { extra[nextra] = &selection.row; extra[nextra + 1] = &selection.arow; @@ -1447,7 +1441,6 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) bool { erased[i] or (copy_lost and positions[i].edit_row != null) else false; - const msel_lost = if (msel_at) |i| erased[i] or erased[i + 1] else false; var sels_keep: [panes.Text.max_selections]bool = undefined; for (0..pane.body.nsel) |i| sels_keep[i] = !(erased[sels_at + 2 * i] or erased[sels_at + 2 * i + 1]); for ([_][]PositionPin{ positions[0..npositions], pointers }, [_]usize{ at_position, at_pointer }) |batch, first| for (batch, first..) |position, k| { @@ -1474,10 +1467,6 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) bool { pane.body.vsel.active = false; moved = true; } - if (msel_lost) { - pane.body.msel.active = false; - moved = true; - } if (pane.body.nsel > 0) { var kept: u16 = 0; for (0..pane.body.nsel) |i| if (sels_keep[i]) { @@ -1774,7 +1763,6 @@ pub fn enterTty(p: *Pardes, id: usize) void { pane.body.mode = .tty; followOutput(pane); // entering raw mode is a request for the live shell - pane.body.msel.active = false; pane.body.vsel.active = false; pane.body.nsel = 0; // The raw renderer follows the live cursor. A captured mouse selection @@ -3445,10 +3433,8 @@ test "a selection whose row ED 3 erased goes; one on the screen stays" { const top: i32 = @intCast(pages.total_rows - pane.rows); const row: i32 = if (in_history) top - 3 else top + 2; pane.body.vsel = .{ .active = true, .row = row, .col = 1 }; - pane.body.msel = .{ .active = true, .r0 = row, .r1 = row }; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } }); try std.testing.expectEqual(!in_history, pane.body.vsel.active); - try std.testing.expectEqual(!in_history, pane.body.msel.active); if (!in_history) try std.testing.expectEqual(@as(i32, 2), pane.body.vsel.row); } } diff --git a/src/views.zig b/src/views.zig index b1786f83..337b5a23 100644 --- a/src/views.zig +++ b/src/views.zig @@ -56,7 +56,7 @@ pub const fields = [_][:0]const u8{ const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices", "pan" }; /// The body's: its cursor, selections and mode. Its undo stays the pane's. -const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "msel", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" }; +const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" }; pub const View = Part(Pardes, &fields); @@ -303,7 +303,6 @@ fn apply(pane: *Pane, v: *const PaneView) void { f.scroll = @min(v.scroll, lines -| 1); if (pane.body.cur_row >= lines) { pane.body.vsel.active = false; - pane.body.msel.active = false; pane.body.nsel = 0; } _ = pardes.edit.clampFileCursor(&pane.body); |
