1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-14 10:45:42 +08:00

fix(flygrep): save previous windows id

merge: https://github.com/SpaceVim/SpaceVim/pull/4479
Co-authored-by: jsecchiero <secchierojacopo@gmail.com>
This commit is contained in:
Shidong Wang 2021-10-17 23:11:58 +08:00
parent 83aa15f1ee
commit cf9b7c08aa
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848

View File

@ -31,6 +31,19 @@ let s:grepid = 0
let s:filename_pattern = '[^:]*:\d\+:\d\+:' let s:filename_pattern = '[^:]*:\d\+:\d\+:'
" if win_getid does not existing, use winnr instead
let s:previous_winid = 0
function! s:close_flygrep_win() abort
noautocmd q
" this function requires vim 7.4.1557
if has('patch-7.4.1557')
call win_gotoid(s:previous_winid)
else
exe s:previous_winid . 'wincmd w'
endif
endfunction
" Init local options: {{{ " Init local options: {{{
let s:grep_expr = '' let s:grep_expr = ''
let [ let [
@ -342,7 +355,7 @@ function! s:close_buffer() abort
noautocmd call s:close_preview_win() noautocmd call s:close_preview_win()
let s:preview_able = 0 let s:preview_able = 0
endif endif
noautocmd q call s:close_flygrep_win()
endfunction endfunction
let s:MPT._onclose = function('s:close_buffer') let s:MPT._onclose = function('s:close_buffer')
" }}} " }}}
@ -502,7 +515,7 @@ function! s:open_item() abort
call s:close_preview_win() call s:close_preview_win()
endif endif
let s:preview_able = 0 let s:preview_able = 0
noautocmd q call s:close_flygrep_win()
call s:update_history() call s:update_history()
call s:BUFFER.open_pos('edit', filename, linenr, colum) call s:BUFFER.open_pos('edit', filename, linenr, colum)
noautocmd normal! : noautocmd normal! :
@ -523,7 +536,7 @@ function! s:open_item_in_tab() abort
call s:close_preview_win() call s:close_preview_win()
endif endif
let s:preview_able = 0 let s:preview_able = 0
noautocmd q call s:close_flygrep_win()
call s:update_history() call s:update_history()
call s:BUFFER.open_pos('tabedit', filename, linenr, colum) call s:BUFFER.open_pos('tabedit', filename, linenr, colum)
noautocmd normal! : noautocmd normal! :
@ -544,7 +557,7 @@ function! s:open_item_vertically() abort
call s:close_preview_win() call s:close_preview_win()
endif endif
let s:preview_able = 0 let s:preview_able = 0
noautocmd q call s:close_flygrep_win()
call s:update_history() call s:update_history()
call s:BUFFER.open_pos('vsplit', filename, linenr, colum) call s:BUFFER.open_pos('vsplit', filename, linenr, colum)
noautocmd normal! : noautocmd normal! :
@ -565,7 +578,7 @@ function! s:open_item_horizontally() abort
call s:close_preview_win() call s:close_preview_win()
endif endif
let s:preview_able = 0 let s:preview_able = 0
noautocmd q call s:close_flygrep_win()
call s:update_history() call s:update_history()
call s:BUFFER.open_pos('split', filename, linenr, colum) call s:BUFFER.open_pos('split', filename, linenr, colum)
noautocmd normal! : noautocmd normal! :
@ -573,10 +586,10 @@ function! s:open_item_horizontally() abort
endfunction endfunction
function! s:get_file_pos(line) abort function! s:get_file_pos(line) abort
let filename = fnameescape(split(a:line, ':\d\+:')[0]) let filename = fnameescape(split(a:line, ':\d\+:')[0])
let linenr = str2nr(matchstr(a:line, ':\d\+:')[1:-2]) let linenr = str2nr(matchstr(a:line, ':\d\+:')[1:-2])
let colum = str2nr(matchstr(a:line, '\(:\d\+\)\@<=:\d\+:')[1:-2]) let colum = str2nr(matchstr(a:line, '\(:\d\+\)\@<=:\d\+:')[1:-2])
return [filename, linenr, colum] return [filename, linenr, colum]
endfunction endfunction
function! s:apply_to_quickfix() abort function! s:apply_to_quickfix() abort
@ -591,7 +604,7 @@ function! s:apply_to_quickfix() abort
endif endif
let s:preview_able = 0 let s:preview_able = 0
let searching_result = s:BUFFER.buf_get_lines(s:buffer_id, 0, -1, 0) let searching_result = s:BUFFER.buf_get_lines(s:buffer_id, 0, -1, 0)
noautocmd q call s:close_flygrep_win()
call s:update_history() call s:update_history()
if !empty(searching_result) if !empty(searching_result)
cgetexpr join(searching_result, "\n") cgetexpr join(searching_result, "\n")
@ -671,12 +684,12 @@ if exists('*nvim_open_win') && exists('*nvim_win_set_buf')
let flygrep_win_height = 16 let flygrep_win_height = 16
noautocmd let s:preview_win_id = s:FLOATING.open_win(bufnr, v:false, noautocmd let s:preview_win_id = s:FLOATING.open_win(bufnr, v:false,
\ { \ {
\ 'relative': 'editor', \ 'relative': 'editor',
\ 'width' : &columns, \ 'width' : &columns,
\ 'height' : 5, \ 'height' : 5,
\ 'row': &lines - flygrep_win_height - 2 - 5, \ 'row': &lines - flygrep_win_height - 2 - 5,
\ 'col': 0 \ 'col': 0
\ }) \ })
endif endif
noautocmd call s:Window.set_cursor(s:preview_win_id, [linenr, 1]) noautocmd call s:Window.set_cursor(s:preview_win_id, [linenr, 1])
@ -804,16 +817,16 @@ let s:MPT._function_key = {
if has('nvim') if has('nvim')
call extend(s:MPT._function_key, call extend(s:MPT._function_key,
\ { \ {
\ "\x80\xfdJ" : function('s:previous_item'), \ "\x80\xfdJ" : function('s:previous_item'),
\ "\x80\xfc \x80\xfdJ" : function('s:previous_item'), \ "\x80\xfc \x80\xfdJ" : function('s:previous_item'),
\ "\x80\xfc@\x80\xfdJ" : function('s:previous_item'), \ "\x80\xfc@\x80\xfdJ" : function('s:previous_item'),
\ "\x80\xfc`\x80\xfdJ" : function('s:previous_item'), \ "\x80\xfc`\x80\xfdJ" : function('s:previous_item'),
\ "\x80\xfdK" : function('s:next_item'), \ "\x80\xfdK" : function('s:next_item'),
\ "\x80\xfc \x80\xfdK" : function('s:next_item'), \ "\x80\xfc \x80\xfdK" : function('s:next_item'),
\ "\x80\xfc@\x80\xfdK" : function('s:next_item'), \ "\x80\xfc@\x80\xfdK" : function('s:next_item'),
\ "\x80\xfc`\x80\xfdK" : function('s:next_item'), \ "\x80\xfc`\x80\xfdK" : function('s:next_item'),
\ } \ }
\ ) \ )
endif endif
let s:MPT._keys.close = ["\<Esc>", "\<C-c>"] let s:MPT._keys.close = ["\<Esc>", "\<C-c>"]
@ -825,6 +838,11 @@ let s:MPT._keys.close = ["\<Esc>", "\<C-c>"]
" files: files for grep, @buffers means listed buffer. " files: files for grep, @buffers means listed buffer.
" dir: specific a directory for grep " dir: specific a directory for grep
function! SpaceVim#plugins#flygrep#open(argv) abort function! SpaceVim#plugins#flygrep#open(argv) abort
if has('patch-7.4.1557')
let s:previous_winid = win_getid()
else
let s:previous_winid = winnr()
endif
if empty(s:grep_default_exe) if empty(s:grep_default_exe)
call s:LOGGER.warn(' [flygrep] make sure you have one search tool in your PATH', 1) call s:LOGGER.warn(' [flygrep] make sure you have one search tool in your PATH', 1)
return return
@ -837,12 +855,12 @@ function! SpaceVim#plugins#flygrep#open(argv) abort
let flygrep_win_height = 16 let flygrep_win_height = 16
noautocmd let s:flygrep_win_id = s:FLOATING.open_win(s:buffer_id, v:true, noautocmd let s:flygrep_win_id = s:FLOATING.open_win(s:buffer_id, v:true,
\ { \ {
\ 'relative': 'editor', \ 'relative': 'editor',
\ 'width' : &columns, \ 'width' : &columns,
\ 'height' : flygrep_win_height, \ 'height' : flygrep_win_height,
\ 'row': &lines - flygrep_win_height - 2, \ 'row': &lines - flygrep_win_height - 2,
\ 'col': 0 \ 'col': 0
\ }) \ })
else else
noautocmd botright split __flygrep__ noautocmd botright split __flygrep__
let s:flygrep_win_id = win_getid() let s:flygrep_win_id = win_getid()