diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-23 10:56:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-23 17:10:58 -0300 |
| commit | a0d367b6c54ff29737662fd7cf5a78d4d183cb20 (patch) | |
| tree | 295dfa438f54b72a907d2c847784d5b5982fca9e /src/exec.zig | |
| parent | 7b743fcc7d568f13512a59089c5214bb6fa3282f (diff) | |
| download | pardes-a0d367b6c54ff29737662fd7cf5a78d4d183cb20.tar.gz pardes-a0d367b6c54ff29737662fd7cf5a78d4d183cb20.zip | |
Audit (core, modal): goto/insert/select tables, edit through sam.Op and sam.apply, Turn.bump and awaitPast, dead helpers out
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/exec.zig')
| -rw-r--r-- | src/exec.zig | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/src/exec.zig b/src/exec.zig index c9f304b0..eb15dbc9 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -210,13 +210,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l var expanded = clicked; if (pane.file != null) { result.file_word = .{ .row = row, .lo = 0, .hi = hi }; - const first = pane.wrapRow(row, 0); - const last = pane.wrapRow(row, hi - 1); - if (first.row < 0 or last.row < 0) return result; - expanded.r0 = first.row + @as(i32, pane.tag_rows); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, 0); - expanded.r1 = last.row + @as(i32, pane.tag_rows); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + expanded = fileWordCells(pane, clicked, row, 0, hi) orelse return result; } else { const shown = if (raw) raw_line else line; expanded.c0 = 0; @@ -236,16 +230,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l const hi = std.math.cast(i32, b.hi) orelse return result; result.text = line[b.lo..b.hi]; result.file_word = .{ .row = row, .lo = lo, .hi = hi }; - - var expanded = clicked; - const first = pane.wrapRow(row, lo); - const last = pane.wrapRow(row, hi - 1); - if (first.row >= 0 and last.row >= 0) { - expanded.r0 = first.row + @as(i32, pane.tag_rows); - expanded.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, lo); - expanded.r1 = last.row + @as(i32, pane.tag_rows); - expanded.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); - } + const expanded = fileWordCells(pane, clicked, row, lo, hi) orelse clicked; result.preview = expanded; result.expanded = expanded; return result; @@ -259,16 +244,35 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l return result; } +/// The cells bytes `lo..hi` of a file pane's line `row` take on screen, +/// soft-wrapped or not, as `clicked` reshaped; null when scrolled off. +fn fileWordCells(pane: *Pane, clicked: Pane.Sel, row: i32, lo: i32, hi: i32) ?Pane.Sel { + const first = pane.wrapRow(row, lo); + const last = pane.wrapRow(row, hi - 1); + if (first.row < 0 or last.row < 0) return null; + var cells = clicked; + cells.r0 = first.row + @as(i32, pane.tag_rows); + cells.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, lo); + cells.r1 = last.row + @as(i32, pane.tag_rows); + cells.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + return cells; +} + +/// Where a held selection is looked for, step `k` of `p.panes.len + 2`: +/// `first`, then the active pane, then the rest; null for one seen. +fn heldPane(p: *Pardes, first: usize, k: usize) ?*Pane { + const i = switch (k) { + 0 => first, + 1 => p.active, + else => k - 2, + }; + if (k > 0 and (i == first or (k > 1 and i == p.active))) return null; + return p.panes[i]; +} + pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { - var k: usize = 0; - while (k < p.panes.len + 2) : (k += 1) { - const i = switch (k) { - 0 => first, - 1 => p.active, - else => k - 2, - }; - if (k > 0 and (i == first or (k > 1 and i == p.active))) continue; - const t = p.panes[i] orelse continue; + for (0..p.panes.len + 2) |k| { + const t = heldPane(p, first, k) orelse continue; if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |pv| { if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; @@ -285,15 +289,8 @@ pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { /// Where the selection `heldSelection` would give is, as acme's argument /// location (exec.c:162, getbytearg): `path:#q0,#q1` of a file pane's dot. pub fn heldSelectionPlace(p: *Pardes, first: usize, buf: []u8) ?[]const u8 { - var k: usize = 0; - while (k < p.panes.len + 2) : (k += 1) { - const i = switch (k) { - 0 => first, - 1 => p.active, - else => k - 2, - }; - if (k > 0 and (i == first or (k > 1 and i == p.active))) continue; - const t = p.panes[i] orelse continue; + 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) { const f = t.file orelse return null; @@ -464,18 +461,7 @@ pub fn missingDir(p: *Pardes, dir: []const u8) bool { // the shell would start: no command or terminal runs there, and none // is made to say `exit 127`. const local = @import("fs.zig").localPath(dir) orelse return std.mem.startsWith(u8, dir, "/n/"); - return !isDirectory(local); -} - -/// Whether `path` is a directory on this host, the turn out while it asks -/// (it may be inside a mount this editor serves). -pub fn isDirectory(path: []const u8) bool { - var buf: [4096]u8 = undefined; - const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return false; - pardes.turn.yield(); - defer pardes.turn.back(); - const stat = @import("fs.zig").statPath(std.Io.Threaded.global_single_threaded.io(), z, .{}) catch return false; - return stat.kind == .directory; + return kindOf(local) != .directory; } /// Whether `path` is a plain file on this host, the turn out while it asks. @@ -484,7 +470,7 @@ pub fn isFile(path: []const u8) bool { } /// What `path` is on this host, null when it is not there; the turn out -/// while it asks. +/// while it asks (it may be inside a mount this editor serves). pub fn kindOf(path: []const u8) ?std.Io.File.Kind { var buf: [4096]u8 = undefined; const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return null; |
