From 386453ee615cd9c62bb6bccd4f1969bc52a4539a Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 20 Nov 2024 19:45:00 +0100 Subject: [PATCH] fix: move keybind command arguments to stack before executing This avoids problems with commands that cause the current mode to be deleted before the arguments are read such as `enter_mode`. --- src/keybind/builtin/vim.json | 8 ++++---- src/keybind/keybind.zig | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/keybind/builtin/vim.json b/src/keybind/builtin/vim.json index ef7d9a6..714967e 100644 --- a/src/keybind/builtin/vim.json +++ b/src/keybind/builtin/vim.json @@ -8,8 +8,8 @@ ["l", "move_right_vim"], ["h", "move_left"], ["", "move_right_vim"], - ["i", "enter_mode", "insert"], - ["v", "enter_mode", "visual"], + ["i", "enter_mode", "vim/insert"], + ["v", "enter_mode", "vim/visual"], ["/", "find"], ["n", "goto_next_match"], ["0", "move_begin"], @@ -32,8 +32,8 @@ "insert": { "syntax": "vim", "press": [ - ["jk", "enter_mode", "normal"], - ["", "enter_mode", "normal"] + ["jk", "enter_mode", "vim/normal"], + ["", "enter_mode", "vim/normal"] ] } } diff --git a/src/keybind/keybind.zig b/src/keybind/keybind.zig index 312a193..c76cdde 100644 --- a/src/keybind/keybind.zig +++ b/src/keybind/keybind.zig @@ -119,7 +119,9 @@ const Binding = struct { command.get_id_cache(self.command, &self.command_id) orelse { return tp.exit_fmt("CommandNotFound: {s}", .{self.command}); }; - try command.execute(id, .{ .args = .{ .buf = self.args } }); + var buf: [2048]u8 = undefined; + @memcpy(buf[0..self.args.len], self.args); + try command.execute(id, .{ .args = .{ .buf = buf[0..self.args.len] } }); } const MatchResult = enum { match_impossible, match_possible, matched };