From e9fd72bdb8b50fe2fad85af3cc3241c219377b57 Mon Sep 17 00:00:00 2001 From: Kushashwa Ravi Shrimali Date: Sat, 24 Feb 2024 19:35:48 +0530 Subject: [PATCH] feat: only cache picker if the prompt is non empty; support last non-empty search instead (#2817) --- doc/telescope.txt | 22 +++++++++++++--------- lua/telescope/config.lua | 23 ++++++++++++++--------- lua/telescope/pickers.lua | 13 +++++++++---- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 4181e87..ab8faff 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -428,15 +428,19 @@ telescope.setup({opts}) *telescope.setup()* ('cache_picker.limit_entries`) are cached. Fields: - - num_pickers: The number of pickers to be cached. - Set to -1 to preserve all pickers of your session. - If passed to a picker, the cached pickers with - indices larger than `cache_picker.num_pickers` will - be cleared. - Default: 1 - - limit_entries: The amount of entries that will be saved for each - picker. - Default: 1000 + - num_pickers: The number of pickers to be cached. + Set to -1 to preserve all pickers of your + session. If passed to a picker, the cached + pickers with indices larger than + `cache_picker.num_pickers` will be cleared. + Default: 1 + - limit_entries: The amount of entries that will be saved for + each picker. + Default: 1000 + - ignore_empty_prompt: If true, the picker will not be cached if + the prompt is empty (i.e., no text has been + typed at the time of closing the prompt). + Default: false *telescope.defaults.preview* diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index c4b5d40..f274ef7 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -526,6 +526,7 @@ append( { num_pickers = 1, limit_entries = 1000, + ignore_empty_prompt = true, }, [[ This field handles the configuration for picker caching. @@ -538,15 +539,19 @@ append( ('cache_picker.limit_entries`) are cached. Fields: - - num_pickers: The number of pickers to be cached. - Set to -1 to preserve all pickers of your session. - If passed to a picker, the cached pickers with - indices larger than `cache_picker.num_pickers` will - be cleared. - Default: 1 - - limit_entries: The amount of entries that will be saved for each - picker. - Default: 1000 + - num_pickers: The number of pickers to be cached. + Set to -1 to preserve all pickers of your + session. If passed to a picker, the cached + pickers with indices larger than + `cache_picker.num_pickers` will be cleared. + Default: 1 + - limit_entries: The amount of entries that will be saved for + each picker. + Default: 1000 + - ignore_empty_prompt: If true, the picker will not be cached if + the prompt is empty (i.e., no text has been + typed at the time of closing the prompt). + Default: false ]] ) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index f7d79f9..dc0b91d 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -1582,11 +1582,16 @@ function pickers.on_close_prompt(prompt_bufnr) picker.manager = EntryManager:new(picker.max_results, picker.entry_adder, picker.stats) end end - picker.default_text = picker:_get_prompt() + local curr_prompt = picker:_get_prompt() + picker.default_text = curr_prompt picker.cache_picker.selection_row = picker._selection_row - picker.cache_picker.cached_prompt = picker:_get_prompt() - picker.cache_picker.is_cached = true - table.insert(cached_pickers, 1, picker) + + -- Only cache if prompt is not empty or ignore_empty_prompt is false + if not picker.cache_picker.ignore_empty_prompt or (curr_prompt and curr_prompt ~= "") then + picker.cache_picker.cached_prompt = curr_prompt + table.insert(cached_pickers, 1, picker) + picker.cache_picker.is_cached = true + end -- release pickers if picker.cache_picker.num_pickers > 0 then