summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/look.zig b/src/look.zig
index 86238413..d53ac76a 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -360,7 +360,12 @@ pub fn resolve(p: ?*pardes.Pardes, word_raw: []const u8, cwd: []const u8, realbu
for (word[config.pane_addr.len..]) |c| {
if (!std.ascii.isDigit(c)) break;
id = id *| 10 +| (c - '0');
- } else return .{ .pane = .{ .id = id, .at = pl.at } };
+ } else {
+ // `@p<serial>`: the pane's serial, as /index and the log name
+ // it, not its slot; one that is not open names none.
+ const slot = if (p) |pp| (pp.paneBySerial(@intCast(@min(id, std.math.maxInt(u32)))) orelse MAX_PANES) else id;
+ return .{ .pane = .{ .id = slot, .at = pl.at } };
+ }
}
for (config.url_schemes) |scheme| {
@@ -635,7 +640,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start
const loc: []const u8 = if (has_path)
std.fs.path.basename(pane.file.?.path)
else
- std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{id}) catch return error.PathTooLong;
+ std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch return error.PathTooLong;
const cl: usize = @intCast(@max(0, pane.body.cur_row));
const cc: usize = @intCast(@max(0, pane.body.cur_col));
for (lines, 0..) |ln, i| {
@@ -1133,7 +1138,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 {
if (comptime pdf_enabled) if (pane.pdf) |doc| return locationText(p, doc.path, target.at);
if (pane.image) |iv| return locationText(p, iv.path, target.at);
var path: [32]u8 = undefined;
- return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{target.id}) catch return null, target.at);
+ return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch return null, target.at);
},
}
}
@@ -1641,6 +1646,16 @@ test "Look copies its operand before releasing pointer selection storage" {
try std.testing.expectEqual(.none, p.drag);
}
+test "@p names a pane by its serial, as /index does" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha\nbravo\n");
+ var realbuf: [4096]u8 = undefined;
+ var word: [32]u8 = undefined;
+ const target = resolve(p, try std.fmt.bufPrint(&word, config.pane_addr ++ "{d}:2", .{pane.serial}), "/", &realbuf);
+ try std.testing.expectEqual(p.paneBySerial(pane.serial).?, target.pane.id);
+}
+
test "Look ignores missing and out of bounds pane addresses" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();