mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
fix(redo): make redo of Lua mappings in op-pending mode work (#23566)
This commit is contained in:
@@ -881,7 +881,7 @@ static int insert_handle_key(InsertState *s)
|
||||
goto check_pum;
|
||||
|
||||
case K_LUA:
|
||||
map_execute_lua();
|
||||
map_execute_lua(false);
|
||||
|
||||
check_pum:
|
||||
// nvim_select_popupmenu_item() can be called from the handling of
|
||||
|
@@ -1140,7 +1140,7 @@ static int command_line_execute(VimState *state, int key)
|
||||
} else if (s->c == K_COMMAND) {
|
||||
do_cmdline(NULL, getcmdkeycmd, NULL, DOCMD_NOWAIT);
|
||||
} else {
|
||||
map_execute_lua();
|
||||
map_execute_lua(false);
|
||||
}
|
||||
|
||||
// nvim_select_popupmenu_item() can be called from the handling of
|
||||
|
@@ -2986,7 +2986,12 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat)
|
||||
return line_ga.ga_data;
|
||||
}
|
||||
|
||||
bool map_execute_lua(void)
|
||||
/// Handle a Lua mapping: get its LuaRef from typeahead and execute it.
|
||||
///
|
||||
/// @param may_repeat save the LuaRef for redoing with "." later
|
||||
///
|
||||
/// @return false if getting the LuaRef was aborted, true otherwise
|
||||
bool map_execute_lua(bool may_repeat)
|
||||
{
|
||||
garray_T line_ga;
|
||||
int c1 = -1;
|
||||
@@ -3018,6 +3023,10 @@ bool map_execute_lua(void)
|
||||
}
|
||||
|
||||
LuaRef ref = (LuaRef)atoi(line_ga.ga_data);
|
||||
if (may_repeat) {
|
||||
repeat_luaref = ref;
|
||||
}
|
||||
|
||||
Error err = ERROR_INIT;
|
||||
Array args = ARRAY_DICT_INIT;
|
||||
nlua_call_ref(ref, NULL, args, false, &err);
|
||||
|
@@ -3232,7 +3232,7 @@ static void nv_colon(cmdarg_T *cap)
|
||||
}
|
||||
|
||||
if (is_lua) {
|
||||
cmd_result = map_execute_lua();
|
||||
cmd_result = map_execute_lua(true);
|
||||
} else {
|
||||
// get a command line and execute it
|
||||
cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL,
|
||||
|
@@ -5777,6 +5777,11 @@ typedef struct {
|
||||
int rv_arg; ///< extra argument
|
||||
} redo_VIsual_T;
|
||||
|
||||
static bool is_ex_cmdchar(cmdarg_T *cap)
|
||||
{
|
||||
return cap->cmdchar == ':' || cap->cmdchar == K_COMMAND;
|
||||
}
|
||||
|
||||
/// Handle an operator after Visual mode or when the movement is finished.
|
||||
/// "gui_yank" is true when yanking text for the clipboard.
|
||||
void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
@@ -5831,7 +5836,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
if ((redo_yank || oap->op_type != OP_YANK)
|
||||
&& ((!VIsual_active || oap->motion_force)
|
||||
// Also redo Operator-pending Visual mode mappings.
|
||||
|| ((cap->cmdchar == ':' || cap->cmdchar == K_COMMAND)
|
||||
|| ((is_ex_cmdchar(cap) || cap->cmdchar == K_LUA)
|
||||
&& oap->op_type != OP_COLON))
|
||||
&& cap->cmdchar != 'D'
|
||||
&& oap->op_type != OP_FOLD
|
||||
@@ -5851,7 +5856,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
AppendToRedobuffLit(cap->searchbuf, -1);
|
||||
}
|
||||
AppendToRedobuff(NL_STR);
|
||||
} else if (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) {
|
||||
} else if (is_ex_cmdchar(cap)) {
|
||||
// do_cmdline() has stored the first typed line in
|
||||
// "repeat_cmdline". When several lines are typed repeating
|
||||
// won't be possible.
|
||||
@@ -5866,6 +5871,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
AppendToRedobuff(NL_STR);
|
||||
XFREE_CLEAR(repeat_cmdline);
|
||||
}
|
||||
} else if (cap->cmdchar == K_LUA) {
|
||||
AppendNumberToRedobuff(repeat_luaref);
|
||||
AppendToRedobuff(NL_STR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6021,7 +6029,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
prep_redo(oap->regname, cap->count0,
|
||||
get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
|
||||
oap->motion_force, cap->cmdchar, cap->nchar);
|
||||
} else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND) {
|
||||
} else if (!is_ex_cmdchar(cap) && cap->cmdchar != K_LUA) {
|
||||
int opchar = get_op_char(oap->op_type);
|
||||
int extra_opchar = get_extra_op_char(oap->op_type);
|
||||
int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/eval/typval.h"
|
||||
#include "nvim/eval/typval_defs.h"
|
||||
@@ -126,4 +127,7 @@ static inline int op_reg_index(const int regname)
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "ops.h.generated.h"
|
||||
#endif
|
||||
|
||||
EXTERN LuaRef repeat_luaref INIT(= LUA_NOREF); ///< LuaRef for "."
|
||||
|
||||
#endif // NVIM_OPS_H
|
||||
|
@@ -596,7 +596,7 @@ static int terminal_execute(VimState *state, int key)
|
||||
break;
|
||||
|
||||
case K_LUA:
|
||||
map_execute_lua();
|
||||
map_execute_lua(false);
|
||||
break;
|
||||
|
||||
case Ctrl_N:
|
||||
|
@@ -820,7 +820,6 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
feed('asdf\n')
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
|
||||
end)
|
||||
|
||||
it (':map command shows lua mapping correctly', function()
|
||||
@@ -909,6 +908,18 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
eq(2, exec_lua[[return VisibleCount]])
|
||||
end)
|
||||
|
||||
it('redo of lua mappings in op-pending mode work', function()
|
||||
eq(0, exec_lua [[
|
||||
OpCount = 0
|
||||
vim.api.nvim_set_keymap('o', '<F2>', '', {callback = function() OpCount = OpCount + 1 end})
|
||||
return OpCount
|
||||
]])
|
||||
feed('d<F2>')
|
||||
eq(1, exec_lua[[return OpCount]])
|
||||
feed('.')
|
||||
eq(2, exec_lua[[return OpCount]])
|
||||
end)
|
||||
|
||||
it('can overwrite lua mappings', function()
|
||||
eq(0, exec_lua [[
|
||||
GlobalCount = 0
|
||||
|
Reference in New Issue
Block a user