From ea31e414ee4b8583cb396e468a74058e65133d72 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 18 Aug 2024 17:59:28 +0200 Subject: [PATCH] refactor: clean-up command naming --- src/Project.zig | 2 +- src/tui/editor.zig | 4 ++-- src/tui/home.zig | 2 +- src/tui/mainview.zig | 4 ++-- src/tui/mode/input/flow.zig | 22 +++++++++++----------- src/tui/mode/input/home.zig | 10 +++++----- src/tui/mode/input/vim/insert.zig | 10 +++++----- src/tui/mode/input/vim/normal.zig | 22 +++++++++++----------- src/tui/mode/input/vim/visual.zig | 22 +++++++++++----------- src/tui/status/linenumstate.zig | 2 +- src/tui/tui.zig | 10 +++++----- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/Project.zig b/src/Project.zig index 681619f..b6f74d2 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -257,7 +257,7 @@ pub fn get_mru_position(self: *Self, from: tp.pid_ref, file_path: []const u8) !v for (self.files.items) |*file| { if (!std.mem.eql(u8, file.path, file_path)) continue; if (file.row != 0) - try from.send(.{ "cmd", "goto", .{ file.row + 1, file.col + 1 } }); + try from.send(.{ "cmd", "goto_line_and_column", .{ file.row + 1, file.col + 1 } }); return; } } diff --git a/src/tui/editor.zig b/src/tui/editor.zig index ef52736..6d87045 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -2976,7 +2976,7 @@ pub const Editor = struct { self.clamp(); } - pub fn open_file(self: *Self, ctx: Context) Result { + pub fn open_buffer_from_file(self: *Self, ctx: Context) Result { var file_path: []const u8 = undefined; if (ctx.args.match(.{tp.extract(&file_path)}) catch false) { try self.open(file_path); @@ -3382,7 +3382,7 @@ pub const Editor = struct { self.clamp(); } - pub fn goto(self: *Self, ctx: Context) Result { + pub fn goto_line_and_column(self: *Self, ctx: Context) Result { try self.send_editor_jump_source(); var line: usize = 0; var column: usize = 0; diff --git a/src/tui/home.zig b/src/tui/home.zig index 9653d7e..49dfce3 100644 --- a/src/tui/home.zig +++ b/src/tui/home.zig @@ -108,7 +108,7 @@ fn menu_action_help(_: **Menu.State(*Self), _: *Button.State(*Menu.State(*Self)) } fn menu_action_open_file(_: **Menu.State(*Self), _: *Button.State(*Menu.State(*Self))) void { - command.executeName("enter_open_file_mode", .{}) catch {}; + command.executeName("open_file", .{}) catch {}; } fn menu_action_open_recent_file(_: **Menu.State(*Self), _: *Button.State(*Menu.State(*Self))) void { diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 5b7de73..b3fd419 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -289,10 +289,10 @@ const cmds = struct { editor.send_editor_jump_source() catch {}; } try self.create_editor(); - try command.executeName("open_file", command.fmt(.{f})); + try command.executeName("open_buffer_from_file", command.fmt(.{f})); } if (goto_args.len != 0) { - try command.executeName("goto", .{ .args = .{ .buf = goto_args } }); + try command.executeName("goto_line_and_column", .{ .args = .{ .buf = goto_args } }); } else if (line) |l| { try command.executeName("goto_line", command.fmt(.{l})); if (!same_file) diff --git a/src/tui/mode/input/flow.zig b/src/tui/mode/input/flow.zig index ee37edb..640cdef 100644 --- a/src/tui/mode/input/flow.zig +++ b/src/tui/mode/input/flow.zig @@ -85,21 +85,21 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'Z' => self.cmd("undo", .{}), 'Y' => self.cmd("redo", .{}), 'Q' => self.cmd("quit", .{}), - 'O' => self.cmd("enter_open_file_mode", .{}), + 'O' => self.cmd("open_file", .{}), 'W' => self.cmd("close_file", .{}), 'S' => self.cmd("save_file", .{}), 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), - 'B' => self.cmd("enter_move_to_char_mode", command.fmt(.{false})), - 'T' => self.cmd("enter_move_to_char_mode", command.fmt(.{true})), + 'B' => self.cmd("move_to_char", command.fmt(.{false})), + 'T' => self.cmd("move_to_char", command.fmt(.{true})), 'X' => self.cmd("cut", .{}), 'C' => self.cmd("copy", .{}), 'V' => self.cmd("system_paste", .{}), 'U' => self.cmd("pop_cursor", .{}), 'K' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers }, - 'F' => self.cmd("enter_find_mode", .{}), - 'G' => self.cmd("enter_goto_mode", .{}), + 'F' => self.cmd("find", .{}), + 'G' => self.cmd("goto", .{}), 'D' => self.cmd("add_cursor_next_match", .{}), 'A' => self.cmd("select_all", .{}), 'I' => self.insert_bytes("\t"), @@ -126,7 +126,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'Z' => self.cmd("redo", .{}), 'Q' => self.cmd("quit_without_saving", .{}), 'W' => self.cmd("close_file_without_saving", .{}), - 'F' => self.cmd("enter_find_in_files_mode", .{}), + 'F' => self.cmd("find_in_files", .{}), 'L' => self.cmd_async("add_cursor_all_matches"), 'I' => self.cmd_async("toggle_inspector_view"), 'M' => self.cmd("show_diagnostics", .{}), @@ -330,11 +330,11 @@ const hints = tui.KeybindHints.initComptime(.{ .{ "dupe_up", "S-A-d" }, .{ "enable_fast_scroll", "hold Ctrl" }, .{ "enable_jump_mode", "hold Alt" }, - .{ "enter_find_in_files_mode", "C-S-f" }, - .{ "enter_find_mode", "C-f" }, - .{ "enter_goto_mode", "C-g" }, - .{ "enter_move_to_char_mode", "C-b, C-t" }, // true/false - .{ "enter_open_file_mode", "C-o" }, + .{ "find_in_files", "C-S-f" }, + .{ "find", "C-f" }, + .{ "goto", "C-g" }, + .{ "move_to_char", "C-b, C-t" }, // true/false + .{ "open_file", "C-o" }, .{ "filter", "A-s" }, // self.cmd("filter", command.fmt(.{"sort"})), // .{ "filter", "S-A-s" }, // self.cmd("filter", command.fmt(.{ "sort", "-u" })), .{ "format", "S-A-f" }, diff --git a/src/tui/mode/input/home.zig b/src/tui/mode/input/home.zig index 71853f0..ac39839 100644 --- a/src/tui/mode/input/home.zig +++ b/src/tui/mode/input/home.zig @@ -61,7 +61,7 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result { 'J' => self.cmd("toggle_panel", .{}), 'Q' => self.cmd("quit", .{}), 'W' => self.cmd("quit", .{}), - 'O' => self.cmd("enter_open_file_mode", .{}), + 'O' => self.cmd("open_file", .{}), 'E' => self.cmd("open_recent", .{}), 'P' => self.cmd("open_command_palette", .{}), '/' => self.cmd("open_help", .{}), @@ -72,7 +72,7 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result { 'P' => self.cmd("open_command_palette", .{}), 'Q' => self.cmd("quit_without_saving", .{}), 'R' => self.cmd("restart", .{}), - 'F' => self.cmd("enter_find_in_files_mode", .{}), + 'F' => self.cmd("find_in_files", .{}), 'L' => self.cmd_async("toggle_panel"), '/' => self.cmd("open_help", .{}), else => {}, @@ -92,7 +92,7 @@ fn mapPress(self: *Self, keypress: u32, modifiers: u32) tp.result { }, 0 => switch (keypress) { 'h' => self.cmd("open_help", .{}), - 'o' => self.cmd("enter_open_file_mode", .{}), + 'o' => self.cmd("open_file", .{}), 'e' => self.cmd("open_recent", .{}), 'r' => self.msg("open recent project not implemented"), 'p' => self.cmd("open_command_palette", .{}), @@ -154,8 +154,8 @@ fn sheeran(self: *Self) void { } const hints = tui.KeybindHints.initComptime(.{ - .{ "enter_find_in_files_mode", "C-S-f" }, - .{ "enter_open_file_mode", "o, C-o" }, + .{ "find_in_files", "C-S-f" }, + .{ "open_file", "o, C-o" }, .{ "open_recent", "e, C-e" }, .{ "open_command_palette", "p, C-S-p, S-A-p" }, .{ "home_menu_activate", "enter" }, diff --git a/src/tui/mode/input/vim/insert.zig b/src/tui/mode/input/vim/insert.zig index 4a8dfd5..0b7c483 100644 --- a/src/tui/mode/input/vim/insert.zig +++ b/src/tui/mode/input/vim/insert.zig @@ -97,14 +97,14 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), - 'B' => self.cmd("enter_move_to_char_mode", command.fmt(.{false})), - 'T' => self.cmd("enter_move_to_char_mode", command.fmt(.{true})), + 'B' => self.cmd("move_to_char", command.fmt(.{false})), + 'T' => self.cmd("move_to_char", command.fmt(.{true})), 'X' => self.cmd("cut", .{}), 'C' => self.cmd("enter_mode", command.fmt(.{"vim/normal"})), 'V' => self.cmd("system_paste", .{}), 'K' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers }, - 'F' => self.cmd("enter_find_mode", .{}), - 'G' => self.cmd("enter_goto_mode", .{}), + 'F' => self.cmd("find", .{}), + 'G' => self.cmd("goto", .{}), 'O' => self.cmd("run_ls", .{}), 'A' => self.cmd("select_all", .{}), 'I' => self.insert_bytes("\t"), @@ -131,7 +131,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'Z' => self.cmd("redo", .{}), 'Q' => self.cmd("quit_without_saving", .{}), 'W' => self.cmd("close_file_without_saving", .{}), - 'F' => self.cmd("enter_find_in_files_mode", .{}), + 'F' => self.cmd("find_in_files", .{}), 'L' => self.cmd_async("add_cursor_all_matches"), 'I' => self.cmd_async("toggle_inspector_view"), key.ENTER => self.cmd("smart_insert_line_before", .{}), diff --git a/src/tui/mode/input/vim/normal.zig b/src/tui/mode/input/vim/normal.zig index 05c33cd..cc7c9b6 100644 --- a/src/tui/mode/input/vim/normal.zig +++ b/src/tui/mode/input/vim/normal.zig @@ -104,14 +104,14 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), - 'B' => self.cmd("enter_move_to_char_mode", command.fmt(.{false})), - 'T' => self.cmd("enter_move_to_char_mode", command.fmt(.{true})), + 'B' => self.cmd("move_to_char", command.fmt(.{false})), + 'T' => self.cmd("move_to_char", command.fmt(.{true})), 'X' => self.cmd("cut", .{}), 'C' => self.cmd("copy", .{}), 'V' => self.cmd("system_paste", .{}), 'K' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers }, - 'F' => self.cmd("enter_find_mode", .{}), - 'G' => self.cmd("enter_goto_mode", .{}), + 'F' => self.cmd("find", .{}), + 'G' => self.cmd("goto", .{}), 'A' => self.cmd("select_all", .{}), '/' => self.cmd("toggle_comment", .{}), key.ENTER => self.cmd("smart_insert_line_after", .{}), @@ -136,7 +136,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'Z' => self.cmd("redo", .{}), 'Q' => self.cmd("quit_without_saving", .{}), 'W' => self.cmd("close_file_without_saving", .{}), - 'F' => self.cmd("enter_find_in_files_mode", .{}), + 'F' => self.cmd("find_in_files", .{}), 'L' => self.cmd_async("add_cursor_all_matches"), 'I' => self.cmd_async("toggle_inspector_view"), key.ENTER => self.cmd("smart_insert_line_before", .{}), @@ -235,7 +235,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'a' => self.seq(.{ "move_right", "enter_mode" }, command.fmt(.{"vim/insert"})), 'v' => self.cmd("enter_mode", command.fmt(.{"vim/visual"})), - '/' => self.cmd("enter_find_mode", .{}), + '/' => self.cmd("find", .{}), 'n' => self.cmd("goto_next_match", .{}), 'h' => self.cmd_count("move_left_vim", .{}), @@ -515,11 +515,11 @@ const hints = tui.KeybindHints.initComptime(.{ .{ "dupe_up", "S-A-d" }, .{ "enable_fast_scroll", "hold Ctrl" }, .{ "enable_jump_mode", "hold Alt" }, - .{ "enter_find_in_files_mode", "C-S-f" }, - .{ "enter_find_mode", "C-f, /" }, - .{ "enter_goto_mode", "C-g" }, - .{ "enter_move_to_char_mode", "C-b, C-t" }, // true/false - .{ "enter_open_file_mode", "C-o" }, + .{ "find_in_files", "C-S-f" }, + .{ "find", "C-f, /" }, + .{ "goto", "C-g" }, + .{ "move_to_char", "C-b, C-t" }, // true/false + .{ "open_file", "C-o" }, .{ "filter", "A-s" }, // self.cmd("filter", command.fmt(.{"sort"})), // .{ "filter", "S-A-s" }, // self.cmd("filter", command.fmt(.{ "sort", "-u" })), .{ "format", "S-A-f" }, diff --git a/src/tui/mode/input/vim/visual.zig b/src/tui/mode/input/vim/visual.zig index 6aca3b0..ad4fb1d 100644 --- a/src/tui/mode/input/vim/visual.zig +++ b/src/tui/mode/input/vim/visual.zig @@ -104,14 +104,14 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'L' => self.cmd_cycle3("scroll_view_center", "scroll_view_top", "scroll_view_bottom", .{}), 'N' => self.cmd("goto_next_match", .{}), 'P' => self.cmd("goto_prev_match", .{}), - 'B' => self.cmd("enter_move_to_char_mode", command.fmt(.{false})), - 'T' => self.cmd("enter_move_to_char_mode", command.fmt(.{true})), + 'B' => self.cmd("move_to_char", command.fmt(.{false})), + 'T' => self.cmd("move_to_char", command.fmt(.{true})), 'X' => self.cmd("cut", .{}), 'C' => self.cmd("copy", .{}), 'V' => self.cmd("system_paste", .{}), 'K' => self.leader = .{ .keypress = keynormal, .modifiers = modifiers }, - 'F' => self.cmd("enter_find_mode", .{}), - 'G' => self.cmd("enter_goto_mode", .{}), + 'F' => self.cmd("find", .{}), + 'G' => self.cmd("goto", .{}), 'A' => self.cmd("select_all", .{}), '/' => self.cmd("toggle_comment", .{}), key.ENTER => self.cmd("smart_insert_line_after", .{}), @@ -136,7 +136,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'Z' => self.cmd("redo", .{}), 'Q' => self.cmd("quit_without_saving", .{}), 'W' => self.cmd("close_file_without_saving", .{}), - 'F' => self.cmd("enter_find_in_files_mode", .{}), + 'F' => self.cmd("find_in_files", .{}), 'L' => self.cmd_async("add_cursor_all_matches"), 'I' => self.cmd_async("toggle_inspector_view"), key.ENTER => self.cmd("smart_insert_line_before", .{}), @@ -233,7 +233,7 @@ fn mapPress(self: *Self, keypress: u32, egc: u32, modifiers: u32) !void { 'a' => self.seq(.{ "move_right", "enter_mode" }, command.fmt(.{"vim/insert"})), 'v' => self.cmd("enter_mode", command.fmt(.{"vim/visual"})), - '/' => self.cmd("enter_find_mode", .{}), + '/' => self.cmd("find", .{}), 'n' => self.cmd("goto_next_match", .{}), 'h' => self.cmd_count("select_left", .{}), @@ -475,11 +475,11 @@ const hints = tui.KeybindHints.initComptime(.{ .{ "dupe_up", "S-A-d" }, .{ "enable_fast_scroll", "hold Ctrl" }, .{ "enable_jump_mode", "hold Alt" }, - .{ "enter_find_in_files_mode", "C-S-f" }, - .{ "enter_find_mode", "C-f, /" }, - .{ "enter_goto_mode", "C-g" }, - .{ "enter_move_to_char_mode", "C-b, C-t" }, // true/false - .{ "enter_open_file_mode", "C-o" }, + .{ "find_in_files", "C-S-f" }, + .{ "find", "C-f, /" }, + .{ "goto", "C-g" }, + .{ "move_to_char", "C-b, C-t" }, // true/false + .{ "open_file", "C-o" }, .{ "filter", "A-s" }, // self.cmd("filter", command.fmt(.{"sort"})), // .{ "filter", "S-A-s" }, // self.cmd("filter", command.fmt(.{ "sort", "-u" })), .{ "format", "S-A-f" }, diff --git a/src/tui/status/linenumstate.zig b/src/tui/status/linenumstate.zig index 5bd281b..775f269 100644 --- a/src/tui/status/linenumstate.zig +++ b/src/tui/status/linenumstate.zig @@ -31,7 +31,7 @@ pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) } fn on_click(_: *Self, _: *Button.State(Self)) void { - command.executeName("enter_goto_mode", .{}) catch {}; + command.executeName("goto", .{}) catch {}; } pub fn layout(self: *Self, _: *Button.State(Self)) Widget.Layout { diff --git a/src/tui/tui.zig b/src/tui/tui.zig index cbad2ca..914a293 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -654,23 +654,23 @@ const cmds = struct { if (self.input_mode) |*mode| mode.deinit(); } - pub fn enter_find_mode(self: *Self, ctx: Ctx) Result { + pub fn find(self: *Self, ctx: Ctx) Result { return enter_mini_mode(self, @import("mode/mini/find.zig"), ctx); } - pub fn enter_find_in_files_mode(self: *Self, ctx: Ctx) Result { + pub fn find_in_files(self: *Self, ctx: Ctx) Result { return enter_mini_mode(self, @import("mode/mini/find_in_files.zig"), ctx); } - pub fn enter_goto_mode(self: *Self, ctx: Ctx) Result { + pub fn goto(self: *Self, ctx: Ctx) Result { return enter_mini_mode(self, @import("mode/mini/goto.zig"), ctx); } - pub fn enter_move_to_char_mode(self: *Self, ctx: Ctx) Result { + pub fn move_to_char(self: *Self, ctx: Ctx) Result { return enter_mini_mode(self, @import("mode/mini/move_to_char.zig"), ctx); } - pub fn enter_open_file_mode(self: *Self, ctx: Ctx) Result { + pub fn open_file(self: *Self, ctx: Ctx) Result { return enter_mini_mode(self, @import("mode/mini/open_file.zig"), ctx); }