Skip to content

Commit

Permalink
When repeating selections, jump to the last selected item
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Jun 29, 2021
1 parent a4ba421 commit 7862633
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions autoload/ale/preview.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Preview windows for showing whatever information in.

if !has_key(s:, 'last__list')
if !has_key(s:, 'last_list')
let s:last_list = []
endif

Expand Down Expand Up @@ -89,6 +89,13 @@ function! ale#preview#ShowSelection(item_list, ...) abort
let b:ale_preview_item_list = a:item_list
let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer')

" Jump to an index for a previous selection, if set.
if has_key(l:options, 'jump_to_index')
let l:pos = getpos('.')
let l:pos[1] = l:options.jump_to_index + 1
call setpos('.', l:pos)
endif

" Remember preview state, so we can repeat it later.
call ale#preview#SetLastSelection(a:item_list, l:options)
endfunction
Expand All @@ -101,12 +108,16 @@ endfunction

function! s:Open(open_in) abort
let l:item_list = get(b:, 'ale_preview_item_list', [])
let l:item = get(l:item_list, getpos('.')[1] - 1, {})
let l:index = getpos('.')[1] - 1
let l:item = get(l:item_list, l:index, {})

if empty(l:item)
return
endif

" Remember an index to jump to when repeating a selection.
let s:last_options.jump_to_index = l:index

:q!

call ale#util#Open(
Expand Down

0 comments on commit 7862633

Please sign in to comment.