Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20205d4

Browse files
committed
fix(inccommand): never preview if parsing command failed
`errormsg` is not always set when parsing the command failed (e.g. whenthe range contains invalid marks). Check the return value is better.
1 parente420cd6 commit20205d4

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

‎src/nvim/ex_getln.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,17 +2375,18 @@ static void cmdpreview_close_win(void)
23752375
/// 6. Revert all changes made by the preview callback.
23762376
staticvoidcmdpreview_show(CommandLineState*s)
23772377
{
2378+
emsg_off++;// Block errors when parsing the command line, and don't update v:errmsg.
23782379
// Parse the command line and return if it fails.
23792380
exarg_Tea;
23802381
CmdParseInfocmdinfo;
23812382
// Copy the command line so we can modify it.
23822383
char*cmdline=xstrdup((char*)ccline.cmdbuff);
23832384
char*errormsg=NULL;
2384-
2385-
parse_cmdline(cmdline,&ea,&cmdinfo,&errormsg);
2386-
if (errormsg!=NULL) {
2385+
if (!parse_cmdline(cmdline,&ea,&cmdinfo,&errormsg)) {
2386+
emsg_off--;
23872387
gotoend;
23882388
}
2389+
emsg_off--;
23892390

23902391
// Swap invalid command range if needed
23912392
if ((ea.argt&EX_RANGE)&&ea.line1>ea.line2) {
@@ -2409,7 +2410,8 @@ static void cmdpreview_show(CommandLineState *s)
24092410
cmdmod_Tsave_cmdmod=cmdmod;
24102411

24112412
cmdpreview= true;
2412-
emsg_silent++;// Block error reporting as the command may be incomplete
2413+
emsg_silent++;// Block error reporting as the command may be incomplete,
2414+
// but still update v:errmsg
24132415
msg_silent++;// Block messages, namely ones that prompt
24142416
block_autocmds();// Block events
24152417
garray_Tsave_view;

‎test/functional/ui/inccommand_spec.lua‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,32 @@ it(':substitute with inccommand, allows :redraw before first separator is typed
29472947
]])
29482948
end)
29492949

2950+
it(':substitute with inccommand, does nothing if range contains invalid marks',function()
2951+
localscreen=Screen.new(30,6)
2952+
clear()
2953+
command('set undolevels=-1')
2954+
common_setup(screen,'split','test')
2955+
feed([[:'a,'bs]])
2956+
screen:expect([[
2957+
test |
2958+
{15:~ }|
2959+
{15:~ }|
2960+
{15:~ }|
2961+
{15:~ }|
2962+
:'a,'bs^ |
2963+
]])
2964+
feed('/')
2965+
screen:expect([[
2966+
test |
2967+
{15:~ }|
2968+
{15:~ }|
2969+
{15:~ }|
2970+
{15:~ }|
2971+
:'a,'bs/^ |
2972+
]])
2973+
eq('',eval('v:errmsg'))
2974+
end)
2975+
29502976
it(":substitute doesn't crash with inccommand, if undo is empty #12932",function()
29512977
localscreen=Screen.new(10,5)
29522978
clear()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp