diff options
Diffstat (limited to 'src/exec.zig')
| -rw-r--r-- | src/exec.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/exec.zig b/src/exec.zig index d7a88ecc..73413910 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -217,6 +217,28 @@ pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { return null; } +/// 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; + 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; + const d = @import("ninep/pane.zig").dotOf(t); + return std.fmt.bufPrint(buf, "{s}:#{d},#{d}", .{ f.path, d.q0, d.q1 }) catch null; + } + } + return null; +} + /// A clicked word and the selection held for it, as one command line. pub fn withArg(p: *Pardes, txt: []const u8, arg: ?[]const u8) []const u8 { const a = std.mem.trim(u8, arg orelse return txt, " \t\r\n"); |
