250829.25 · 7ceca1fb5fb6050a40b377ad5ab6c2be1d72ee2b
fix(fzf_live): reload action in live picker
regression from 31dfbe018e28de062d79387ec52a71962b85b16f
reading declarations
@@ -169,6 +169,7 @@ end ---@return boolean M.can_transform = function(opts) return utils.has(opts, "fzf", { 0, 45 })+ and opts.fn_reload -- currently only used for "live" picker and opts.rg_glob and not opts.multiprocess and not opts.fn_transform@@ -177,12 +178,12 @@ M.can_transform = function(opts) end ---@param contents string|fun(query: string[]): string|string[]|function?----@param opts? table+---@param opts? fzf-lua.config.Base|{} ---@return thread?, string?, table? M.fzf_live = function(contents, opts)+ opts.fn_reload = true opts = config.normalize_opts(opts or {}, {}) if not opts then return end- opts.fn_reload = contents -- AKA "live": fzf acts as a selector only (fuzzy matching is disabled) -- each keypress reloads fzf's input usually based on the typed query -- utilizes fzf's 'change:reload' event or skim's "interactive" mode@@ -201,7 +202,7 @@ M.fzf_live = function(contents, opts) if type(contents) == "function" and M.can_transform(opts) then local cmd = shell.stringify_data(contents, opts, fzf_field_index) M.setup_fzf_live_flags(cmd, fzf_field_index, opts)- return M.fzf_wrap(utils.shell_nop(), opts, true)+ return M.fzf_wrap(cmd, opts, true) end local cmd0 = contents ---@type string local func_contents = type(contents) == "function"@@ -216,7 +217,7 @@ M.fzf_live = function(contents, opts) shell.stringify(func_contents, opts, fzf_field_index) cmd = mt and M.expand_query(cmd, fzf_field_index) or cmd M.setup_fzf_live_flags(cmd, fzf_field_index, opts)- return M.fzf_wrap(utils.shell_nop(), opts, true)+ return M.fzf_wrap(cmd, opts, true) end M.fzf_resume = function(opts)@@ -1004,10 +1005,11 @@ M.convert_reload_actions = function(reload_cmd, opts) end local cmd = shell.stringify_data2(v.fn, opts, v.field_index or "{+}") opts.keymap.fzf[k] = {- string.format("%s%sexecute-silent(%s)+reload(%s)%s",+ string.format("%s%sexecute-silent(%s)+%s(%s)%s", type(v.prefix) == "string" and v.prefix or "", unbind and (unbind .. "+") or "", cmd,+ M.can_transform(opts) and "transform" or "reload", -- contents is not "cmd" but "reload:cmd" reload_cmd, type(v.postfix) == "string" and v.postfix or ""), desc = v.desc or config.get_action_helpstr(v.fn)
@@ -151,6 +151,7 @@ _G.FzfLua = require("fzf-lua") ---@field resume boolean? ---@field no_resume boolean? ---@field profile string|table?+---@field fn_reload boolean? is "live" picker ---set_headers ---@field _headers string[]? ---@field headers string[]?
@@ -35,4 +35,29 @@ T["actions"]["ui don't freeze on error"] = function() child.expect_screen_lines(screen_opts) end +T["actions"]["reload"] = new_set({+ parametrize = { { "fzf_live" }, { "fzf_exec" } }+}, {+ function(api)+ local screen_opts = { ignore_text = { 28 } }+ helpers.FzfLua[api](child, api == "fzf_exec"+ and [[function(cb) cb(_G._fzf_reload and 'reloaded' or 'unreloaded') cb(nil) end]]+ or [[function() return { _G._fzf_reload and 'reloaded' or 'unreloaded' } end ]],+ {+ __no_abort = true,+ __expect_lines = false,+ __after_open = function()+ if helpers.IS_WIN() then vim.uv.sleep(250) end+ end,+ actions = {+ ["ctrl-a"] = { fn = function() _G._fzf_reload = true end, reload = true },+ },+ })+ child.type_keys("<c-a>")+ child.wait_until(function() return child.lua_get([[_G._fzf_reload]]) == true end)+ if helpers.IS_WIN() then vim.uv.sleep(250) end+ child.expect_screen_lines(screen_opts)+ end+})+ return T
tests/screenshots/tests-actions_spec.lua---actions---reload---1-+-args-{-'fzf_exec'-}
@@ -0,0 +1,29 @@+--|---------|---------|---------|---------|---------|---------|----+01| +02|~ +03|~ ╭─────────────────────────────────────────────────╮ +04|~ │> 1/1 │ +05|~ │──────────────────────────────────────────────── │ +06|~ │▌ reloaded │ +07|~ │ │ +08|~ │ │ +09|~ │ │ +10|~ │ │ +11|~ │ │ +12|~ │ │ +13|~ │ │ +14|~ │ │ +15|~ │ │ +16|~ │ │ +17|~ │ │ +18|~ │ │ +19|~ │ │ +20|~ │ │ +21|~ │ │ +22|~ ╰─────────────────────────────────────────────────╯ +23|~ +24|[No Name] 0,0-1 All+25| +26| +27| +28|-- TERMINAL -- 1,3 All
tests/screenshots/tests-actions_spec.lua---actions---reload---1-+-args-{-'fzf_live'-}
@@ -0,0 +1,29 @@+--|---------|---------|---------|---------|---------|---------|----+01| +02|~ +03|~ ╭─────────────────────────────────────────────────╮ +04|~ │> 1/1 │ +05|~ │──────────────────────────────────────────────── │ +06|~ │▌ reloaded │ +07|~ │ │ +08|~ │ │ +09|~ │ │ +10|~ │ │ +11|~ │ │ +12|~ │ │ +13|~ │ │ +14|~ │ │ +15|~ │ │ +16|~ │ │ +17|~ │ │ +18|~ │ │ +19|~ │ │ +20|~ │ │ +21|~ │ │ +22|~ ╰─────────────────────────────────────────────────╯ +23|~ +24|[No Name] 0,0-1 All+25| +26| +27| +28|-- TERMINAL -- 1,3 All
@@ -274,7 +274,7 @@ T["win"]["previewer"]["toggle_behavior=extend"] = new_set( if o.preview then opts.previewer = nil -- "echo {}", windows: "foo", unix: foo- opts.__screen_opts.ignore_text = { 15 }+ table.insert(opts.__screen_opts.ignore_text, 15) end opts = vim.tbl_extend("force", opts, o) helpers.FzfLua.fzf_exec(child, [==[{ "foo", "bar", "baz" }]==], opts)@@ -291,7 +291,7 @@ T["win"]["reuse"] = new_set({ }, { function(o) -- Ignore terminal command line with process number- local screen_opts = { ignore_text = { 24 }, normalize_paths = helpers.IS_WIN() }+ local screen_opts = { ignore_text = { 24, 28 }, normalize_paths = helpers.IS_WIN() } local opts = { __no_abort = true, __expect_lines = false,