mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06: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:
parent
2e1217da46
commit
795f2bb9b9
@ -1599,6 +1599,16 @@ static int command_line_changed(CommandLineState *s)
|
||||
&& cmd_is_live(ccline.cmdbuff)) {
|
||||
// process a "live" command ('inccommand')
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
insert("X")
|
||||
feed("IY<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")
|
||||
expect(default_text:gsub("Inc", "XInc"))
|
||||
feed("u")
|
||||
@ -430,6 +430,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
|
||||
if case == "split" then
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
^MOo lines |
|
||||
|
|
||||
{15:~ }|
|
||||
@ -438,7 +439,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
]])
|
||||
else
|
||||
@ -482,6 +482,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
|
||||
if case == "split" then
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
two line^s |
|
||||
|
|
||||
{15:~ }|
|
||||
@ -490,7 +491,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
]])
|
||||
else
|
||||
@ -522,6 +522,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
|
||||
if case == "split" then
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
^MOo lines |
|
||||
|
|
||||
{15:~ }|
|
||||
@ -530,7 +531,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
]])
|
||||
else
|
||||
@ -564,6 +564,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
feed("u")
|
||||
if case == "split" then
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
^MOo lines |
|
||||
|
|
||||
{15:~ }|
|
||||
@ -572,7 +573,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
]])
|
||||
else
|
||||
@ -602,7 +602,8 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
|
||||
if case == "split" then
|
||||
screen:expect([[
|
||||
^two lines |
|
||||
^LInc substitution on|
|
||||
two lines |
|
||||
|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
@ -610,7 +611,6 @@ describe(":substitute, 'inccommand' preserves undo", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
Already...st change |
|
||||
]])
|
||||
elseif case == "" then
|
||||
@ -705,7 +705,7 @@ describe(":substitute, inccommand=split", function()
|
||||
]])
|
||||
end)
|
||||
|
||||
it('shows split window with empty replacement', function()
|
||||
it('shows preview with empty replacement', function()
|
||||
feed(":%s/tw/")
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
@ -727,11 +727,11 @@ describe(":substitute, inccommand=split", function()
|
||||
|
||||
feed("x")
|
||||
screen:expect([[
|
||||
xo lines |
|
||||
Inc substitution on |
|
||||
xo lines |
|
||||
|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{11:[No Name] [+] }|
|
||||
|2| {12:x}o lines |
|
||||
|4| {12:x}o lines |
|
||||
@ -746,11 +746,11 @@ describe(":substitute, inccommand=split", function()
|
||||
|
||||
feed("<bs>")
|
||||
screen:expect([[
|
||||
o lines |
|
||||
Inc substitution on |
|
||||
o lines |
|
||||
|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{11:[No Name] [+] }|
|
||||
|2| o lines |
|
||||
|4| o lines |
|
||||
@ -768,11 +768,11 @@ describe(":substitute, inccommand=split", function()
|
||||
it('shows split window when typing replacement', function()
|
||||
feed(":%s/tw/XX")
|
||||
screen:expect([[
|
||||
XXo lines |
|
||||
Inc substitution on |
|
||||
XXo lines |
|
||||
|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{11:[No Name] [+] }|
|
||||
|2| {12:XX}o lines |
|
||||
|4| {12:XX}o lines |
|
||||
@ -831,7 +831,7 @@ describe(":substitute, inccommand=split", function()
|
||||
]])
|
||||
end)
|
||||
|
||||
it('highlights the replacement text correctly', function()
|
||||
it('highlights the replacement text', function()
|
||||
feed('ggO')
|
||||
feed('M M M<esc>')
|
||||
feed(':%s/M/123/g')
|
||||
@ -855,9 +855,10 @@ describe(":substitute, inccommand=split", function()
|
||||
end)
|
||||
|
||||
it('actually replaces text', function()
|
||||
feed(":%s/tw/XX/g<enter>")
|
||||
feed(":%s/tw/XX/g<Enter>")
|
||||
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
XXo lines |
|
||||
Inc substitution on |
|
||||
^XXo lines |
|
||||
@ -871,7 +872,6 @@ describe(":substitute, inccommand=split", function()
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
:%s/tw/XX/g |
|
||||
]])
|
||||
end)
|
||||
@ -884,11 +884,11 @@ describe(":substitute, inccommand=split", function()
|
||||
|
||||
feed(":%s/tw/X")
|
||||
screen:expect([[
|
||||
Inc substitution on |
|
||||
BBo lines |
|
||||
Inc substitution on |
|
||||
Xo lines |
|
||||
Inc substitution on |
|
||||
Xo lines |
|
||||
{11:[No Name] [+] }|
|
||||
|1001| {12:X}o lines |
|
||||
|1003| {12:X}o lines |
|
||||
@ -922,13 +922,13 @@ describe(":substitute, inccommand=split", function()
|
||||
end)
|
||||
|
||||
it('works with the n flag', function()
|
||||
feed(":%s/tw/Mix/n<enter>")
|
||||
feed(":%s/tw/Mix/n<Enter>")
|
||||
screen:expect([[
|
||||
^two lines |
|
||||
Inc substitution on |
|
||||
two lines |
|
||||
|
|
||||
{15:~ }|
|
||||
Inc substitution on |
|
||||
two lines |
|
||||
^ |
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
{15:~ }|
|
||||
@ -1303,10 +1303,12 @@ describe("'inccommand' split windows", function()
|
||||
it('work after more splits', function()
|
||||
refresh()
|
||||
|
||||
feed("gg")
|
||||
execute("vsplit")
|
||||
execute("split")
|
||||
feed(":%s/tw")
|
||||
screen:expect([[
|
||||
Inc substitution on {10:|}Inc substitution on|
|
||||
two lines {10:|}two lines |
|
||||
{10:|} |
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
@ -1320,13 +1322,12 @@ describe("'inccommand' split windows", function()
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{11:[No Name] [+] }{10:|}{15:~ }|
|
||||
Inc substitution on {10:|}{15:~ }|
|
||||
two lines {10:|}{15:~ }|
|
||||
{10:|}{15:~ }|
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{15:~ }{10:|}{15:~ }|
|
||||
{10:[No Name] [+] [No Name] [+] }|
|
||||
|2| two lines |
|
||||
|
|
||||
|
Loading…
Reference in New Issue
Block a user