fix: catch more errors in file browser
This commit is contained in:
parent
67f49110dc
commit
b1362814db
5 changed files with 20 additions and 18 deletions
|
@ -175,13 +175,13 @@ pub fn Create(options: type) type {
|
|||
self.entries.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
fn try_complete_file(self: *Self) !void {
|
||||
fn try_complete_file(self: *Self) project_manager.Error!void {
|
||||
self.complete_trigger_count += 1;
|
||||
if (self.complete_trigger_count == 1) {
|
||||
self.query.clearRetainingCapacity();
|
||||
self.match.clearRetainingCapacity();
|
||||
self.clear_entries();
|
||||
if (try root.is_directory(self.file_path.items)) {
|
||||
if (root.is_directory(self.file_path.items)) {
|
||||
try self.query.appendSlice(self.file_path.items);
|
||||
} else if (self.file_path.items.len > 0) blk: {
|
||||
const basename_begin = std.mem.lastIndexOfScalar(u8, self.file_path.items, std.fs.path.sep) orelse {
|
||||
|
@ -198,7 +198,7 @@ pub fn Create(options: type) type {
|
|||
}
|
||||
}
|
||||
|
||||
fn reverse_complete_file(self: *Self) !void {
|
||||
fn reverse_complete_file(self: *Self) error{OutOfMemory}!void {
|
||||
if (self.complete_trigger_count < 2) {
|
||||
self.complete_trigger_count = 0;
|
||||
self.file_path.clearRetainingCapacity();
|
||||
|
@ -222,6 +222,10 @@ pub fn Create(options: type) type {
|
|||
try self.process_project_manager(m);
|
||||
return true;
|
||||
}
|
||||
if (try cbor.match(m.buf, .{ "exit", "error.FileNotFound" })) {
|
||||
message("path not found", .{});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -262,13 +266,15 @@ pub fn Create(options: type) type {
|
|||
self.file_path.clearRetainingCapacity();
|
||||
if (self.match.items.len > 0) {
|
||||
try self.match_path();
|
||||
} else {
|
||||
} 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 });
|
||||
}
|
||||
|
||||
fn construct_path(self: *Self, path_: []const u8, entry: Entry, entry_no: usize) !void {
|
||||
fn construct_path(self: *Self, path_: []const u8, entry: Entry, entry_no: usize) error{OutOfMemory}!void {
|
||||
self.matched_entry = entry_no;
|
||||
const path = project_manager.normalize_file_path(path_);
|
||||
try self.file_path.appendSlice(path);
|
||||
|
|
|
@ -10,7 +10,7 @@ pub const Type = @import("file_browser.zig").Create(@This());
|
|||
|
||||
pub const create = Type.create;
|
||||
|
||||
pub fn load_entries(self: *Type) !void {
|
||||
pub fn load_entries(self: *Type) error{ Exit, OutOfMemory }!void {
|
||||
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
|
||||
if (editor.is_dirty()) return tp.exit("unsaved changes");
|
||||
if (editor.file_path) |old_path|
|
||||
|
@ -31,7 +31,7 @@ pub fn name(_: *Type) []const u8 {
|
|||
}
|
||||
|
||||
pub fn select(self: *Type) void {
|
||||
if (root.is_directory(self.file_path.items) catch false) return;
|
||||
if (root.is_directory(self.file_path.items)) return;
|
||||
if (self.file_path.items.len > 0)
|
||||
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = self.file_path.items } }) catch {};
|
||||
command.executeName("exit_mini_mode", .{}) catch {};
|
||||
|
|
|
@ -28,7 +28,7 @@ pub fn name(_: *Type) []const u8 {
|
|||
}
|
||||
|
||||
pub fn select(self: *Type) void {
|
||||
if (root.is_directory(self.file_path.items) catch false) return;
|
||||
if (root.is_directory(self.file_path.items)) return;
|
||||
if (self.file_path.items.len > 0)
|
||||
tp.self_pid().send(.{ "cmd", "save_file_as", .{self.file_path.items} }) catch {};
|
||||
command.executeName("exit_mini_mode", .{}) catch {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue