Fix #3316 - Repeat -relative for ALERepeatSelection
This commit is contained in:
parent
f5aa0e8457
commit
66ff00c420
2 changed files with 35 additions and 16 deletions
|
@ -1,14 +1,22 @@
|
||||||
" Author: w0rp <devw0rp@gmail.com>
|
" Author: w0rp <devw0rp@gmail.com>
|
||||||
" Description: Preview windows for showing whatever information in.
|
" Description: Preview windows for showing whatever information in.
|
||||||
|
|
||||||
if !has_key(s:, 'last_selection_list')
|
if !has_key(s:, 'last__list')
|
||||||
let s:last_selection_list = []
|
let s:last_list = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !has_key(s:, 'last_selection_open_in')
|
if !has_key(s:, 'last_options')
|
||||||
let s:last_selection_open_in = 'current-buffer'
|
let s:last_options = {}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! ale#preview#SetLastSelection(item_list, options) abort
|
||||||
|
let s:last_list = a:item_list
|
||||||
|
let s:last_options = {
|
||||||
|
\ 'open_in': get(a:options, 'open_in', 'current-buffer'),
|
||||||
|
\ 'use_relative_paths': get(a:options, 'use_relative_paths', 0),
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Open a preview window and show some lines in it.
|
" Open a preview window and show some lines in it.
|
||||||
" A second argument can be passed as a Dictionary with options. They are...
|
" A second argument can be passed as a Dictionary with options. They are...
|
||||||
"
|
"
|
||||||
|
@ -81,19 +89,14 @@ function! ale#preview#ShowSelection(item_list, ...) abort
|
||||||
let b:ale_preview_item_list = a:item_list
|
let b:ale_preview_item_list = a:item_list
|
||||||
let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer')
|
let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer')
|
||||||
|
|
||||||
" Remove the last preview
|
" Remember preview state, so we can repeat it later.
|
||||||
let s:last_selection_list = b:ale_preview_item_list
|
call ale#preview#SetLastSelection(a:item_list, l:options)
|
||||||
let s:last_selection_open_in = b:ale_preview_item_open_in
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#preview#RepeatSelection() abort
|
function! ale#preview#RepeatSelection() abort
|
||||||
if empty(s:last_selection_list)
|
if !empty(s:last_list)
|
||||||
return
|
call ale#preview#ShowSelection(s:last_list, s:last_options)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call ale#preview#ShowSelection(s:last_selection_list, {
|
|
||||||
\ 'open_in': s:last_selection_open_in,
|
|
||||||
\})
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Open(open_in) abort
|
function! s:Open(open_in) abort
|
||||||
|
|
|
@ -63,6 +63,8 @@ Before:
|
||||||
let g:preview_called = 1
|
let g:preview_called = 1
|
||||||
let g:item_list = a:item_list
|
let g:item_list = a:item_list
|
||||||
let g:options = a:options
|
let g:options = a:options
|
||||||
|
|
||||||
|
call ale#preview#SetLastSelection(a:item_list, a:options)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
@ -110,7 +112,16 @@ Given typescript(Some typescript file):
|
||||||
bazxyzxyzxyz
|
bazxyzxyzxyz
|
||||||
|
|
||||||
Execute(Results should be shown for tsserver responses):
|
Execute(Results should be shown for tsserver responses):
|
||||||
call ale#references#SetMap({3: {}})
|
" We should remember these options when we repeat the selection.
|
||||||
|
call ale#references#SetMap(
|
||||||
|
\ {
|
||||||
|
\ 3: {
|
||||||
|
\ 'ignorethis': 'x',
|
||||||
|
\ 'open_in': 'tab',
|
||||||
|
\ 'use_relative_paths': 1,
|
||||||
|
\ }
|
||||||
|
\ }
|
||||||
|
\)
|
||||||
call ale#references#HandleTSServerResponse(1, {
|
call ale#references#HandleTSServerResponse(1, {
|
||||||
\ 'command': 'references',
|
\ 'command': 'references',
|
||||||
\ 'request_seq': 3,
|
\ 'request_seq': 3,
|
||||||
|
@ -158,8 +169,7 @@ Execute(Results should be shown for tsserver responses):
|
||||||
AssertEqual {}, ale#references#GetMap()
|
AssertEqual {}, ale#references#GetMap()
|
||||||
|
|
||||||
" We should be able to repeat selections with ALERepeatSelection
|
" We should be able to repeat selections with ALERepeatSelection
|
||||||
let g:ale_item_list = []
|
let g:item_list = []
|
||||||
|
|
||||||
ALERepeatSelection
|
ALERepeatSelection
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
|
@ -170,6 +180,12 @@ Execute(Results should be shown for tsserver responses):
|
||||||
\ ],
|
\ ],
|
||||||
\ g:item_list
|
\ g:item_list
|
||||||
AssertEqual {}, ale#references#GetMap()
|
AssertEqual {}, ale#references#GetMap()
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'open_in': 'tab',
|
||||||
|
\ 'use_relative_paths': 1,
|
||||||
|
\ },
|
||||||
|
\ g:options
|
||||||
|
|
||||||
Execute(The preview window should not be opened for empty tsserver responses):
|
Execute(The preview window should not be opened for empty tsserver responses):
|
||||||
call ale#references#SetMap({3: {}})
|
call ale#references#SetMap({3: {}})
|
||||||
|
|
Reference in a new issue