Skip to content

Commit

Permalink
Factor out user#plugin#ddu#update_input
Browse files Browse the repository at this point in the history
  • Loading branch information
creasty committed Sep 16, 2023
1 parent af13998 commit e9c898e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions nvim/autoload/user/plugin/ddu.vim
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
let s:last_cwd = ''
let s:preserved_inputs = {}

function! s:can_resume() abort
let l:cwd = getcwd()
let l:is_same_dir = (l:cwd == s:last_cwd)
let s:last_cwd = l:cwd
return l:is_same_dir
endfunction

let s:preserved_inputs = {}
function! s:get_preserved_input(name, reset) abort
if a:reset || get(s:preserved_inputs, a:name, '') ==# ''
let s:preserved_inputs[a:name] = input('Search: ')
endif
return s:preserved_inputs[a:name]
endfunction

function! user#plugin#ddu#get_preserved_input() abort
if has_key(s:preserved_inputs, b:ddu_ui_name)
return s:get_preserved_input(b:ddu_ui_name, v:true)
else
return ''
end
function! user#plugin#ddu#update_input() abort
let l:input = has_key(s:preserved_inputs, b:ddu_ui_name)
\ ? s:get_preserved_input(b:ddu_ui_name, v:true)
\ : ''
call ddu#redraw(b:ddu_ui_name, {
\ 'refreshItems': v:true,
\ 'input': l:input,
\ })
endfunction

function! user#plugin#ddu#open() abort
Expand Down Expand Up @@ -117,7 +118,7 @@ function! user#plugin#ddu#init_buffer() abort
nnoremap <buffer><script> <C-l> <SID>(reset-cursor)<SID>(refresh)
inoremap <buffer><script> <C-l> <Esc><SID>(reset-cursor)<SID>(refresh)i
nnoremap <buffer> <SID>(reload) <Cmd>call ddu#redraw(b:ddu_ui_name, { 'refreshItems': v:true, 'input': user#plugin#ddu#get_preserved_input() })<CR>
nnoremap <buffer> <SID>(reload) <Cmd>call user#plugin#ddu#update_input()<CR>
nnoremap <buffer><script> <C-r> <SID>(reload)
inoremap <buffer><script> <C-r> <Esc><SID>(reload)i
Expand Down

0 comments on commit e9c898e

Please sign in to comment.