summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-15 13:21:29 -0300
committerGabriel Schneider <[email protected]>2026-09-15 17:24:42 -0300
commit2bdde8c5ec1049ea0f575c6f9165ed4cef00ea50 (patch)
tree0d7879e387223bd19d78a295bee0ba7ab3a62e00 /src/pardes.zig
parent8ec8924cd577f71953f8e420af1cd60da92f3300 (diff)
downloadpardes-2bdde8c5ec1049ea0f575c6f9165ed4cef00ea50.tar.gz
pardes-2bdde8c5ec1049ea0f575c6f9165ed4cef00ea50.zip
Align location results and configure source context
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 8a25f8f9..537b212a 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -7,6 +7,7 @@ pub const modal = @import("modal.zig");
pub const look = @import("look.zig");
pub const filesystem = @import("fs.zig");
pub const syntax = @import("syntax.zig");
+pub const locations_config = @import("locations_config.zig");
const tracy = @import("tracy.zig");
pub const panes = @import("panes.zig");
pub const builtins = @import("builtins.zig");
@@ -1089,6 +1090,32 @@ test "Collapse builtin keeps content and restores the pane from its default tag"
try std.testing.expectEqualStrings(file_pane_tail, Pardes.curTail(pane));
}
+test "LocationsConfig command reports partial updates and survives restore" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("source\n");
+ try std.testing.expect(p.executeBuiltinLine(0, "LocationsConfig context:5 tscontext:on"));
+ try std.testing.expect(p.executeBuiltinLine(0, "LocationsConfig tslocations:off"));
+ const expected: locations_config.Config = .{ .context = 5, .tscontext = true, .tslocations = false };
+ try std.testing.expectEqual(expected, p.locations_config);
+ try std.testing.expect(p.executeBuiltinLine(0, "LocationsConfig context:2 unknown:on"));
+ try std.testing.expectEqual(expected, p.locations_config);
+ var reports: usize = 0;
+ for (p.panes) |slot| {
+ const pane = slot orelse continue;
+ const file = pane.file orelse continue;
+ const out = file.output orelse continue;
+ if (!std.meta.eql(out.from, panes.Output.Origin{ .cmd = .LocationsConfig })) continue;
+ reports += 1;
+ try std.testing.expectEqualStrings("LocationsConfig context:5 tscontext:on tslocations:off\n", file.content);
+ }
+ try std.testing.expectEqual(@as(usize, 1), reports);
+ try p.dumpState();
+ const restored = try Pardes.initFromDump(p.gpa, .{ .tty_only = true }, p.dump_out.?);
+ defer restored.deinit();
+ try std.testing.expectEqual(expected, restored.locations_config);
+}
+
test "TreeContext command and custom tag survive a workspace round trip" {
if (comptime !syntax.enabled) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
@@ -5719,6 +5746,7 @@ pub const Pardes = struct {
/// hands out Pane.serial; monotonic, never reused
next_serial: u32 = 0,
settings: config.Runtime = .{ .font = .{ .tagline_percent = config.gui_tagline_font_percent } },
+ locations_config: locations_config.Config = .{},
tty_filter_palette: panes.Terminal.FilterPalette = .{},
font_request_taken: bool = false,
custom_theme: ?Theme = null,
@@ -9054,10 +9082,15 @@ pub const Pardes = struct {
// fresh results: n starts at the first row, N has nothing behind it
const nrows: i64 = @intCast(std.mem.count(u8, rf.content, "\n") +
@intFromBool(rf.content.len > 0 and rf.content[rf.content.len - 1] != '\n'));
- const step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1;
- if (step < 0 or step >= nrows) return true; // armed, nowhere left to go
- _ = p.jumpResult(id, @intCast(step));
- p.active = id;
+ var step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1;
+ if (delta == 0) return true;
+ const direction: i64 = if (delta > 0) 1 else -1;
+ while (step >= 0 and step < nrows) : (step += direction) {
+ if (!panes.Output.isResultRow(rf, @intCast(step))) continue;
+ _ = p.jumpResult(id, @intCast(step));
+ p.active = id;
+ break;
+ }
return true;
}
@@ -12051,6 +12084,7 @@ pub const Pardes = struct {
.topbar = config.topbar_str,
.topbar_custom = if (p.global_tag.custom) p.global_tag.slice("") else null,
.theme = p.theme().name,
+ .locations_config = p.locations_config,
.columns = columns[0..columns_len],
.panes = dump_panes[0..panes_len],
.mounts = mounts[0..p.fs.mounts.items.len],
@@ -12114,6 +12148,7 @@ pub const Pardes = struct {
var parsed = try dump.readZon(gpa, zon_bytes, "load");
defer parsed.deinit();
const st = parsed.value;
+ p.locations_config = st.locations_config;
for (st.mounts) |mount| {
var already_mounted = false;
for (p.fs.mounts.items) |existing| {