Added hiding auto-complete after typing one of the offered options (#494).

This commit is contained in:
Paul Kulchenko
2015-06-25 12:12:38 -07:00
parent 5144e92e89
commit e5fa2afe3c
3 changed files with 16 additions and 3 deletions

View File

@@ -599,7 +599,9 @@ function CreateAutoCompList(editor,key,pos)
if token.fpos and pos and token.fpos > pos then break end
if token[1] == 'Id' or token[1] == 'Var' then
local var = token.name
if var ~= key and var:find(key, 1, true) == 1 then
if var:find(key, 1, true) == 1
-- skip the variable formed by what's being typed
and (not token.fpos or not pos or token.fpos < pos-#key) then
-- if it's a global variable, store in the auto-complete list,
-- but if it's local, store separately as it needs to be checked
table.insert(token.context[var] and vars or apilist, var)

View File

@@ -245,8 +245,10 @@ function EditorAutoComplete(editor)
:gsub("^ +",""):gsub(" +$",""):gsub(" +"," "))
end
-- don't show the list if it only suggests what's already typed
if userList and #userList > 0 and not lt:find(userList.."$") then
-- don't show the list if it only suggests what's already typed;
-- don't show if what's typed so far matches one of the options
if userList and #userList > 0 and not lt:find(userList.."$")
and not userList:find("%f[%w_]"..lt..(right or "").."%f[%W]") then
editor:UserListShow(1, userList)
elseif editor:AutoCompActive() then
editor:AutoCompCancel()

View File

@@ -121,6 +121,15 @@ ok(value and value:find("close"), "Auto-complete is shown after comma.")
ok(not (CreateAutoCompList(editor, "pri.") or ""):match('print'),
"Auto-complete doesn't offer 'print' after 'pri.'.")
editor:SetText('')
editor:AddText('local name = "abc"; local namelen = #name')
IndicateAll(editor)
EditorAutoComplete(editor)
local isactive = editor:AutoCompActive()
editor:AutoCompCancel() -- cleanup
ok(not isactive, "Auto-complete is not shown if typed sequence matches one of the options.")
editor:SetText('')
editor:AddText(' -- a = io\na:')
editor:Colourise(0, -1) -- set proper styles