summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-22 09:50:43 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:24 -0300
commita8b457a306a4442975210bcac3f04b56513c61c3 (patch)
tree6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/look.zig
parenta8a1499bdffffc5b6919e24ec957e92fabaf003b (diff)
parent7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff)
downloadpardes-a8b457a306a4442975210bcac3f04b56513c61c3.tar.gz
pardes-a8b457a306a4442975210bcac3f04b56513c61c3.zip
Merge: Def/Refs, the diff viewer, Helix n/N, Callstack, Zig 0.17, Window mode and the terminal cwd fix onto 0.24
The docs keep both sides: 0.24's Ctrl-i fallbacks and typed ls with this line's Window mode, raw Esc and Helix n/N wording. The CHANGELOG's unreleased entries go above 0.24, Def/Refs and the context rows among them. cheatsheet-a4.pdf rendered again; .scratch/ ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/look.zig b/src/look.zig
index 41cfdc0c..f4fbe52e 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -524,7 +524,7 @@ pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel {
const w = pane.wrapRow(pane.body.cur_row, pane.body.cur_col);
const vrow = w.row + @as(i32, pane.tag_rows);
const vcol = if (pane.file != null)
- panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane))
+ w.pad + panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane))
else blk: {
const lines = edit.paneCursorLines(p, &pane.body) catch break :blk pane.body.cur_col;
const local = pane.body.cur_row;
@@ -542,7 +542,10 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
if (normal.selRegexArmed(pane)) |a| {
// helix keeps the pattern in `/`
- if (a.pat.len > 0) p.registers.put(p.gpa, '/', a.pat, 0, 1, true);
+ if (a.pat.len > 0) {
+ p.registers.put(p.gpa, '/', a.pat, 0, 1, true);
+ p.registers.last_search = '/';
+ }
return if (p.promptTarget(pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode);
}
const armed = pane.promptText() orelse return;
@@ -556,7 +559,13 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
else
.text;
_ = runSearch(p, id, armed[slash + 1 ..], kind, .top, true) catch |err| return p.reportError(id, "search", err);
- if (kind == .text) lookFirstHit(p, id);
+ if (kind == .text) {
+ var pattern: std.ArrayList(u8) = .empty;
+ normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return;
+ p.registers.put(p.gpa, '/', pattern.items, 0, 1, true);
+ p.registers.last_search = '/';
+ lookFirstHit(p, id);
+ }
}
fn lookFirstHit(p: *Pardes, id: usize) void {
@@ -662,7 +671,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start
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| {
- const at = std.ascii.indexOfIgnoreCase(ln, pat) orelse continue;
+ const at = std.ascii.findIgnoreCase(ln, pat) orelse continue;
const row = try std.fmt.allocPrint(arena, "{s}:{d}:{d}{c}{d} {s}\n", .{
loc, i + 1, at + 1, config.range_sep, at + pat.len, std.mem.trimEnd(u8, ln, " \t"),
});
@@ -883,7 +892,13 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz
if (grain == .whole) break :span wholeRowSpan(ln);
if (pane.file) |f| if (@as(usize, @intCast(r)) < f.location_rows.len) {
const end = f.location_rows[@intCast(r)].location_end;
- if (end > 0) break :span @as(?Span, .{ .start = 0, .end = end });
+ if (end > 0) {
+ const start_byte = if (f.output != null and std.meta.eql(f.output.?.from, panes.Output.Origin{ .query = .callstack }))
+ @import("locations.zig").treePrefix(ln).end
+ else
+ 0;
+ break :span @as(?Span, .{ .start = start_byte, .end = end });
+ }
};
break :span lineSpan(p, ln, dir, &realbuf);
} orelse continue;
@@ -1048,6 +1063,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke
if (id >= MAX_PANES) return;
const pane = p.panes[id] orelse return;
p.active = id;
+ if (pane.collapsed) layout.toggleCollapse(p, id);
pane.body.normal.clear();
if (pane.hasPdf()) {
if (landing == .keep) return;
@@ -1257,7 +1273,7 @@ fn missText(text: []const u8, buf: *[miss_path_cap + "…".len]u8) []const u8 {
test "a miss names a long path by its start and its end, its middle given up to …" {
var cut: [miss_path_cap + "…".len]u8 = undefined;
- const long = "/home/someone/" ++ "deep/" ** 80 ++ "the-file.zig";
+ const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig";
const said = missText(long, &cut);
try std.testing.expect(said.len <= miss_path_cap);
try std.testing.expect(std.mem.startsWith(u8, said, "/home/someone/"));
@@ -1869,6 +1885,18 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
const before = p.active;
var opened: ?usize = null;
if (!focusPaneByPath(p, target.path, target.at)) {
+ // A .diff or .patch looked at bare: its hunks stacked in a
+ // +Diff (DiffLook hunks), which takes the keyboard as the
+ // file would; one with none in it opens as text.
+ if (p.settings.diff_look == .hunks and !p.look_text and target.at.line == 0 and
+ (std.mem.endsWith(u8, target.path, ".diff") or std.mem.endsWith(u8, target.path, ".patch")))
+ if (filesystem.read(p, target.path)) |bytes| {
+ defer p.gpa.free(bytes);
+ if (panes.Output.openDiff(p, id, target.path, bytes)) |hid| {
+ p.active = hid;
+ return;
+ } else |_| {}
+ } else |_| {};
const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
const nt = panes.File.open(p, free, target.path, target.at.line) catch |err|
return lookOpenFailed(p, id, target.path, err);
@@ -2157,7 +2185,7 @@ test "Look ignores missing and out of bounds pane addresses" {
test "a pointer resting where a look-hover found nothing does not wake the core every frame" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
defer p.deinit();
- _ = try p.setTestFile(" \n" ** 30);
+ _ = try p.setTestFile(std.mem.asBytes(&@as([30][6]u8, @splat(" \n".*))));
p.sync();
const r = p.rects[p.active];
// Resting on blanks in the body: a wait, then nothing to open.
@@ -2527,7 +2555,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
const line = modal.lineSlice(case.text, case.row);
// A diff line written whole; a place, as a script writes it.
const written = if (std.mem.eql(u8, case.name, "change.diff")) line else line[case.sweep[0] .. case.sweep[1] + 1];
- _ = th.wr(p, @intFromEnum(pardes.ctlfs.TopFile.look), written);
+ _ = th.wr(p, @backingInt(pardes.ctlfs.TopFile.look), written);
},
.event_write_back => {
const body = pane.file.?.content;
@@ -2656,7 +2684,7 @@ test "Incl's directories find a name found nowhere else, <name> too; bare Incl l
try std.testing.expectEqual(@as(usize, 0), p.incl.items.len);
}
-test "n in a command pane walks its own file:line places, whoever walked last" {
+test "LookNext in a command pane walks its own file:line places, whoever walked last" {
if (!platform_has_fs) return;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
@@ -2685,12 +2713,12 @@ test "n in a command pane walks its own file:line places, whoever walked last" {
cmd.focus = .body;
cmd.body.mode = .normal;
for ([_]u21{ 'g', 'g' }) |cp| p.update(.{ .key = .{ .cp = cp } });
- p.update(.{ .key = .{ .cp = 'n' } });
+ exec.runBuiltin(p, .LookNext, p.active, "", null);
try std.testing.expectEqual(dst, p.active);
const first = cmd.look_at orelse return error.NoSpot;
const lines = try edit.paneCursorLines(p, &cmd.body);
try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(first.row)][@intCast(first.col0)..], "x.c:3:1"));
- p.update(.{ .key = .{ .cp = 'n' } });
+ exec.runBuiltin(p, .LookNext, p.active, "", null);
try std.testing.expectEqual(dst, p.active);
const second = cmd.look_at orelse return error.NoSpot;
try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(second.row)][@intCast(second.col0)..], "y.c:2:1"));
@@ -2740,7 +2768,6 @@ test "Look on a diff under each git prefix opens the repository's file, and a re
}
}
-
test "Look on a diff line is the look of the address it names, selected by hand: a cached patch, the checkout elsewhere" {
if (!platform_has_fs) return;
const io = std.testing.io;