1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 05:30:07 +08:00

Fix mouse wheel in flygrep

This commit is contained in:
wsdjeg 2017-12-05 20:49:16 +08:00
parent d8774f488e
commit dc812ae0c7

View File

@ -5,15 +5,15 @@ let s:grepid = 0
function! SpaceVim#plugins#flygrep#open() abort
rightbelow split __flygrep__
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
let save_tve = &t_ve
setlocal t_ve=
" setlocal nomodifiable
setf SpaceVimFlyGrep
redraw!
call s:MPT.open()
let &t_ve = save_tve
rightbelow split __flygrep__
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
let save_tve = &t_ve
setlocal t_ve=
" setlocal nomodifiable
setf SpaceVimFlyGrep
redraw!
call s:MPT.open()
let &t_ve = save_tve
endfunction
let s:grep_expr = ''
@ -22,53 +22,53 @@ let s:grep_timer_id = 0
" @vimlint(EVL103, 1, a:timer)
function! s:grep_timer(timer) abort
let s:grepid = s:JOB.start(s:get_search_cmd(s:grep_exe, s:grep_expr), {
\ 'on_stdout' : function('s:grep_stdout'),
\ 'in_io' : 'null',
\ 'on_exit' : function('s:grep_exit'),
\ })
let s:grepid = s:JOB.start(s:get_search_cmd(s:grep_exe, s:grep_expr), {
\ 'on_stdout' : function('s:grep_stdout'),
\ 'in_io' : 'null',
\ 'on_exit' : function('s:grep_exit'),
\ })
endfunction
" @vimlint(EVL103, 0, a:timer)
function! s:flygrep(expr) abort
call s:MPT._build_prompt()
if a:expr ==# ''
redrawstatus
return
endif
try
syn clear FileNames
catch
endtr
exe 'syn match FileNames /' . substitute(a:expr, '\([/\\]\)', '\\\1', 'g') . '/'
hi def link FileNames MoreMsg
let s:grep_expr = a:expr
let s:grep_timer_id = timer_start(500, funcref('s:grep_timer'), {'repeat' : 1})
call s:MPT._build_prompt()
if a:expr ==# ''
redrawstatus
return
endif
try
syn clear FileNames
catch
endtr
exe 'syn match FileNames /' . substitute(a:expr, '\([/\\]\)', '\\\1', 'g') . '/'
hi def link FileNames MoreMsg
let s:grep_expr = a:expr
let s:grep_timer_id = timer_start(500, funcref('s:grep_timer'), {'repeat' : 1})
endfunction
let s:MPT._handle_fly = function('s:flygrep')
function! s:close_buffer() abort
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
if s:grep_timer_id != 0
call timer_stop(s:grep_timer_id)
endif
q
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
if s:grep_timer_id != 0
call timer_stop(s:grep_timer_id)
endif
q
endfunction
let s:MPT._onclose = function('s:close_buffer')
function! s:close_grep_job() abort
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
if s:grep_timer_id != 0
call timer_stop(s:grep_timer_id)
endif
normal! "_ggdG
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
if s:grep_timer_id != 0
call timer_stop(s:grep_timer_id)
endif
normal! "_ggdG
endfunction
let s:MPT._oninputpro = function('s:close_grep_job')
@ -77,18 +77,18 @@ let s:MPT._oninputpro = function('s:close_grep_job')
" @vimlint(EVL103, 1, a:id)
" @vimlint(EVL103, 1, a:event)
function! s:grep_stdout(id, data, event) abort
let datas =filter(a:data, '!empty(v:val)')
if getline(1) ==# ''
call setline(1, datas)
else
call append('$', datas)
endif
call s:MPT._build_prompt()
let datas =filter(a:data, '!empty(v:val)')
if getline(1) ==# ''
call setline(1, datas)
else
call append('$', datas)
endif
call s:MPT._build_prompt()
endfunction
function! s:grep_exit(id, data, event) abort
redrawstatus
let s:grepid = 0
redrawstatus
let s:grepid = 0
endfunction
" @vimlint(EVL103, 0, a:data)
@ -96,98 +96,113 @@ endfunction
" @vimlint(EVL103, 0, a:event)
function! s:get_search_cmd(exe, expr) abort
if a:exe ==# 'grep'
return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.']
elseif a:exe ==# 'rg'
return ['rg', '-n', '-i', a:expr]
else
return [a:exe, a:expr]
endif
if a:exe ==# 'grep'
return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.']
elseif a:exe ==# 'rg'
return ['rg', '-n', '-i', a:expr]
else
return [a:exe, a:expr]
endif
endfunction
function! s:next_item() abort
if line('.') == line('$')
normal! gg
else
normal! j
endif
redrawstatus
call s:MPT._build_prompt()
if line('.') == line('$')
normal! gg
else
normal! j
endif
redrawstatus
call s:MPT._build_prompt()
endfunction
function! s:previous_item() abort
if line('.') == 1
normal! G
else
normal! k
endif
redrawstatus
call s:MPT._build_prompt()
if line('.') == 1
normal! G
else
normal! k
endif
redrawstatus
call s:MPT._build_prompt()
endfunction
function! s:open_item() abort
if getline('.') !=# ''
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
call s:MPT._clear_prompt()
let s:MPT._quit = 1
let line = getline('.')
let filename = fnameescape(split(line, ':\d\+:')[0])
let linenr = matchstr(line, ':\d\+:')[1:-2]
q
exe 'e ' . filename
exe linenr
if getline('.') !=# ''
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
call s:MPT._clear_prompt()
let s:MPT._quit = 1
let line = getline('.')
let filename = fnameescape(split(line, ':\d\+:')[0])
let linenr = matchstr(line, ':\d\+:')[1:-2]
q
exe 'e ' . filename
exe linenr
endif
endfunction
function! s:double_click() abort
if line('.') !=# ''
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
call s:MPT._clear_prompt()
let s:MPT._quit = 1
let isfname = &isfname
if s:SYS.isWindows
set isfname-=:
endif
normal! gF
let nr = bufnr('%')
q
exe 'silent b' . nr
normal! :
let &isfname = isfname
if line('.') !=# ''
if s:grepid != 0
call s:JOB.stop(s:grepid)
endif
call s:MPT._clear_prompt()
let s:MPT._quit = 1
let isfname = &isfname
if s:SYS.isWindows
set isfname-=:
endif
normal! gF
let nr = bufnr('%')
q
exe 'silent b' . nr
normal! :
let &isfname = isfname
endif
endfunction
function! s:move_cursor() abort
if v:mouse_win == winnr()
let cl = line('.')
if cl < v:mouse_lnum
exe 'normal! ' . (v:mouse_lnum - cl) . 'j'
elseif cl > v:mouse_lnum
exe 'normal! ' . (cl - v:mouse_lnum) . 'k'
endif
if v:mouse_win == winnr()
let cl = line('.')
if cl < v:mouse_lnum
exe 'normal! ' . (v:mouse_lnum - cl) . 'j'
elseif cl > v:mouse_lnum
exe 'normal! ' . (cl - v:mouse_lnum) . 'k'
endif
call s:MPT._build_prompt()
endif
call s:MPT._build_prompt()
endfunction
let s:MPT._function_key = {
\ "\<Tab>" : function('s:next_item'),
\ "\<ScrollWheelDown>" : function('s:next_item'),
\ "\<S-tab>" : function('s:previous_item'),
\ "\<ScrollWheelUp>" : function('s:previous_item'),
\ "\<Return>" : function('s:open_item'),
\ "\<LeftMouse>" : function('s:move_cursor'),
\ "\<2-LeftMouse>" : function('s:double_click'),
\ }
\ "\<Tab>" : function('s:next_item'),
\ "\<ScrollWheelDown>" : function('s:next_item'),
\ "\<S-tab>" : function('s:previous_item'),
\ "\<ScrollWheelUp>" : function('s:previous_item'),
\ "\<Return>" : function('s:open_item'),
\ "\<LeftMouse>" : function('s:move_cursor'),
\ "\<2-LeftMouse>" : function('s:double_click'),
\ }
if has('nvim')
call extend(s:MPT._function_key,
\ {
\ "\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\xfc \x80\xfdK" : function('s:next_item'),
\ "\x80\xfc@\x80\xfdK" : function('s:next_item'),
\ "\x80\xfc`\x80\xfdK" : function('s:next_item'),
\ }
\ )
endif
" statusline api
function! SpaceVim#plugins#flygrep#lineNr() abort
if getline(1) ==# ''
return ''
else
return line('.') . '/' . line('$')
endif
if getline(1) ==# ''
return ''
else
return line('.') . '/' . line('$')
endif
endfunction