Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves menu selection mechanics (regular vim) #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions autoload/internal_buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ let s:InternalBuffer.MethodsList = [
\'ClearBuffer',
\'BufferLnum',
\'RestorePopupCursor',
\'SetCursorToNextLink',
\'SetCursorToPreviousLink',
\'GetCurLine',
\]

" Produce new Render Buffer
Expand Down Expand Up @@ -182,17 +185,52 @@ fu! s:InternalBuffer.CreateItem(type, text, hl_group, ...) dict abort
return item
endfu


fu! s:InternalBuffer.GetItemByPos() dict abort
fu! s:InternalBuffer.GetCurLine() dict abort
if s:nvim
let idx = getbufinfo(self.vim_bufnr)[0]['lnum']
return getbufinfo(self.vim_bufnr)[0]['lnum']
else
" vim popup buffer doesn't have current line info inside getbufinfo()
" so extract line nr from win
let l:popup_pos = 0
call win_execute(self.popup_winid, 'let l:popup_pos = getcurpos()')
let idx = l:popup_pos[1]
return l:popup_pos[1]
end
endfu

fu! s:InternalBuffer.SetCursorToNextLink() dict abort
let idx = self.GetCurLine()

while idx < len(self.items)
let line = self.items[idx]
for item in line
if item.type == 'link' || item.type == 'button'
let cmd = printf("call setpos('.', [%d, %d, 1, 0])", self.vim_bufnr, idx + 1)
call win_execute(self.popup_winid, cmd)
return
endif
endfor
let idx += 1
endwhile
endfu

fu! s:InternalBuffer.SetCursorToPreviousLink() dict abort
let idx = self.GetCurLine() - 2

while idx >= 0
let line = self.items[idx]
for item in line
if item.type == 'link' || item.type == 'button'
let cmd = printf("call setpos('.', [%d, %d, 1, 0])", self.vim_bufnr, idx + 1)
call win_execute(self.popup_winid, cmd)
return
endif
endfor
let idx -= 1
endwhile
endfu

fu! s:InternalBuffer.GetItemByPos() dict abort
let idx = self.GetCurLine()

if idx > len(self.items)
return 0
Expand Down Expand Up @@ -352,7 +390,12 @@ fu! s:InternalBuffer.JumpToFirstOfType(type, ...) dict abort

if type(item) == v:t_dict
let ln = self.GetItemLineNumber(item)
call cursor(ln, 2)
if s:nvim
call cursor(ln, 2)
else
let cmd = printf('call cursor(%d, 2)', ln)
call win_execute(self.popup_winid, cmd)
endif
endif
endfu

Expand Down
5 changes: 3 additions & 2 deletions plugin/any-jump.vim
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,19 @@ fu! s:CreateVimUi(internal_buffer) abort
let a:internal_buffer.vim_bufnr = winbufnr(popup_winid)

call a:internal_buffer.RenderUi()
call a:internal_buffer.JumpToFirstOfType('link', 'definitions')
endfu

fu! s:VimPopupFilter(popup_winid, key) abort
let bufnr = winbufnr(a:popup_winid)
let ib = s:GetCurrentInternalBuffer()

if a:key ==# "j"
call popup_filter_menu(a:popup_winid, a:key)
call ib.SetCursorToNextLink()
return 1

elseif a:key ==# "k"
call popup_filter_menu(a:popup_winid, a:key)
call ib.SetCursorToPreviousLink()
return 1

elseif a:key ==# "p" || a:key ==# "\<TAB>"
Expand Down