simplify term hint text indexing and fix lua prompt hint handler

This commit is contained in:
payonel 2016-05-24 19:04:33 -07:00
parent 9e21c3d4f5
commit c819466b04
2 changed files with 9 additions and 6 deletions

View File

@ -85,7 +85,9 @@ if #args == 0 or options.i then
end
end
local function hint(line, index)
line = (line or ""):sub(1, index - 1)
line = (line or "")
local tail = line:sub(index)
line = line:sub(1, index - 1)
local path = string.match(line, "[a-zA-Z_][a-zA-Z0-9_.]*$")
if not path then return nil end
local suffix = string.match(path, "[^.]+$") or ""
@ -95,7 +97,7 @@ if #args == 0 or options.i then
local r1, r2 = {}, {}
findKeys(t, r1, string.sub(line, 1, #line - #suffix), suffix)
for k in pairs(r1) do
table.insert(r2, k)
table.insert(r2, k .. tail)
end
table.sort(r2)
if #r2 == 1 then
@ -103,10 +105,11 @@ if #args == 0 or options.i then
__index=function(tbl, key)
if key==2 then
local prev=tbl[1]
tbl[1]=nil
local next = hint(prev,#prev+1)
for i,v in ipairs(next) do
tbl[i] = v
if next then
for i,v in ipairs(next) do
tbl[i] = v
end
end
setmetatable(tbl,getmetatable(next))
return tbl[1]

View File

@ -517,7 +517,7 @@ function --[[@delayloaded-start@]] term.internal.tab(input,hints)
c.i=(c.i+change)%math.max(#c,1)
local next=c[c.i+1]
if next then
local tail = unicode.wlen(input.data) - input.index - 1
local tail = unicode.len(input.data) - input.index
input:clear()
input:update(next)
input:move(-tail)