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),
|
match: std.ArrayList(u8),
|
||||||
entries: std.ArrayList(Entry),
|
entries: std.ArrayList(Entry),
|
||||||
complete_trigger_count: usize = 0,
|
complete_trigger_count: usize = 0,
|
||||||
|
total_matches: usize = 0,
|
||||||
matched_entry: usize = 0,
|
matched_entry: usize = 0,
|
||||||
commands: Commands = undefined,
|
commands: Commands = undefined,
|
||||||
|
|
||||||
|
@ -172,14 +173,23 @@ pub fn Create(options: type) type {
|
||||||
fn do_complete(self: *Self) !void {
|
fn do_complete(self: *Self) !void {
|
||||||
self.complete_trigger_count = @min(self.complete_trigger_count, self.entries.items.len);
|
self.complete_trigger_count = @min(self.complete_trigger_count, self.entries.items.len);
|
||||||
self.file_path.clearRetainingCapacity();
|
self.file_path.clearRetainingCapacity();
|
||||||
|
const match_number = self.complete_trigger_count;
|
||||||
if (self.match.items.len > 0) {
|
if (self.match.items.len > 0) {
|
||||||
try self.match_path();
|
try self.match_path();
|
||||||
|
if (self.total_matches == 1)
|
||||||
|
self.complete_trigger_count = 0;
|
||||||
} else if (self.entries.items.len > 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);
|
try self.construct_path(self.query.items, self.entries.items[self.complete_trigger_count - 1], self.complete_trigger_count - 1);
|
||||||
} else {
|
} else {
|
||||||
try self.construct_path(self.query.items, .{ .name = "", .type = .file }, 0);
|
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 {
|
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 {
|
fn match_path(self: *Self) !void {
|
||||||
|
var found_match: ?usize = null;
|
||||||
var matched: usize = 0;
|
var matched: usize = 0;
|
||||||
var last: ?Entry = null;
|
var last: ?Entry = null;
|
||||||
var last_no: usize = 0;
|
var last_no: usize = 0;
|
||||||
|
@ -202,12 +213,14 @@ pub fn Create(options: type) type {
|
||||||
matched += 1;
|
matched += 1;
|
||||||
if (matched == self.complete_trigger_count) {
|
if (matched == self.complete_trigger_count) {
|
||||||
try self.construct_path(self.query.items, entry, i);
|
try self.construct_path(self.query.items, entry, i);
|
||||||
return;
|
found_match = i;
|
||||||
}
|
}
|
||||||
last = entry;
|
last = entry;
|
||||||
last_no = i;
|
last_no = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.total_matches = matched;
|
||||||
|
if (found_match) |_| return;
|
||||||
if (last) |entry| {
|
if (last) |entry| {
|
||||||
try self.construct_path(self.query.items, entry, last_no);
|
try self.construct_path(self.query.items, entry, last_no);
|
||||||
self.complete_trigger_count = matched;
|
self.complete_trigger_count = matched;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue