mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-24 02:10:05 +08:00
use floating windows for flygrep (#2216)
This commit is contained in:
parent
e05a364225
commit
ca5465ab6e
@ -16,6 +16,8 @@ let s:LIST = SpaceVim#api#import('data#list')
|
||||
let s:HI = SpaceVim#api#import('vim#highlight')
|
||||
" }}}
|
||||
|
||||
let s:grepid = 0
|
||||
|
||||
" Init local options: {{{
|
||||
let s:grep_expr = ''
|
||||
let [
|
||||
@ -258,6 +260,7 @@ function! s:close_grep_job() abort
|
||||
" NOTE: the jobid maybe -1, that is means the cmd is not executable.
|
||||
if s:grepid > 0
|
||||
call s:JOB.stop(s:grepid)
|
||||
let s:std_line = 0
|
||||
endif
|
||||
call timer_stop(s:grep_timer_id)
|
||||
call timer_stop(s:preview_timer_id)
|
||||
@ -275,6 +278,16 @@ endfunction
|
||||
" @vimlint(EVL103, 1, a:data)
|
||||
" @vimlint(EVL103, 1, a:id)
|
||||
" @vimlint(EVL103, 1, a:event)
|
||||
|
||||
" if exists('*nvim_open_win')
|
||||
" let s:std_line = 0
|
||||
" function! s:grep_stdout(id, data, event) abort
|
||||
" let datas =filter(a:data, '!empty(v:val)')
|
||||
" call nvim_buf_set_lines(s:buffer_id,s:std_line,-1,v:true,datas)
|
||||
" let s:std_line += len(datas)
|
||||
" call s:MPT._build_prompt()
|
||||
" endfunction
|
||||
" else
|
||||
function! s:grep_stdout(id, data, event) abort
|
||||
let datas =filter(a:data, '!empty(v:val)')
|
||||
" let datas = s:LIST.uniq_by_func(datas, function('s:file_line'))
|
||||
@ -288,6 +301,7 @@ function! s:grep_stdout(id, data, event) abort
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
" endif
|
||||
|
||||
function! s:grep_stderr(id, data, event) abort
|
||||
call SpaceVim#logger#error(' flygerp stderr: ' . string(a:data))
|
||||
@ -297,6 +311,7 @@ function! s:grep_exit(id, data, event) abort
|
||||
redraw
|
||||
call s:MPT._build_prompt()
|
||||
redrawstatus
|
||||
let s:std_line = 1
|
||||
let s:grepid = 0
|
||||
endfunction
|
||||
" @vimlint(EVL103, 0, a:data)
|
||||
@ -446,6 +461,13 @@ endfunction
|
||||
let s:previewd_bufnrs = []
|
||||
|
||||
" @vimlint(EVL103, 1, a:timer)
|
||||
" use floating windows to preview
|
||||
let s:preview_win_id = -1
|
||||
if exists('*nvim_open_win')
|
||||
function! s:preview_timer(timer) abort
|
||||
|
||||
endfunction
|
||||
else
|
||||
function! s:preview_timer(timer) abort
|
||||
for id in filter(s:previewd_bufnrs, 'bufexists(v:val) && buflisted(v:val)')
|
||||
exe 'silent bd ' . id
|
||||
@ -463,6 +485,7 @@ function! s:preview_timer(timer) abort
|
||||
resize 18
|
||||
call s:MPT._build_prompt()
|
||||
endfunction
|
||||
endif
|
||||
" @vimlint(EVL103, 0, a:timer)
|
||||
|
||||
|
||||
@ -573,7 +596,22 @@ function! SpaceVim#plugins#flygrep#open(agrv) abort
|
||||
let s:mode = ''
|
||||
" set default handle func: s:flygrep
|
||||
let s:MPT._handle_fly = function('s:flygrep')
|
||||
if exists('*nvim_open_win')
|
||||
let s:buffer_id = nvim_create_buf(v:false, v:false)
|
||||
let flygrep_win_height = 16
|
||||
let s:flygrep_win_id = nvim_open_win(s:buffer_id, v:true, &columns, flygrep_win_height,
|
||||
\ {
|
||||
\ 'relative': 'editor',
|
||||
\ 'row': &lines - flygrep_win_height - 2,
|
||||
\ 'col': 0
|
||||
\ })
|
||||
else
|
||||
noautocmd rightbelow split __flygrep__
|
||||
let s:flygrep_win_id = win_getid()
|
||||
endif
|
||||
if exists('&winhighlight')
|
||||
set winhighlight=Normal:Pmenu,EndOfBuffer:Pmenu,CursorLine:PmenuSel
|
||||
endif
|
||||
let s:flygrep_buffer_id = bufnr('%')
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
|
||||
let save_tve = &t_ve
|
||||
@ -632,6 +670,42 @@ function! SpaceVim#plugins#flygrep#open(agrv) abort
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
let s:statusline_win_id = -1
|
||||
let s:statusline_buf_id = -1
|
||||
function! s:create_statusline() abort
|
||||
let s:statusline_buf_id = nvim_create_buf(0,0)
|
||||
let s:statusline_win_id = nvim_open_win(s:statusline_buf_id,
|
||||
\ v:true,
|
||||
\ &columns ,
|
||||
\ 1,
|
||||
\ {
|
||||
\ 'relative': 'editor',
|
||||
\ 'row': &lines ,
|
||||
\ 'col': 10
|
||||
\ })
|
||||
call setbufvar(s:statusline_buf_id, '&relativenumber', 0)
|
||||
call setbufvar(s:statusline_buf_id, '&number', 0)
|
||||
call nvim_buf_set_virtual_text(
|
||||
\ s:statusline_buf_id,
|
||||
\ -1,
|
||||
\ 0,
|
||||
\ [
|
||||
\ ['FlyGrep ', 'SpaceVim_statusline_a_bold'],
|
||||
\ ['', 'SpaceVim_statusline_a_SpaceVim_statusline_b'],
|
||||
\ [SpaceVim#plugins#flygrep#mode(), 'SpaceVim_statusline_b'],
|
||||
\ ['', 'SpaceVim_statusline_b_SpaceVim_statusline_c'],
|
||||
\ [getcwd(), 'SpaceVim_statusline_c'],
|
||||
\ ['', 'SpaceVim_statusline_c_SpaceVim_statusline_b'],
|
||||
\ [SpaceVim#plugins#flygrep#lineNr(), 'SpaceVim_statusline_b'],
|
||||
\ ['', 'SpaceVim_statusline_b_SpaceVim_statusline_z'],
|
||||
\ ],
|
||||
\ {})
|
||||
endfunction
|
||||
|
||||
function! Test_st() abort
|
||||
call s:create_statusline()
|
||||
endfunction
|
||||
|
||||
" Plugin API: SpaceVim#plugins#flygrep#lineNr() {{{
|
||||
function! SpaceVim#plugins#flygrep#lineNr() abort
|
||||
if getline(1) ==# ''
|
||||
|
Loading…
Reference in New Issue
Block a user