diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index 5c68add..53992f0 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -137,6 +137,20 @@ M.grep = function(opts) contents = contents .. " 2>&1" end + -- when using an empty string grep (as in 'grep_project') or + -- when switching from grep to live_grep using 'ctrl-g' users + -- may find it confusing why is the last typed query not + -- considered the last search so we find out if that's the + -- case and use the last typed prompt as the grep string + opts.fn_post_fzf = function(o, _) + local last_search, _ = get_last_search(o) + local last_query = config.__resume_data and config.__resume_data.last_query + if not last_search or #last_search==0 + and (last_query and #last_query>0) then + set_last_search(opts, last_query) + end + end + opts = core.set_fzf_field_index(opts) core.fzf_files(opts, contents) opts.search = nil diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index 96de7c9..0a9d939 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -102,6 +102,16 @@ local function tags(opts) end end + -- see my comment in 'grep.lua:grep' what this is for + opts.fn_post_fzf = function(o, _) + local last_search, _ = M.get_last_search(o) + local last_query = config.__resume_data and config.__resume_data.last_query + if not last_search or #last_search==0 + and (last_query and #last_query>0) then + M.set_last_search(opts, last_query) + end + end + -- save the search query so the use can -- call the same search again M.set_last_search(opts, opts.search, opts.no_esc)