mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.5043: can open a cmdline window from a substitute expression
Problem: Can open a cmdline window from a substitute expression. Solution: Disallow opening a command line window when text or buffer is locked.
This commit is contained in:
parent
89b25585cc
commit
71223e2db8
@ -2407,12 +2407,7 @@ buflist_getfile(
|
|||||||
if (buf == curbuf)
|
if (buf == curbuf)
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
if (text_locked())
|
if (text_or_buf_locked())
|
||||||
{
|
|
||||||
text_locked_msg();
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
if (curbuf_locked())
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
// altfpos may be changed by getfile(), get it now
|
// altfpos may be changed by getfile(), get it now
|
||||||
|
@ -2739,6 +2739,21 @@ get_text_locked_msg(void)
|
|||||||
return e_not_allowed_to_change_text_or_change_window;
|
return e_not_allowed_to_change_text_or_change_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for text, window or buffer locked.
|
||||||
|
* Give an error message and return TRUE if something is locked.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
text_or_buf_locked(void)
|
||||||
|
{
|
||||||
|
if (text_locked())
|
||||||
|
{
|
||||||
|
text_locked_msg();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return curbuf_locked();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is
|
* Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is
|
||||||
* and give an error message.
|
* and give an error message.
|
||||||
@ -4379,6 +4394,10 @@ open_cmdwin(void)
|
|||||||
int save_KeyTyped;
|
int save_KeyTyped;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Can't do this when text or buffer is locked.
|
||||||
|
if (text_or_buf_locked())
|
||||||
|
return K_IGNORE;
|
||||||
|
|
||||||
// Can't do this recursively. Can't do it when typing a password.
|
// Can't do this recursively. Can't do it when typing a password.
|
||||||
if (cmdwin_type != 0
|
if (cmdwin_type != 0
|
||||||
# if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
# if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
||||||
|
@ -3,9 +3,10 @@ void cmdline_init(void);
|
|||||||
char_u *getcmdline(int firstc, long count, int indent, getline_opt_T do_concat);
|
char_u *getcmdline(int firstc, long count, int indent, getline_opt_T do_concat);
|
||||||
char_u *getcmdline_prompt(int firstc, char_u *prompt, int attr, int xp_context, char_u *xp_arg);
|
char_u *getcmdline_prompt(int firstc, char_u *prompt, int attr, int xp_context, char_u *xp_arg);
|
||||||
int check_opt_wim(void);
|
int check_opt_wim(void);
|
||||||
|
int text_locked(void);
|
||||||
void text_locked_msg(void);
|
void text_locked_msg(void);
|
||||||
char *get_text_locked_msg(void);
|
char *get_text_locked_msg(void);
|
||||||
int text_locked(void);
|
int text_or_buf_locked(void);
|
||||||
int curbuf_locked(void);
|
int curbuf_locked(void);
|
||||||
int allbuf_locked(void);
|
int allbuf_locked(void);
|
||||||
char_u *getexline(int c, void *cookie, int indent, getline_opt_T options);
|
char_u *getexline(int c, void *cookie, int indent, getline_opt_T options);
|
||||||
@ -32,8 +33,8 @@ cmdline_info_T *get_cmdline_info(void);
|
|||||||
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
|
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdline(typval_T *argvars, typval_T *rettv);
|
void f_getcmdline(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdpos(typval_T *argvars, typval_T *rettv);
|
void f_getcmdpos(typval_T *argvars, typval_T *rettv);
|
||||||
void f_setcmdpos(typval_T *argvars, typval_T *rettv);
|
|
||||||
void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
|
void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
|
||||||
|
void f_setcmdpos(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
|
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
|
||||||
int get_cmdline_firstc(void);
|
int get_cmdline_firstc(void);
|
||||||
int get_list_range(char_u **str, int *num1, int *num2);
|
int get_list_range(char_u **str, int *num1, int *num2);
|
||||||
|
@ -1035,6 +1035,31 @@ func Test_sub_undo_change()
|
|||||||
delfunc Repl
|
delfunc Repl
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" This was opening a command line window from the expression
|
||||||
|
func Test_sub_open_cmdline_win()
|
||||||
|
" the error only happens in a very specific setup, run a new Vim instance to
|
||||||
|
" get a clean starting point.
|
||||||
|
let lines =<< trim [SCRIPT]
|
||||||
|
norm o0000000000000000000000000000000000000000000000000000
|
||||||
|
func Replace()
|
||||||
|
norm q/
|
||||||
|
endfunc
|
||||||
|
s/\%')/\=Replace()
|
||||||
|
redir >Xresult
|
||||||
|
messages
|
||||||
|
redir END
|
||||||
|
qall!
|
||||||
|
[SCRIPT]
|
||||||
|
call writefile(lines, 'Xscript')
|
||||||
|
if RunVim([], [], '-u NONE -S Xscript')
|
||||||
|
let messages = readfile('Xresult')
|
||||||
|
call assert_match('E565: Not allowed to change text or change window', messages[3])
|
||||||
|
endif
|
||||||
|
|
||||||
|
call delete('Xscript')
|
||||||
|
call delete('Xresult')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for the 2-letter and 3-letter :substitute commands
|
" Test for the 2-letter and 3-letter :substitute commands
|
||||||
func Test_substitute_short_cmd()
|
func Test_substitute_short_cmd()
|
||||||
new
|
new
|
||||||
|
@ -734,6 +734,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
5043,
|
||||||
/**/
|
/**/
|
||||||
5042,
|
5042,
|
||||||
/**/
|
/**/
|
||||||
|
@ -4585,14 +4585,11 @@ win_goto(win_T *wp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (text_locked())
|
if (text_or_buf_locked())
|
||||||
{
|
{
|
||||||
beep_flush();
|
beep_flush();
|
||||||
text_locked_msg();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (curbuf_locked())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (wp->w_buffer != curbuf)
|
if (wp->w_buffer != curbuf)
|
||||||
reset_VIsual_and_resel();
|
reset_VIsual_and_resel();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user