From 21f19cac1a0e3a1a87824762fee667218db032db Mon Sep 17 00:00:00 2001 From: bhagwan Date: Mon, 20 Dec 2021 18:12:37 -0800 Subject: [PATCH] new option 'global_resume_query': split resume from typed query (#271) --- README.md | 8 +++++--- doc/fzf-lua.txt | 8 +++++--- lua/fzf-lua/config.lua | 10 ++++++++++ lua/fzf-lua/core.lua | 24 +++++++++++++++++------- lua/fzf-lua/providers/grep.lua | 4 ++-- lua/fzf-lua/providers/lsp.lua | 2 +- lua/fzf-lua/providers/module.lua | 8 +++----- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3cf5c63..6cdb450 100644 --- a/README.md +++ b/README.md @@ -214,9 +214,11 @@ Consult the list below for available settings: local actions = require "fzf-lua.actions" require'fzf-lua'.setup { global_resume = true, -- enable global `resume`? - -- send 'no_global_resume = true' - -- to exclude specific providers - -- from being resumed + -- can also be sent individually: + -- `.({ gl ... })` + global_resume_query = true, -- include typed query in `resume`? + -- may cause lag when fast typing + -- disable if you're having issues winopts = { -- split = "belowright new",-- open in a split instead? -- "belowright new" : split below diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 60ad53b..e2c3e04 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -248,9 +248,11 @@ Consult the list below for available settings: local actions = require "fzf-lua.actions" require'fzf-lua'.setup { global_resume = true, -- enable global `resume`? - -- send 'no_global_resume = true' - -- to exclude specific providers - -- from being resumed + -- can also be sent individually: + -- `.({ gl ... })` + global_resume_query = true, -- include typed query in `resume`? + -- may cause lag when fast typing + -- disable if you're having issues winopts = { -- split = "belowright new",-- open in a split instead? -- "belowright new" : split below diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 0721abd..c69efeb 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -26,6 +26,7 @@ M.__resume_data = {} M.globals = { global_resume = true, + global_resume_query = true, winopts = { height = 0.85, width = 0.80, @@ -590,6 +591,15 @@ function M.normalize_opts(opts, defaults) opts[k] or {}, utils.tbl_deep_clone(M.globals[k]) or {}) end + local function get_opt(o, t1, t2) + if t1[o] ~= nil then return t1[o] + else return t2[o] end + end + + -- Merge global resume options + opts.global_resume = get_opt('global_resume', opts, M.globals) + opts.global_resume_query = get_opt('global_resume_query', opts, M.globals) + -- backward compatibility, rhs overrides lhs -- (rhs being the "old" option) local backward_compat = { diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index c735806..aa01c37 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -46,8 +46,12 @@ M.fzf_wrap = function(opts, contents, fn_post) end M.fzf = function(opts, contents) + -- normalize with globals if not already normalized + if not opts._normalized then + opts = config.normalize_opts(opts, {}) + end -- support global resume? - if config.globals.global_resume and not opts.no_global_resume then + if opts.global_resume then config.__resume_data = config.__resume_data or {} config.__resume_data.opts = vim.deepcopy(opts) config.__resume_data.contents = contents and vim.deepcopy(contents) or nil @@ -60,18 +64,24 @@ M.fzf = function(opts, contents) -- providers config.__resume_data.last_query = nil end - if not opts._is_skim and not opts.no_global_resume_act then + -- signals to the win object resume is enabled + -- so we can setup the keypress event monitoring + -- TODO: how to get keypress event in neovim? + -- InsertCharPre would be perfect here but: + -- https://github.com/neovim/neovim/issues/5018 + opts.fn_save_query = function(query) + config.__resume_data.last_query = query and #query>0 and query + end + -- this is causing lag when typing too fast (#271) + -- also not possible with skim (no 'change' event) + if opts.global_resume_query and not opts._is_skim then local raw_act = shell.raw_action(function(args) - config.__resume_data.last_query = args[1] + opts.fn_save_query(args[1]) end, "{q}") opts._fzf_cli_args = ('--bind=change:execute-silent:%s'): format(vim.fn.shellescape(raw_act)) end end - -- normalize with globals if not already normalized - if not opts._normalized then - opts = config.normalize_opts(opts, {}) - end -- setup the fzf window and preview layout local fzf_win = win(opts) if not fzf_win then return end diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index 2e72713..840ed85 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -152,7 +152,7 @@ M.live_grep_st = function(opts) -- disable global resume -- conflicts with 'change:reload' event - opts.no_global_resume_act = true + opts.global_resume_query = false opts.__FNCREF__ = opts.__FNCREF__ or utils.__FNCREF__() opts = core.set_fzf_line_args(opts) opts = core.set_fzf_interactive_cmd(opts) @@ -269,7 +269,7 @@ M.live_grep_mt = function(opts) -- disable global resume -- conflicts with 'change:reload' event - opts.no_global_resume_act = true + opts.global_resume_query = false opts.__FNCREF__ = opts.__FNCREF__ or utils.__FNCREF__() opts = core.set_fzf_line_args(opts) core.fzf_files(opts) diff --git a/lua/fzf-lua/providers/lsp.lua b/lua/fzf-lua/providers/lsp.lua index 682f523..838657c 100644 --- a/lua/fzf-lua/providers/lsp.lua +++ b/lua/fzf-lua/providers/lsp.lua @@ -639,7 +639,7 @@ M.live_workspace_symbols = function(opts) -- disable global resume -- conflicts with 'change:reload' event - opts.no_global_resume_act = true + opts.global_resume_query = false opts.__FNCREF__ = M.live_workspace_symbols opts = core.set_fzf_interactive_cb(opts) opts = core.set_fzf_line_args(opts) diff --git a/lua/fzf-lua/providers/module.lua b/lua/fzf-lua/providers/module.lua index 1a111b1..62e5bf0 100644 --- a/lua/fzf-lua/providers/module.lua +++ b/lua/fzf-lua/providers/module.lua @@ -31,11 +31,9 @@ M.metatable = function(opts) opts.fzf_opts['--preview-window'] = 'hidden:down:10' opts.fzf_opts['--no-multi'] = '' - if opts.no_global_resume == nil then - -- builtin is excluded by from global resume - -- as the behavior might confuse users (#267) - opts.no_global_resume = true - end + -- builtin is excluded by from global resume + -- as the behavior might confuse users (#267) + opts.global_resume = false core.fzf_wrap(opts, methods, function(selected)