From e5fa2afe3cecf21eebb78eaebc4137856efcfa81 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Thu, 25 Jun 2015 12:12:38 -0700 Subject: [PATCH] Added hiding auto-complete after typing one of the offered options (#494). --- src/editor/autocomplete.lua | 4 +++- src/editor/editor.lua | 6 ++++-- t/2-autocomplete.lua | 9 +++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/editor/autocomplete.lua b/src/editor/autocomplete.lua index 9355d413aa..f50cdde92d 100644 --- a/src/editor/autocomplete.lua +++ b/src/editor/autocomplete.lua @@ -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) diff --git a/src/editor/editor.lua b/src/editor/editor.lua index 31c2b7e827..e96f30a613 100644 --- a/src/editor/editor.lua +++ b/src/editor/editor.lua @@ -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() diff --git a/t/2-autocomplete.lua b/t/2-autocomplete.lua index ed41e3a3af..b667f64b0e 100644 --- a/t/2-autocomplete.lua +++ b/t/2-autocomplete.lua @@ -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