mirror of
https://github.com/neovim/neovim.git
synced 2025-11-05 10:14:26 +00:00
Merge pull request #19261 from zeertzjq/vim-8.2.5023
vim-patch:8.2.{5023,5043,5044}: substitute textlock fixes
This commit is contained in:
@@ -1963,11 +1963,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text_locked()) {
|
if (text_or_buf_locked()) {
|
||||||
text_locked_msg();
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
if (curbuf_locked()) {
|
|
||||||
return FAIL;
|
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
|
/// Check if "curbuf->b_ro_locked" or "allbuf_lock" is set and
|
||||||
/// return true when it is and give an error message.
|
/// return true when it is and give an error message.
|
||||||
bool curbuf_locked(void)
|
bool curbuf_locked(void)
|
||||||
@@ -6600,9 +6611,9 @@ static int open_cmdwin(void)
|
|||||||
bool save_exmode = exmode_active;
|
bool save_exmode = exmode_active;
|
||||||
int save_cmdmsg_rl = cmdmsg_rl;
|
int save_cmdmsg_rl = cmdmsg_rl;
|
||||||
|
|
||||||
|
// Can't do this when text or buffer is locked.
|
||||||
// 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 (text_or_buf_locked() || cmdwin_type != 0 || cmdline_star > 0) {
|
||||||
|| cmdline_star > 0) {
|
|
||||||
beep_flush();
|
beep_flush();
|
||||||
return K_IGNORE;
|
return K_IGNORE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -432,6 +432,18 @@ static int find_command(int cmdchar)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If currently editing a cmdline or text is locked: beep and give an error
|
||||||
|
/// message, return true.
|
||||||
|
static bool check_text_locked(oparg_T *oap)
|
||||||
|
{
|
||||||
|
if (text_locked()) {
|
||||||
|
clearopbeep(oap);
|
||||||
|
text_locked_msg();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Normal state entry point. This is called on:
|
/// Normal state entry point. This is called on:
|
||||||
///
|
///
|
||||||
/// - Startup, In this case the function never returns.
|
/// - Startup, In this case the function never returns.
|
||||||
@@ -1079,15 +1091,9 @@ static int normal_execute(VimState *state, int key)
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text_locked() && (nv_cmds[s->idx].cmd_flags & NV_NCW)) {
|
if ((nv_cmds[s->idx].cmd_flags & NV_NCW)
|
||||||
// This command is not allowed while editing a cmdline: beep.
|
&& (check_text_locked(&s->oa) || curbuf_locked())) {
|
||||||
clearopbeep(&s->oa);
|
// this command is not allowed now
|
||||||
text_locked_msg();
|
|
||||||
s->command_finished = true;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((nv_cmds[s->idx].cmd_flags & NV_NCW) && curbuf_locked()) {
|
|
||||||
s->command_finished = true;
|
s->command_finished = true;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
@@ -4704,9 +4710,7 @@ static void nv_gotofile(cmdarg_T *cap)
|
|||||||
char_u *ptr;
|
char_u *ptr;
|
||||||
linenr_T lnum = -1;
|
linenr_T lnum = -1;
|
||||||
|
|
||||||
if (text_locked()) {
|
if (check_text_locked(cap->oap)) {
|
||||||
clearopbeep(cap->oap);
|
|
||||||
text_locked_msg();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (curbuf_locked()) {
|
if (curbuf_locked()) {
|
||||||
@@ -6433,13 +6437,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
|
|
||||||
// "gQ": improved Ex mode
|
// "gQ": improved Ex mode
|
||||||
case 'Q':
|
case 'Q':
|
||||||
if (text_locked()) {
|
if (!check_text_locked(cap->oap) && !checkclearopq(oap)) {
|
||||||
clearopbeep(cap->oap);
|
|
||||||
text_locked_msg();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!checkclearopq(oap)) {
|
|
||||||
do_exmode();
|
do_exmode();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
" Tests for the substitute (:s) command
|
" Tests for the substitute (:s) command
|
||||||
|
|
||||||
|
source shared.vim
|
||||||
|
|
||||||
func Test_multiline_subst()
|
func Test_multiline_subst()
|
||||||
enew!
|
enew!
|
||||||
call append(0, ["1 aa",
|
call append(0, ["1 aa",
|
||||||
@@ -851,6 +853,54 @@ func Test_sub_change_window()
|
|||||||
delfunc Repl
|
delfunc Repl
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" This was undoign a change in between computing the length and using it.
|
||||||
|
func Do_Test_sub_undo_change()
|
||||||
|
new
|
||||||
|
norm o0000000000000000000000000000000000000000000000000000
|
||||||
|
silent! s/\%')/\=Repl()
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_sub_undo_change()
|
||||||
|
func Repl()
|
||||||
|
silent! norm g-
|
||||||
|
endfunc
|
||||||
|
call Do_Test_sub_undo_change()
|
||||||
|
|
||||||
|
func! Repl()
|
||||||
|
silent earlier
|
||||||
|
endfunc
|
||||||
|
call Do_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]
|
||||||
|
set vb t_vb=
|
||||||
|
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')
|
||||||
|
call assert_match('E565: Not allowed to change text or change window',
|
||||||
|
\ readfile('Xresult')->join('XX'))
|
||||||
|
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
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
#include "nvim/change.h"
|
#include "nvim/change.h"
|
||||||
#include "nvim/cursor.h"
|
#include "nvim/cursor.h"
|
||||||
#include "nvim/edit.h"
|
#include "nvim/edit.h"
|
||||||
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/extmark.h"
|
#include "nvim/extmark.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
@@ -1954,6 +1955,11 @@ void undo_time(long step, bool sec, bool file, bool absolute)
|
|||||||
bool above = false;
|
bool above = false;
|
||||||
bool did_undo = true;
|
bool did_undo = true;
|
||||||
|
|
||||||
|
if (text_locked()) {
|
||||||
|
text_locked_msg();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// First make sure the current undoable change is synced.
|
// First make sure the current undoable change is synced.
|
||||||
if (curbuf->b_u_synced == false) {
|
if (curbuf->b_u_synced == false) {
|
||||||
u_sync(true);
|
u_sync(true);
|
||||||
|
|||||||
@@ -4571,12 +4571,8 @@ void win_goto(win_T *wp)
|
|||||||
{
|
{
|
||||||
win_T *owp = curwin;
|
win_T *owp = curwin;
|
||||||
|
|
||||||
if (text_locked()) {
|
if (text_or_buf_locked()) {
|
||||||
beep_flush();
|
beep_flush();
|
||||||
text_locked_msg();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (curbuf_locked()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user