feat: add results count to open_recent palette

This commit is contained in:
CJ van den Berg 2025-11-23 19:35:58 +01:00
parent 7993186aeb
commit 23e66d8fe9
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 16 additions and 5 deletions

View file

@ -381,7 +381,7 @@ pub fn request_n_most_recent_file(self: *Self, from: tp.pid_ref, n: usize) Clien
} }
pub fn request_recent_files(self: *Self, from: tp.pid_ref, max: usize) ClientError!void { pub fn request_recent_files(self: *Self, from: tp.pid_ref, max: usize) ClientError!void {
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, "" }) catch {}; defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, "", self.files.items.len }) catch {};
for (self.files.items, 0..) |file, i| { for (self.files.items, 0..) |file, i| {
from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, file.type, file.icon, file.color }) catch return error.ClientFailed; from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, file.type, file.icon, file.color }) catch return error.ClientFailed;
if (i >= max) return; if (i >= max) return;
@ -468,7 +468,7 @@ pub fn request_new_or_modified_files(self: *Self, from: tp.pid_ref, max: usize)
fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize { fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize {
var i: usize = 0; var i: usize = 0;
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {}; defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query, self.files.items.len }) catch {};
for (self.files.items) |file| { for (self.files.items) |file| {
if (file.path.len < query.len) continue; if (file.path.len < query.len) continue;
if (std.mem.indexOf(u8, file.path, query)) |idx| { if (std.mem.indexOf(u8, file.path, query)) |idx| {
@ -487,7 +487,7 @@ fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: [
pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize { pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize {
if (query.len < 3) if (query.len < 3)
return self.simple_query_recent_files(from, max, query); return self.simple_query_recent_files(from, max, query);
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {}; defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query, self.files.items.len }) catch {};
var searcher = try fuzzig.Ascii.init( var searcher = try fuzzig.Ascii.init(
self.allocator, self.allocator,

View file

@ -38,6 +38,8 @@ longest: usize,
commands: Commands = undefined, commands: Commands = undefined,
buffer_manager: ?*BufferManager, buffer_manager: ?*BufferManager,
split: enum { none, vertical } = .none, split: enum { none, vertical } = .none,
total_items: usize = 0,
total_files_in_project: usize = 0,
const inputbox_label = "Search files by name"; const inputbox_label = "Search files by name";
const MenuType = Menu.Options(*Self).MenuType; const MenuType = Menu.Options(*Self).MenuType;
@ -146,6 +148,7 @@ fn add_item(
indicator: []const u8, indicator: []const u8,
matches: ?[]const u8, matches: ?[]const u8,
) !void { ) !void {
self.total_items += 1;
var label: std.Io.Writer.Allocating = .init(self.allocator); var label: std.Io.Writer.Allocating = .init(self.allocator);
defer label.deinit(); defer label.deinit();
const writer = &label.writer; const writer = &label.writer;
@ -209,12 +212,14 @@ fn process_project_manager(self: *Self, m: tp.message) MessageFilter.Error!void
self.need_select_first = false; self.need_select_first = false;
} }
tui.need_render(); tui.need_render();
} else if (try cbor.match(m.buf, .{ "PRJ", "recent_done", tp.extract(&self.longest), tp.extract(&query) })) { } else if (try cbor.match(m.buf, .{ "PRJ", "recent_done", tp.extract(&self.longest), tp.extract(&query), tp.extract(&self.total_files_in_project) })) {
self.update_count_hint();
self.query_pending = false; self.query_pending = false;
self.need_reset = true; self.need_reset = true;
if (!std.mem.eql(u8, self.inputbox.text.items, query)) if (!std.mem.eql(u8, self.inputbox.text.items, query))
try self.start_query(); try self.start_query();
} else if (try cbor.match(m.buf, .{ "PRJ", "open_done", tp.string, tp.extract(&self.longest), tp.any })) { } else if (try cbor.match(m.buf, .{ "PRJ", "open_done", tp.string, tp.extract(&self.longest), tp.extract(&self.total_files_in_project) })) {
self.update_count_hint();
self.query_pending = false; self.query_pending = false;
self.need_reset = true; self.need_reset = true;
try self.start_query(); try self.start_query();
@ -239,7 +244,13 @@ fn reset_results(self: *Self) void {
self.need_select_first = true; self.need_select_first = true;
} }
fn update_count_hint(self: *Self) void {
self.inputbox.hint.clearRetainingCapacity();
self.inputbox.hint.print(self.inputbox.allocator, "{d}/{d}", .{ self.total_items, self.total_files_in_project }) catch {};
}
fn start_query(self: *Self) MessageFilter.Error!void { fn start_query(self: *Self) MessageFilter.Error!void {
self.total_items = 0;
if (self.query_pending) return; if (self.query_pending) return;
self.query_pending = true; self.query_pending = true;
try project_manager.query_recent_files(max_recent_files, self.inputbox.text.items); try project_manager.query_recent_files(max_recent_files, self.inputbox.text.items);