diff --git a/src/keybind/builtin/emacs.json b/src/keybind/builtin/emacs.json index 661a77d..b2a9c71 100644 --- a/src/keybind/builtin/emacs.json +++ b/src/keybind/builtin/emacs.json @@ -1,5 +1,5 @@ { - "normal": { + "project": { "press": [ ["f4", "toggle_input_mode"], ["ctrl+0", "reset_fontsize"], @@ -7,11 +7,17 @@ ["ctrl+-", "adjust_fontsize", -1.0], ["ctrl+r", "find_file"], ["ctrl+h ctrl+a", "open_help"], + ["ctrl+x ctrl+f", "open_file"], + ["ctrl+x b", "open_recent"], ["ctrl+c ctrl+o", "open_recent_project"], ["ctrl+c g", "find_in_files"], ["alt+x", "open_command_palette"], - ["ctrl+x ctrl+c", "quit"], - + ["ctrl+x ctrl+c", "quit"] + ] + }, + "normal": { + "inherit": "project", + "press": [ ["ctrl+g", "cancel"], ["ctrl+_", "undo"], ["\u001f", "undo"], @@ -109,21 +115,9 @@ }, "home": { "on_match_failure": "ignore", + "inherit": "project", "press": [ - ["f", "change_fontface"], - ["f4", "toggle_input_mode"], - ["ctrl+0", "reset_fontsize"], - ["ctrl+=", "adjust_fontsize", 1.0], - ["ctrl+-", "adjust_fontsize", -1.0], - ["ctrl+r", "find_file"], - ["ctrl+h ctrl+a", "open_help"], - ["ctrl+x ctrl+f", "open_file"], - ["ctrl+x ctrl+r", "open_recent"], - ["ctrl+x b", "switch_buffers"], - ["ctrl+c ctrl+o", "open_recent_project"], - ["ctrl+c g", "find_in_files"], - ["alt+x", "open_command_palette"], - ["ctrl+x ctrl+c", "quit"] + ["f", "change_fontface"] ] } } diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index b0c2c03..f32b90a 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -337,7 +337,8 @@ const cmds = struct { tui.rdr().set_terminal_working_directory(project); if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" }); if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" }); - tp.self_pid().send(.{ "cmd", "open_recent" }) catch return; + if (try project_manager.request_most_recent_file(self.allocator)) |file_path| + self.show_file_async_and_free(file_path); } pub const change_project_meta: Meta = .{ .arguments = &.{.string} }; @@ -1223,6 +1224,11 @@ fn toggle_inputview_async(_: *Self) void { tp.self_pid().send(.{ "cmd", "toggle_inputview" }) catch return; } +fn show_file_async_and_free(self: *Self, file_path: []const u8) void { + defer self.allocator.free(file_path); + self.show_file_async(file_path); +} + fn show_file_async(_: *Self, file_path: []const u8) void { tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } }) catch return; } diff --git a/src/tui/mode/mini/open_file.zig b/src/tui/mode/mini/open_file.zig index 3eeb4b6..de60c07 100644 --- a/src/tui/mode/mini/open_file.zig +++ b/src/tui/mode/mini/open_file.zig @@ -2,7 +2,6 @@ const std = @import("std"); const tp = @import("thespian"); const root = @import("root"); const command = @import("command"); -const project_manager = @import("project_manager"); const tui = @import("../../tui.zig"); @@ -11,11 +10,6 @@ pub const Type = @import("file_browser.zig").Create(@This()); pub const create = Type.create; pub fn load_entries(self: *Type) error{ Exit, OutOfMemory }!void { - var project_name_buf: [512]u8 = undefined; - const project_path = tp.env.get().str("project"); - const project_name = project_manager.abbreviate_home(&project_name_buf, project_path); - try self.file_path.appendSlice(project_name); - try self.file_path.append(std.fs.path.sep); const editor = tui.get_active_editor() orelse return; if (editor.file_path) |old_path| if (std.mem.lastIndexOf(u8, old_path, "/")) |pos| @@ -34,15 +28,8 @@ pub fn name(_: *Type) []const u8 { } pub fn select(self: *Type) void { - var buf = std.ArrayList(u8).init(self.allocator); - defer buf.deinit(); - const file_path = project_manager.expand_home(&buf, self.file_path.items); - if (root.is_directory(file_path)) { - tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch return; - tp.self_pid().send(.{ "cmd", "change_project", .{file_path} }) catch {}; - return; - } - if (file_path.len > 0) - tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } }) catch {}; + 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 {}; }