feat(open_recent): always size open recent file list to longest known file path
This commit is contained in:
parent
0abf7bd989
commit
9d9d9388b9
2 changed files with 12 additions and 12 deletions
|
@ -14,6 +14,7 @@ a: std.mem.Allocator,
|
|||
name: []const u8,
|
||||
files: std.ArrayList(File),
|
||||
pending: std.ArrayList(File),
|
||||
longest_file_path: usize = 0,
|
||||
open_time: i64,
|
||||
language_servers: std.StringHashMap(LSP),
|
||||
file_language_server: std.StringHashMap(LSP),
|
||||
|
@ -82,6 +83,7 @@ pub fn restore_state(self: *Self, data: []const u8) !void {
|
|||
error.CborTooShort => return,
|
||||
else => return e,
|
||||
}) {
|
||||
self.longest_file_path = @max(self.longest_file_path, path.len);
|
||||
try self.update_mru_internal(path, mtime, row, col);
|
||||
}
|
||||
}
|
||||
|
@ -133,16 +135,16 @@ pub fn sort_files_by_mtime(self: *Self) void {
|
|||
}
|
||||
|
||||
pub fn request_recent_files(self: *Self, from: tp.pid_ref, max: usize) error{ OutOfMemory, Exit }!void {
|
||||
defer from.send(.{ "PRJ", "recent_done", "" }) catch {};
|
||||
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, "" }) catch {};
|
||||
for (self.files.items, 0..) |file, i| {
|
||||
try from.send(.{ "PRJ", "recent", file.path });
|
||||
try from.send(.{ "PRJ", "recent", self.longest_file_path, file.path });
|
||||
if (i >= max) return;
|
||||
}
|
||||
}
|
||||
|
||||
fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) error{ OutOfMemory, Exit }!usize {
|
||||
var i: usize = 0;
|
||||
defer from.send(.{ "PRJ", "recent_done", query }) catch {};
|
||||
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {};
|
||||
for (self.files.items) |file| {
|
||||
if (file.path.len < query.len) continue;
|
||||
if (std.mem.indexOf(u8, file.path, query)) |idx| {
|
||||
|
@ -150,7 +152,7 @@ fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: [
|
|||
defer self.a.free(matches);
|
||||
var n: usize = 0;
|
||||
while (n < query.len) : (n += 1) matches[n] = idx + n;
|
||||
try from.send(.{ "PRJ", "recent", file.path, matches });
|
||||
try from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, matches });
|
||||
i += 1;
|
||||
if (i >= max) return i;
|
||||
}
|
||||
|
@ -161,7 +163,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) error{ OutOfMemory, Exit }!usize {
|
||||
if (query.len < 3)
|
||||
return self.simple_query_recent_files(from, max, query);
|
||||
defer from.send(.{ "PRJ", "recent_done", query }) catch {};
|
||||
defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {};
|
||||
|
||||
var searcher = try fuzzig.Ascii.init(
|
||||
self.a,
|
||||
|
@ -198,11 +200,12 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co
|
|||
std.mem.sort(Match, matches.items, {}, less_fn);
|
||||
|
||||
for (matches.items[0..@min(max, matches.items.len)]) |match|
|
||||
try from.send(.{ "PRJ", "recent", match.path, match.matches });
|
||||
try from.send(.{ "PRJ", "recent", self.longest_file_path, match.path, match.matches });
|
||||
return @min(max, matches.items.len);
|
||||
}
|
||||
|
||||
pub fn add_pending_file(self: *Self, file_path: []const u8, mtime: i128) error{OutOfMemory}!void {
|
||||
self.longest_file_path = @max(self.longest_file_path, file_path.len);
|
||||
(try self.pending.addOne()).* = .{ .path = try self.a.dupe(u8, file_path), .mtime = mtime };
|
||||
}
|
||||
|
||||
|
|
|
@ -171,9 +171,8 @@ fn process_project_manager(self: *Self, m: tp.message) !void {
|
|||
var file_name: []const u8 = undefined;
|
||||
var matches: []const u8 = undefined;
|
||||
var query: []const u8 = undefined;
|
||||
if (try m.match(.{ "PRJ", "recent", tp.extract(&file_name), tp.extract_cbor(&matches) })) {
|
||||
if (try m.match(.{ "PRJ", "recent", tp.extract(&self.longest), tp.extract(&file_name), tp.extract_cbor(&matches) })) {
|
||||
if (self.need_reset) self.reset_results();
|
||||
self.longest = @max(self.longest, file_name.len);
|
||||
try self.add_item(file_name, matches);
|
||||
self.menu.resize(.{ .y = 0, .x = self.menu_pos_x(), .w = self.menu_width() });
|
||||
if (self.need_select_first) {
|
||||
|
@ -181,9 +180,8 @@ fn process_project_manager(self: *Self, m: tp.message) !void {
|
|||
self.need_select_first = false;
|
||||
}
|
||||
tui.need_render();
|
||||
} else if (try m.match(.{ "PRJ", "recent", tp.extract(&file_name) })) {
|
||||
} else if (try m.match(.{ "PRJ", "recent", tp.extract(&self.longest), tp.extract(&file_name) })) {
|
||||
if (self.need_reset) self.reset_results();
|
||||
self.longest = @max(self.longest, file_name.len);
|
||||
try self.add_item(file_name, null);
|
||||
self.menu.resize(.{ .y = 0, .x = self.menu_pos_x(), .w = self.menu_width() });
|
||||
if (self.need_select_first) {
|
||||
|
@ -191,7 +189,7 @@ fn process_project_manager(self: *Self, m: tp.message) !void {
|
|||
self.need_select_first = false;
|
||||
}
|
||||
tui.need_render();
|
||||
} else if (try m.match(.{ "PRJ", "recent_done", tp.extract(&query) })) {
|
||||
} else if (try m.match(.{ "PRJ", "recent_done", tp.extract(&self.longest), tp.extract(&query) })) {
|
||||
self.query_pending = false;
|
||||
self.need_reset = true;
|
||||
if (!std.mem.eql(u8, self.inputbox.text.items, query))
|
||||
|
@ -290,7 +288,6 @@ fn mapRelease(self: *Self, keypress: u32, _: u32) !void {
|
|||
}
|
||||
|
||||
fn reset_results(self: *Self) void {
|
||||
self.longest = 0;
|
||||
self.need_reset = false;
|
||||
self.menu.reset_items();
|
||||
self.menu.selected = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue