mirror of
https://github.com/neovim/neovim.git
synced 2025-11-25 03:30:37 +00:00
'inccommand': Restore cursor/view if cancelled.
Restore cursor position and window "view", if command is cancelled. This is how 'incsearch' works.
This commit is contained in:
@@ -1599,6 +1599,16 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
&& cmd_is_live(ccline.cmdbuff)) {
|
&& cmd_is_live(ccline.cmdbuff)) {
|
||||||
// process a "live" command ('inccommand')
|
// process a "live" command ('inccommand')
|
||||||
do_cmdline(ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_LIVE);
|
do_cmdline(ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_LIVE);
|
||||||
|
|
||||||
|
// restore the window "view"
|
||||||
|
curwin->w_cursor = s->old_cursor;
|
||||||
|
curwin->w_curswant = s->old_curswant;
|
||||||
|
curwin->w_leftcol = s->old_leftcol;
|
||||||
|
curwin->w_topline = s->old_topline;
|
||||||
|
curwin->w_topfill = s->old_topfill;
|
||||||
|
curwin->w_botline = s->old_botline;
|
||||||
|
update_topline();
|
||||||
|
|
||||||
redrawcmdline();
|
redrawcmdline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
insert("X")
|
insert("X")
|
||||||
feed("IY<esc>")
|
feed("IY<esc>")
|
||||||
feed(":%s/tw/MO/<esc>")
|
feed(":%s/tw/MO/<esc>")
|
||||||
-- using execute("undo") here will result in a "Press ENTER" prompt
|
-- execute("undo") here would cause "Press ENTER".
|
||||||
feed("u")
|
feed("u")
|
||||||
expect(default_text:gsub("Inc", "XInc"))
|
expect(default_text:gsub("Inc", "XInc"))
|
||||||
feed("u")
|
feed("u")
|
||||||
@@ -430,6 +430,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
|
|
||||||
if case == "split" then
|
if case == "split" then
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on |
|
||||||
^MOo lines |
|
^MOo lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
@@ -438,7 +439,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
|
||||||
Already...st change |
|
Already...st change |
|
||||||
]])
|
]])
|
||||||
else
|
else
|
||||||
@@ -482,6 +482,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
|
|
||||||
if case == "split" then
|
if case == "split" then
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on |
|
||||||
two line^s |
|
two line^s |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
@@ -490,7 +491,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
|
||||||
Already...st change |
|
Already...st change |
|
||||||
]])
|
]])
|
||||||
else
|
else
|
||||||
@@ -522,6 +522,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
|
|
||||||
if case == "split" then
|
if case == "split" then
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on |
|
||||||
^MOo lines |
|
^MOo lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
@@ -530,7 +531,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
|
||||||
Already...st change |
|
Already...st change |
|
||||||
]])
|
]])
|
||||||
else
|
else
|
||||||
@@ -564,6 +564,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
feed("u")
|
feed("u")
|
||||||
if case == "split" then
|
if case == "split" then
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on |
|
||||||
^MOo lines |
|
^MOo lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
@@ -572,7 +573,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
|
||||||
Already...st change |
|
Already...st change |
|
||||||
]])
|
]])
|
||||||
else
|
else
|
||||||
@@ -602,7 +602,8 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
|
|
||||||
if case == "split" then
|
if case == "split" then
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^two lines |
|
^LInc substitution on|
|
||||||
|
two lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
@@ -610,7 +611,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
|||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
|
||||||
Already...st change |
|
Already...st change |
|
||||||
]])
|
]])
|
||||||
elseif case == "" then
|
elseif case == "" then
|
||||||
@@ -705,7 +705,7 @@ describe(":substitute, inccommand=split", function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('shows split window with empty replacement', function()
|
it('shows preview with empty replacement', function()
|
||||||
feed(":%s/tw/")
|
feed(":%s/tw/")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
@@ -727,11 +727,11 @@ describe(":substitute, inccommand=split", function()
|
|||||||
|
|
||||||
feed("x")
|
feed("x")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
xo lines |
|
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
xo lines |
|
xo lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
|
{15:~ }|
|
||||||
{11:[No Name] [+] }|
|
{11:[No Name] [+] }|
|
||||||
|2| {12:x}o lines |
|
|2| {12:x}o lines |
|
||||||
|4| {12:x}o lines |
|
|4| {12:x}o lines |
|
||||||
@@ -746,11 +746,11 @@ describe(":substitute, inccommand=split", function()
|
|||||||
|
|
||||||
feed("<bs>")
|
feed("<bs>")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
o lines |
|
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
o lines |
|
o lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
|
{15:~ }|
|
||||||
{11:[No Name] [+] }|
|
{11:[No Name] [+] }|
|
||||||
|2| o lines |
|
|2| o lines |
|
||||||
|4| o lines |
|
|4| o lines |
|
||||||
@@ -768,11 +768,11 @@ describe(":substitute, inccommand=split", function()
|
|||||||
it('shows split window when typing replacement', function()
|
it('shows split window when typing replacement', function()
|
||||||
feed(":%s/tw/XX")
|
feed(":%s/tw/XX")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
XXo lines |
|
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
XXo lines |
|
XXo lines |
|
||||||
|
|
|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
|
{15:~ }|
|
||||||
{11:[No Name] [+] }|
|
{11:[No Name] [+] }|
|
||||||
|2| {12:XX}o lines |
|
|2| {12:XX}o lines |
|
||||||
|4| {12:XX}o lines |
|
|4| {12:XX}o lines |
|
||||||
@@ -831,7 +831,7 @@ describe(":substitute, inccommand=split", function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('highlights the replacement text correctly', function()
|
it('highlights the replacement text', function()
|
||||||
feed('ggO')
|
feed('ggO')
|
||||||
feed('M M M<esc>')
|
feed('M M M<esc>')
|
||||||
feed(':%s/M/123/g')
|
feed(':%s/M/123/g')
|
||||||
@@ -855,9 +855,10 @@ describe(":substitute, inccommand=split", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('actually replaces text', function()
|
it('actually replaces text', function()
|
||||||
feed(":%s/tw/XX/g<enter>")
|
feed(":%s/tw/XX/g<Enter>")
|
||||||
|
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on |
|
||||||
XXo lines |
|
XXo lines |
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
^XXo lines |
|
^XXo lines |
|
||||||
@@ -871,7 +872,6 @@ describe(":substitute, inccommand=split", function()
|
|||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
|
||||||
:%s/tw/XX/g |
|
:%s/tw/XX/g |
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
@@ -884,11 +884,11 @@ describe(":substitute, inccommand=split", function()
|
|||||||
|
|
||||||
feed(":%s/tw/X")
|
feed(":%s/tw/X")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on |
|
||||||
BBo lines |
|
BBo lines |
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
Xo lines |
|
Xo lines |
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
Xo lines |
|
|
||||||
{11:[No Name] [+] }|
|
{11:[No Name] [+] }|
|
||||||
|1001| {12:X}o lines |
|
|1001| {12:X}o lines |
|
||||||
|1003| {12:X}o lines |
|
|1003| {12:X}o lines |
|
||||||
@@ -922,13 +922,13 @@ describe(":substitute, inccommand=split", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with the n flag', function()
|
it('works with the n flag', function()
|
||||||
feed(":%s/tw/Mix/n<enter>")
|
feed(":%s/tw/Mix/n<Enter>")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^two lines |
|
|
||||||
Inc substitution on |
|
Inc substitution on |
|
||||||
two lines |
|
two lines |
|
||||||
|
|
Inc substitution on |
|
||||||
{15:~ }|
|
two lines |
|
||||||
|
^ |
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
{15:~ }|
|
{15:~ }|
|
||||||
@@ -1303,10 +1303,12 @@ describe("'inccommand' split windows", function()
|
|||||||
it('work after more splits', function()
|
it('work after more splits', function()
|
||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
|
feed("gg")
|
||||||
execute("vsplit")
|
execute("vsplit")
|
||||||
execute("split")
|
execute("split")
|
||||||
feed(":%s/tw")
|
feed(":%s/tw")
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
|
Inc substitution on {10:|}Inc substitution on|
|
||||||
two lines {10:|}two lines |
|
two lines {10:|}two lines |
|
||||||
{10:|} |
|
{10:|} |
|
||||||
{15:~ }{10:|}{15:~ }|
|
{15:~ }{10:|}{15:~ }|
|
||||||
@@ -1320,13 +1322,12 @@ describe("'inccommand' split windows", function()
|
|||||||
{15:~ }{10:|}{15:~ }|
|
{15:~ }{10:|}{15:~ }|
|
||||||
{15:~ }{10:|}{15:~ }|
|
{15:~ }{10:|}{15:~ }|
|
||||||
{15:~ }{10:|}{15:~ }|
|
{15:~ }{10:|}{15:~ }|
|
||||||
{15:~ }{10:|}{15:~ }|
|
|
||||||
{11:[No Name] [+] }{10:|}{15:~ }|
|
{11:[No Name] [+] }{10:|}{15:~ }|
|
||||||
|
Inc substitution on {10:|}{15:~ }|
|
||||||
two lines {10:|}{15:~ }|
|
two lines {10:|}{15:~ }|
|
||||||
{10:|}{15:~ }|
|
{10:|}{15:~ }|
|
||||||
{15:~ }{10:|}{15:~ }|
|
{15:~ }{10:|}{15:~ }|
|
||||||
{15:~ }{10:|}{15:~ }|
|
{15:~ }{10:|}{15:~ }|
|
||||||
{15:~ }{10:|}{15:~ }|
|
|
||||||
{10:[No Name] [+] [No Name] [+] }|
|
{10:[No Name] [+] [No Name] [+] }|
|
||||||
|2| two lines |
|
|2| two lines |
|
||||||
|
|
|
|
||||||
|
|||||||
Reference in New Issue
Block a user