mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
vim-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.
71223e2db8
This commit is contained in:
@@ -1963,11 +1963,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (text_locked()) {
|
||||
text_locked_msg();
|
||||
return FAIL;
|
||||
}
|
||||
if (curbuf_locked()) {
|
||||
if (text_or_buf_locked()) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
@@ -2726,6 +2726,17 @@ char *get_text_locked_msg(void)
|
||||
}
|
||||
}
|
||||
|
||||
/// Check for text, window or buffer locked.
|
||||
/// Give an error message and return true if something is locked.
|
||||
bool text_or_buf_locked(void)
|
||||
{
|
||||
if (text_locked()) {
|
||||
text_locked_msg();
|
||||
return true;
|
||||
}
|
||||
return curbuf_locked();
|
||||
}
|
||||
|
||||
/// Check if "curbuf->b_ro_locked" or "allbuf_lock" is set and
|
||||
/// return true when it is and give an error message.
|
||||
bool curbuf_locked(void)
|
||||
@@ -6600,6 +6611,11 @@ static int open_cmdwin(void)
|
||||
bool save_exmode = exmode_active;
|
||||
int save_cmdmsg_rl = cmdmsg_rl;
|
||||
|
||||
// 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.
|
||||
if (cmdwin_type != 0
|
||||
|| cmdline_star > 0) {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
" Tests for the substitute (:s) command
|
||||
|
||||
source shared.vim
|
||||
|
||||
func Test_multiline_subst()
|
||||
enew!
|
||||
call append(0, ["1 aa",
|
||||
@@ -873,6 +875,31 @@ func Test_sub_undo_change()
|
||||
delfunc Repl
|
||||
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
|
||||
func Test_substitute_short_cmd()
|
||||
new
|
||||
|
@@ -4571,12 +4571,8 @@ void win_goto(win_T *wp)
|
||||
{
|
||||
win_T *owp = curwin;
|
||||
|
||||
if (text_locked()) {
|
||||
if (text_or_buf_locked()) {
|
||||
beep_flush();
|
||||
text_locked_msg();
|
||||
return;
|
||||
}
|
||||
if (curbuf_locked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user