feat(file_browser): complete into subdirs when there is only one match
This commit is contained in:
parent
261acbc681
commit
1f74ef2559
1 changed files with 15 additions and 2 deletions
|
@ -24,6 +24,7 @@ pub fn Create(options: type) type {
|
|||
match: std.ArrayList(u8),
|
||||
entries: std.ArrayList(Entry),
|
||||
complete_trigger_count: usize = 0,
|
||||
total_matches: usize = 0,
|
||||
matched_entry: usize = 0,
|
||||
commands: Commands = undefined,
|
||||
|
||||
|
@ -172,14 +173,23 @@ pub fn Create(options: type) type {
|
|||
fn do_complete(self: *Self) !void {
|
||||
self.complete_trigger_count = @min(self.complete_trigger_count, self.entries.items.len);
|
||||
self.file_path.clearRetainingCapacity();
|
||||
const match_number = self.complete_trigger_count;
|
||||
if (self.match.items.len > 0) {
|
||||
try self.match_path();
|
||||
if (self.total_matches == 1)
|
||||
self.complete_trigger_count = 0;
|
||||
} else if (self.entries.items.len > 0) {
|
||||
try self.construct_path(self.query.items, self.entries.items[self.complete_trigger_count - 1], self.complete_trigger_count - 1);
|
||||
} else {
|
||||
try self.construct_path(self.query.items, .{ .name = "", .type = .file }, 0);
|
||||
}
|
||||
message("{d}/{d}", .{ self.matched_entry + 1, self.entries.items.len });
|
||||
if (self.match.items.len > 0)
|
||||
if (self.total_matches > 1)
|
||||
message("{d}/{d} ({d}/{d} matches)", .{ self.matched_entry + 1, self.entries.items.len, match_number, self.total_matches })
|
||||
else
|
||||
message("{d}/{d} ({d} match)", .{ self.matched_entry + 1, self.entries.items.len, self.total_matches })
|
||||
else
|
||||
message("{d}/{d}", .{ self.matched_entry + 1, self.entries.items.len });
|
||||
}
|
||||
|
||||
fn construct_path(self: *Self, path_: []const u8, entry: Entry, entry_no: usize) error{OutOfMemory}!void {
|
||||
|
@ -194,6 +204,7 @@ pub fn Create(options: type) type {
|
|||
}
|
||||
|
||||
fn match_path(self: *Self) !void {
|
||||
var found_match: ?usize = null;
|
||||
var matched: usize = 0;
|
||||
var last: ?Entry = null;
|
||||
var last_no: usize = 0;
|
||||
|
@ -202,12 +213,14 @@ pub fn Create(options: type) type {
|
|||
matched += 1;
|
||||
if (matched == self.complete_trigger_count) {
|
||||
try self.construct_path(self.query.items, entry, i);
|
||||
return;
|
||||
found_match = i;
|
||||
}
|
||||
last = entry;
|
||||
last_no = i;
|
||||
}
|
||||
}
|
||||
self.total_matches = matched;
|
||||
if (found_match) |_| return;
|
||||
if (last) |entry| {
|
||||
try self.construct_path(self.query.items, entry, last_no);
|
||||
self.complete_trigger_count = matched;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue