Fix missing items in completion
FIX: This commit fix dbeniamine/todo.txt-vim#7 some the last completion item was not added to the completion list CHG: This commit also provide a small refactor of todo#Complete
This commit is contained in:
@@ -277,7 +277,7 @@ endfunction
|
|||||||
" Completion {{{1
|
" Completion {{{1
|
||||||
|
|
||||||
" Simple keyword completion on all buffers {{{2
|
" Simple keyword completion on all buffers {{{2
|
||||||
function! TodoKeywordComplete(base)
|
function! TodoKeywordComplete(base)
|
||||||
" Search for matches
|
" Search for matches
|
||||||
let res = []
|
let res = []
|
||||||
for bufnr in range(1,bufnr('$'))
|
for bufnr in range(1,bufnr('$'))
|
||||||
@@ -293,6 +293,25 @@ function! TodoKeywordComplete(base)
|
|||||||
endfor
|
endfor
|
||||||
return res
|
return res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Convert an item to the completion format and add it to the completion list
|
||||||
|
fun! TodoAddToCompletionList(list,item,opp)
|
||||||
|
" Create the definitive item
|
||||||
|
let resitem={}
|
||||||
|
let resitem.word=a:item.word
|
||||||
|
let resitem.info=a:opp=='+'?"Projects":"Contexts"
|
||||||
|
let resitem.info.=": ".join(a:item.related, ", ")
|
||||||
|
\."\nBuffers: ".join(a:item.buffers, ", ")
|
||||||
|
call add(a:list,resitem)
|
||||||
|
endfun
|
||||||
|
|
||||||
|
fun! TodoCopyTempItem(item)
|
||||||
|
let ret={}
|
||||||
|
let ret.word=a:item.word
|
||||||
|
let ret.related=[a:item.related]
|
||||||
|
let ret.buffers=[a:item.buffers]
|
||||||
|
return ret
|
||||||
|
endfun
|
||||||
|
|
||||||
" Intelligent completion for projects and Contexts {{{2
|
" Intelligent completion for projects and Contexts {{{2
|
||||||
fun! todo#Complete(findstart, base)
|
fun! todo#Complete(findstart, base)
|
||||||
@@ -327,10 +346,7 @@ fun! todo#Complete(findstart, base)
|
|||||||
call sort(res)
|
call sort(res)
|
||||||
" Here all results are sorted in res, but we need to merge them
|
" Here all results are sorted in res, but we need to merge them
|
||||||
let ret=[]
|
let ret=[]
|
||||||
if res != []
|
if res != []
|
||||||
let curitem={}
|
|
||||||
let curitem.word=res[0].word
|
|
||||||
let curitem.related=[]
|
|
||||||
let curitem=TodoCopyTempItem(res[0])
|
let curitem=TodoCopyTempItem(res[0])
|
||||||
for it in res
|
for it in res
|
||||||
if curitem.word==it.word
|
if curitem.word==it.word
|
||||||
@@ -341,19 +357,14 @@ fun! todo#Complete(findstart, base)
|
|||||||
if index(curitem.buffers,it.buffers) <0
|
if index(curitem.buffers,it.buffers) <0
|
||||||
call add(curitem.buffers,it.buffers)
|
call add(curitem.buffers,it.buffers)
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
" Create the definitive item
|
" Add to list
|
||||||
let resitem={}
|
|
||||||
let resitem.word=curitem.word
|
|
||||||
let resitem.info=opp=='+'?"Projects":"Contexts"
|
|
||||||
let resitem.info.=": ".join(curitem.related, ", ")
|
|
||||||
\."\nBuffers: ".join(curitem.buffers, ", ")
|
|
||||||
call TodoAddToCompletionList(ret,curitem,opp)
|
call TodoAddToCompletionList(ret,curitem,opp)
|
||||||
" Init new item from it
|
" Init new item from it
|
||||||
let curitem.word=it.word
|
|
||||||
let curitem.related=[it.related]
|
|
||||||
let curitem=TodoCopyTempItem(it)
|
let curitem=TodoCopyTempItem(it)
|
||||||
endif
|
endif
|
||||||
|
endfor
|
||||||
|
" Don't forget to add the list item
|
||||||
call TodoAddToCompletionList(ret,curitem,opp)
|
call TodoAddToCompletionList(ret,curitem,opp)
|
||||||
endif
|
endif
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
Reference in New Issue
Block a user