new option 'global_resume_query': split resume from typed query (#271)

main
bhagwan 2 years ago
parent ab30844a7a
commit 21f19cac1a

@ -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:
-- `<any_function>.({ 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

@ -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:
-- `<any_function>.({ 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

@ -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 = {

@ -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

@ -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)

@ -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)

@ -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)

Loading…
Cancel
Save