From f326c9a77da3aef052ce6af0f851344f2479c844 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 6 Jan 2022 13:48:37 +0000 Subject: vim-patch:8.2.4018: ml_get error when win_execute redraws with Visual selection Problem: ml_get error when win_execute redraws with Visual selection. Solution: Disable Visual area temporarily. (closes vim/vim#9479) https://github.com/vim/vim/commit/18f4740f043b353abe47b7a00131317052457686 {switch_to/restore}_win_for_buf is N/A (marked as such in v8.0.0860; currently only used in Vim's if_py). Add a modeline to test_execute_func.vim. --- src/nvim/eval/funcs.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/nvim/eval/funcs.c') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 29619f62e9..3cfc00fea2 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2176,20 +2176,18 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) { tabpage_T *tp; win_T *wp = win_id2wp_tp(argvars, &tp); - win_T *save_curwin; - tabpage_T *save_curtab; // Return an empty string if something fails. rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; if (wp != NULL && tp != NULL) { pos_T curpos = wp->w_cursor; - if (switch_win_noblock(&save_curwin, &save_curtab, wp, tp, true) == - OK) { + switchwin_T switchwin; + if (switch_win_noblock(&switchwin, wp, tp, true) == OK) { check_cursor(); execute_common(argvars, rettv, fptr, 1); } - restore_win_noblock(save_curwin, save_curtab, true); + restore_win_noblock(&switchwin, true); // Update the status line if the cursor moved. if (win_valid(wp) && !equalpos(curpos, wp->w_cursor)) { @@ -4031,8 +4029,6 @@ static void f_gettabinfo(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_gettabvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - win_T *oldcurwin; - tabpage_T *oldtabpage; bool done = false; rettv->v_type = VAR_STRING; @@ -4046,7 +4042,8 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) win_T *const window = tp == curtab || tp->tp_firstwin == NULL ? firstwin : tp->tp_firstwin; - if (switch_win(&oldcurwin, &oldtabpage, window, tp, true) == OK) { + switchwin_T switchwin; + if (switch_win(&switchwin, window, tp, true) == OK) { // look up the variable // Let gettabvar({nr}, "") return the "t:" dictionary. const dictitem_T *const v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 't', @@ -4059,7 +4056,7 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) } // restore previous notion of curwin - restore_win(oldcurwin, oldtabpage, true); + restore_win(&switchwin, true); } if (!done && argvars[2].v_type != VAR_UNKNOWN) { @@ -5881,18 +5878,16 @@ static void f_line(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (argvars[1].v_type != VAR_UNKNOWN) { tabpage_T *tp; - win_T *save_curwin; - tabpage_T *save_curtab; // use window specified in the second argument win_T *wp = win_id2wp_tp(&argvars[1], &tp); if (wp != NULL && tp != NULL) { - if (switch_win_noblock(&save_curwin, &save_curtab, wp, tp, true) - == OK) { + switchwin_T switchwin; + if (switch_win_noblock(&switchwin, wp, tp, true) == OK) { check_cursor(); fp = var2fpos(&argvars[0], true, &fnum); } - restore_win_noblock(save_curwin, save_curtab, true); + restore_win_noblock(&switchwin, true); } } else { // use current window -- cgit From d984a8d130c2063dcd33ae52f98c22fe3567cd18 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 7 Jan 2022 17:27:47 +0000 Subject: vim-patch:8.2.4026: ml_get error with specific win_execute() command Problem: ml_get error with specific win_execute() command. (Sean Dewar) Solution: Check cursor and Visual area are OK. https://github.com/vim/vim/commit/e664a327014f4aa8baf8549a34a4caab2f3116a3 --- src/nvim/eval/funcs.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/eval/funcs.c') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 3cfc00fea2..b16041b832 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2193,6 +2193,13 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (win_valid(wp) && !equalpos(curpos, wp->w_cursor)) { wp->w_redr_status = true; } + + // In case the command moved the cursor or changed the Visual area, + // check it is valid. + check_cursor(); + if (VIsual_active) { + check_pos(curbuf, &VIsual); + } } } -- cgit From 452b46fcf79de52317e2c41adb083d461a93ace5 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 8 Jan 2022 12:27:35 +0000 Subject: fix(api/nvim_win_call): share common win_execute logic We have to be sure that the bugs fixed in the previous patches also apply to nvim_win_call. Checking v8.1.2124 and v8.2.4026 is especially important as these patches were only applied to win_execute, but nvim_win_call is also affected by the same bugs. A lot of win_execute's logic can be shared with nvim_win_call, so factor it out into a common macro to reduce the possibility of this happening again. --- src/nvim/eval/funcs.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'src/nvim/eval/funcs.c') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b16041b832..b1b308a393 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2181,25 +2181,7 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) rettv->vval.v_string = NULL; if (wp != NULL && tp != NULL) { - pos_T curpos = wp->w_cursor; - switchwin_T switchwin; - if (switch_win_noblock(&switchwin, wp, tp, true) == OK) { - check_cursor(); - execute_common(argvars, rettv, fptr, 1); - } - restore_win_noblock(&switchwin, true); - - // Update the status line if the cursor moved. - if (win_valid(wp) && !equalpos(curpos, wp->w_cursor)) { - wp->w_redr_status = true; - } - - // In case the command moved the cursor or changed the Visual area, - // check it is valid. - check_cursor(); - if (VIsual_active) { - check_pos(curbuf, &VIsual); - } + WIN_EXECUTE(wp, tp, execute_common(argvars, rettv, fptr, 1)); } } -- cgit