vim-patch:8.2.2732: prompt for s///c in Ex mode can be wrong

Problem:    Prompt for s///c in Ex mode can be wrong.
Solution:   Position the cursor before showing the prompt. (closes vim/vim#8073)
e5b0b98a90
This commit is contained in:
zeertzjq
2022-07-12 12:37:23 +08:00
parent d079995fb8
commit 1abdb3224b
3 changed files with 40 additions and 22 deletions

View File

@@ -3874,6 +3874,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
curwin->w_cursor.col = 0; curwin->w_cursor.col = 0;
} }
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec); getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec);
curwin->w_cursor.col = regmatch.startpos[0].col;
if (subflags.do_number || curwin->w_p_nu) { if (subflags.do_number || curwin->w_p_nu) {
int numw = number_width(curwin) + 1; int numw = number_width(curwin) + 1;
sc += numw; sc += numw;

View File

@@ -78,6 +78,9 @@ func Test_Ex_substitute()
call WaitForAssert({-> assert_match(' 1 foo foo', term_getline(buf, 5))}, call WaitForAssert({-> assert_match(' 1 foo foo', term_getline(buf, 5))},
\ 1000) \ 1000)
call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, 1000) call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, 1000)
call term_sendkeys(buf, "N\<CR>")
call term_wait(buf)
call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, 1000)
call term_sendkeys(buf, "n\<CR>") call term_sendkeys(buf, "n\<CR>")
call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))},
\ 1000) \ 1000)

View File

@@ -44,67 +44,81 @@ describe('Ex mode', function()
it('substitute confirmation prompt', function() it('substitute confirmation prompt', function()
command('set noincsearch nohlsearch inccommand=') command('set noincsearch nohlsearch inccommand=')
local screen = Screen.new(60, 6) local screen = Screen.new(60, 6)
screen:set_default_attr_ids({
[0] = {bold = true, reverse = true}, -- MsgSeparator
[1] = {foreground = Screen.colors.Brown}, -- LineNr
[2] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
})
screen:attach() screen:attach()
command([[call setline(1, ['foo foo', 'foo foo', 'foo foo'])]]) command([[call setline(1, ['foo foo', 'foo foo', 'foo foo'])]])
command([[set number]]) command([[set number]])
feed('gQ') feed('gQ')
screen:expect([[ screen:expect([[
1 foo foo | {1: 1 }foo foo |
2 foo foo | {1: 2 }foo foo |
3 foo foo | {1: 3 }foo foo |
| {0: }|
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:^ | :^ |
]]) ]])
feed('%s/foo/bar/gc<CR>') feed('%s/foo/bar/gc<CR>')
screen:expect([[ screen:expect([[
1 foo foo | {1: 1 }foo foo |
| {0: }|
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:%s/foo/bar/gc | :%s/foo/bar/gc |
1 foo foo | {1: 1 }foo foo |
^^^^ |
]])
feed('N<CR>')
screen:expect([[
Entering Ex mode. Type "visual" to go to Normal mode. |
:%s/foo/bar/gc |
{1: 1 }foo foo |
^^^N |
{1: 1 }foo foo |
^^^^ | ^^^^ |
]]) ]])
feed('n<CR>') feed('n<CR>')
screen:expect([[ screen:expect([[
Entering Ex mode. Type "visual" to go to Normal mode. | {1: 1 }foo foo |
:%s/foo/bar/gc | ^^^N |
1 foo foo | {1: 1 }foo foo |
^^^n | ^^^n |
1 foo foo | {1: 1 }foo foo |
^^^^ | ^^^^ |
]]) ]])
feed('y<CR>') feed('y<CR>')
feed('q<CR>') feed('q<CR>')
screen:expect([[ screen:expect([[
1 foo foo | {1: 1 }foo foo |
^^^y | ^^^y |
2 foo foo | {1: 2 }foo foo |
^^^q | ^^^q |
2 foo foo | {1: 2 }foo foo |
:^ | :^ |
]]) ]])
-- Pressing enter in ex mode should print the current line -- Pressing enter in ex mode should print the current line
feed('<CR>') feed('<CR>')
screen:expect([[ screen:expect([[
1 foo foo | {1: 1 }foo foo |
^^^y | ^^^y |
2 foo foo | {1: 2 }foo foo |
^^^q | ^^^q |
3 foo foo | {1: 3 }foo foo |
:^ | :^ |
]]) ]])
feed(':vi<CR>') feed(':vi<CR>')
screen:expect([[ screen:expect([[
1 foo bar | {1: 1 }foo bar |
2 foo foo | {1: 2 }foo foo |
3 ^foo foo | {1: 3 }^foo foo |
~ | {2:~ }|
~ | {2:~ }|
| |
]]) ]])
end) end)