Merge pull request #7692 from bfredl/wildcmd

ui: fix glitch with both ext_cmdline and cmd_wildmenu
This commit is contained in:
Björn Linse 2017-12-06 19:19:05 +01:00 committed by GitHub
commit 873af01245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 251 additions and 122 deletions

View File

@ -3455,8 +3455,10 @@ nextwild (
return FAIL; return FAIL;
} }
MSG_PUTS("..."); /* show that we are busy */ if (!ui_is_external(kUIWildmenu)) {
ui_flush(); MSG_PUTS("..."); // show that we are busy
ui_flush();
}
i = (int)(xp->xp_pattern - ccline.cmdbuff); i = (int)(xp->xp_pattern - ccline.cmdbuff);
xp->xp_pattern_len = ccline.cmdpos - i; xp->xp_pattern_len = ccline.cmdpos - i;

View File

@ -10,12 +10,19 @@ describe('external cmdline', function()
local last_level = 0 local last_level = 0
local cmdline = {} local cmdline = {}
local block = nil local block = nil
local wild_items = nil
local wild_selected = nil
before_each(function() before_each(function()
clear() clear()
cmdline, block = {}, nil cmdline, block = {}, nil
screen = Screen.new(25, 5) screen = Screen.new(25, 5)
screen:attach({rgb=true, ext_cmdline=true}) screen:attach({rgb=true, ext_cmdline=true})
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1},
[2] = {reverse = true},
[3] = {bold = true, reverse = true},
})
screen:set_on_event_handler(function(name, data) screen:set_on_event_handler(function(name, data)
if name == "cmdline_show" then if name == "cmdline_show" then
local content, pos, firstc, prompt, indent, level = unpack(data) local content, pos, firstc, prompt, indent, level = unpack(data)
@ -38,6 +45,12 @@ describe('external cmdline', function()
block[#block+1] = data[1] block[#block+1] = data[1]
elseif name == "cmdline_block_hide" then elseif name == "cmdline_block_hide" then
block = nil block = nil
elseif name == "wildmenu_show" then
wild_items = data[1]
elseif name == "wildmenu_select" then
wild_selected = data[1]
elseif name == "wildmenu_hide" then
wild_items, wild_selected = nil, nil
end end
end) end)
end) end)
@ -66,9 +79,9 @@ describe('external cmdline', function()
feed(':') feed(':')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq(1, last_level) eq(1, last_level)
@ -84,9 +97,9 @@ describe('external cmdline', function()
feed('sign') feed('sign')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -101,9 +114,9 @@ describe('external cmdline', function()
feed('<Left>') feed('<Left>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -118,9 +131,9 @@ describe('external cmdline', function()
feed('<bs>') feed('<bs>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -135,9 +148,9 @@ describe('external cmdline', function()
feed('<Esc>') feed('<Esc>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({}, cmdline) eq({}, cmdline)
@ -148,9 +161,9 @@ describe('external cmdline', function()
feed(':call input("input", "default")<cr>') feed(':call input("input", "default")<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -164,9 +177,9 @@ describe('external cmdline', function()
feed('<cr>') feed('<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({}, cmdline) eq({}, cmdline)
@ -178,9 +191,9 @@ describe('external cmdline', function()
feed(':xx<c-r>') feed(':xx<c-r>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -196,9 +209,9 @@ describe('external cmdline', function()
feed('=') feed('=')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -234,9 +247,9 @@ describe('external cmdline', function()
}} }}
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq(expectation, cmdline) eq(expectation, cmdline)
@ -249,9 +262,9 @@ describe('external cmdline', function()
-- focus is at external cmdline anyway. -- focus is at external cmdline anyway.
screen:expect([[ screen:expect([[
| |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
^ | ^ |
]], nil, nil, function() ]], nil, nil, function()
eq(expectation, cmdline) eq(expectation, cmdline)
@ -261,9 +274,9 @@ describe('external cmdline', function()
feed('<cr>') feed('<cr>')
screen:expect([[ screen:expect([[
| |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
^ | ^ |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -278,9 +291,9 @@ describe('external cmdline', function()
feed('<esc>') feed('<esc>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({}, cmdline) eq({}, cmdline)
@ -291,9 +304,9 @@ describe('external cmdline', function()
feed(':function Foo()<cr>') feed(':function Foo()<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -309,9 +322,9 @@ describe('external cmdline', function()
feed('line1<cr>') feed('line1<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{{{}, 'function Foo()'}}, eq({{{{}, 'function Foo()'}},
@ -322,9 +335,9 @@ describe('external cmdline', function()
command("redraw!") command("redraw!")
screen:expect([[ screen:expect([[
| |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
^ | ^ |
]], nil, nil, function() ]], nil, nil, function()
eq({{{{}, 'function Foo()'}}, eq({{{{}, 'function Foo()'}},
@ -335,9 +348,9 @@ describe('external cmdline', function()
feed('endfunction<cr>') feed('endfunction<cr>')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq(nil, block) eq(nil, block)
@ -348,9 +361,9 @@ describe('external cmdline', function()
feed(':make') feed(':make')
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -365,9 +378,9 @@ describe('external cmdline', function()
feed('<c-f>') feed('<c-f>')
screen:expect([[ screen:expect([[
| |
[No Name] | {2:[No Name] }|
:make^ | {1::}make^ |
[Command Line] | {3:[Command Line] }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({}, cmdline) eq({}, cmdline)
@ -377,9 +390,9 @@ describe('external cmdline', function()
feed(':yank') feed(':yank')
screen:expect([[ screen:expect([[
| |
[No Name] | {2:[No Name] }|
:make^ | {1::}make^ |
[Command Line] | {3:[Command Line] }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({nil, { eq({nil, {
@ -395,9 +408,9 @@ describe('external cmdline', function()
command("redraw!") command("redraw!")
screen:expect([[ screen:expect([[
| |
[No Name] | {2:[No Name] }|
:make | {1::}make |
[Command Line] | {3:[Command Line] }|
^ | ^ |
]], nil, nil, function() ]], nil, nil, function()
eq({nil, { eq({nil, {
@ -412,9 +425,9 @@ describe('external cmdline', function()
feed("<c-c>") feed("<c-c>")
screen:expect([[ screen:expect([[
| |
[No Name] | {2:[No Name] }|
:make^ | {1::}make^ |
[Command Line] | {3:[Command Line] }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({}, cmdline) eq({}, cmdline)
@ -423,9 +436,9 @@ describe('external cmdline', function()
feed("<c-c>") feed("<c-c>")
screen:expect([[ screen:expect([[
| |
[No Name] | {2:[No Name] }|
:make^ | {1::}make^ |
[Command Line] | {3:[Command Line] }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -441,9 +454,9 @@ describe('external cmdline', function()
command("redraw!") command("redraw!")
screen:expect([[ screen:expect([[
| |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
^ | ^ |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -460,9 +473,9 @@ describe('external cmdline', function()
feed(":call inputsecret('secret:')<cr>abc123") feed(":call inputsecret('secret:')<cr>abc123")
screen:expect([[ screen:expect([[
^ | ^ |
~ | {1:~ }|
~ | {1:~ }|
~ | {1:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
eq({{ eq({{
@ -476,50 +489,160 @@ describe('external cmdline', function()
end) end)
it('works with highlighted cmdline', function() it('works with highlighted cmdline', function()
source([[ source([[
highlight RBP1 guibg=Red highlight RBP1 guibg=Red
highlight RBP2 guibg=Yellow highlight RBP2 guibg=Yellow
highlight RBP3 guibg=Green highlight RBP3 guibg=Green
highlight RBP4 guibg=Blue highlight RBP4 guibg=Blue
let g:NUM_LVLS = 4 let g:NUM_LVLS = 4
function RainBowParens(cmdline) function RainBowParens(cmdline)
let ret = [] let ret = []
let i = 0 let i = 0
let lvl = 0 let lvl = 0
while i < len(a:cmdline) while i < len(a:cmdline)
if a:cmdline[i] is# '(' if a:cmdline[i] is# '('
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
let lvl += 1 let lvl += 1
elseif a:cmdline[i] is# ')' elseif a:cmdline[i] is# ')'
let lvl -= 1 let lvl -= 1
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)]) call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
endif endif
let i += 1 let i += 1
endwhile endwhile
return ret return ret
endfunction endfunction
map <f5> :let x = input({'prompt':'>','highlight':'RainBowParens'})<cr> map <f5> :let x = input({'prompt':'>','highlight':'RainBowParens'})<cr>
"map <f5> :let x = input({'prompt':'>'})<cr> "map <f5> :let x = input({'prompt':'>'})<cr>
]]) ]])
screen:set_default_attr_ids({ screen:set_default_attr_ids({
RBP1={background = Screen.colors.Red}, RBP1={background = Screen.colors.Red},
RBP2={background = Screen.colors.Yellow}, RBP2={background = Screen.colors.Yellow},
RBP3={background = Screen.colors.Green}, RBP3={background = Screen.colors.Green},
RBP4={background = Screen.colors.Blue}, RBP4={background = Screen.colors.Blue},
EOB={bold = true, foreground = Screen.colors.Blue1}, EOB={bold = true, foreground = Screen.colors.Blue1},
ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red}, ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red},
SK={foreground = Screen.colors.Blue}, SK={foreground = Screen.colors.Blue},
PE={bold = true, foreground = Screen.colors.SeaGreen4} PE={bold = true, foreground = Screen.colors.SeaGreen4}
}) })
feed('<f5>(a(b)a)') feed('<f5>(a(b)a)')
screen:expect([[ screen:expect([[
^ | ^ |
{EOB:~ }| {EOB:~ }|
{EOB:~ }| {EOB:~ }|
{EOB:~ }| {EOB:~ }|
| |
]], nil, nil, function() ]], nil, nil, function()
expect_cmdline(1, '{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}') expect_cmdline(1, '{RBP1:(}a{RBP2:(}b{RBP2:)}a{RBP1:)}')
end) end)
end)
it('works together with ext_wildmenu', function()
local expected = {
'define',
'jump',
'list',
'place',
'undefine',
'unplace',
}
command('set wildmode=full')
command('set wildmenu')
screen:set_option('ext_wildmenu', true)
feed(':sign <tab>')
screen:expect([[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
|
]], nil, nil, function()
eq({{
content = { { {}, "sign define"} },
firstc = ":",
indent = 0,
pos = 11,
prompt = ""
}}, cmdline)
eq(expected, wild_items)
eq(0, wild_selected)
end)
feed('<tab>')
screen:expect([[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
|
]], nil, nil, function()
eq({{
content = { { {}, "sign jump"} },
firstc = ":",
indent = 0,
pos = 9,
prompt = ""
}}, cmdline)
eq(expected, wild_items)
eq(1, wild_selected)
end)
feed('<left><left>')
screen:expect([[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
|
]], nil, nil, function()
eq({{
content = { { {}, "sign "} },
firstc = ":",
indent = 0,
pos = 5,
prompt = ""
}}, cmdline)
eq(expected, wild_items)
eq(-1, wild_selected)
end)
feed('<right>')
screen:expect([[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
|
]], nil, nil, function()
eq({{
content = { { {}, "sign define"} },
firstc = ":",
indent = 0,
pos = 11,
prompt = ""
}}, cmdline)
eq(expected, wild_items)
eq(0, wild_selected)
end)
feed('a')
screen:expect([[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
|
]], nil, nil, function()
eq({{
content = { { {}, "sign definea"} },
firstc = ":",
indent = 0,
pos = 12,
prompt = ""
}}, cmdline)
eq(nil, wild_items)
eq(nil, wild_selected)
end)
end) end)
end) end)

View File

@ -176,6 +176,10 @@ function Screen:try_resize(columns, rows)
self:sleep(0.1) self:sleep(0.1)
end end
function Screen:set_option(option, value)
uimeths.set_option(option, value)
end
-- Asserts that `expected` eventually matches the screen state. -- Asserts that `expected` eventually matches the screen state.
-- --
-- expected: Expected screen state (string). Each line represents a screen -- expected: Expected screen state (string). Each line represents a screen