@@ -10,6 +10,22 @@ local detailed_extmark_opts = { limit = 4, type = "highlight", details = true, h
1010local padding = { " " , " SelectHeaderPadding" }
1111local spacing = { " ," , " SelectHeaderDelimiter" }
1212
13+ local PREVIEW_EVENTIGNORE = table.concat ({
14+ " FileType" ,
15+ " BufEnter" ,
16+ " BufLeave" ,
17+ " BufWinEnter" ,
18+ " BufWinLeave" ,
19+ " WinEnter" ,
20+ " WinLeave" ,
21+ " WinNew" ,
22+ " WinClosed" ,
23+ " CursorMoved" ,
24+ " CursorMovedI" ,
25+ " CursorHold" ,
26+ " CursorHoldI" ,
27+ }, " ," )
28+
1329local utils = require (" fuzzy.utils" )
1430local Async = require (" fuzzy.async" )
1531local Worker = require (" fuzzy.worker" )
@@ -850,7 +866,7 @@ local function display_default(content, window, buffer)
850866 end
851867 if buffer ~= nil and vim .api .nvim_buf_is_valid (buffer ) then
852868 local old_ignore = vim .o .eventignore
853- vim .o .eventignore = " all "
869+ vim .o .eventignore = PREVIEW_EVENTIGNORE
854870 pcall (populate_buffer , buffer , content )
855871 vim .api .nvim_win_set_buf (window , buffer )
856872 vim .api .nvim_win_set_cursor (window , { 1 , 0 })
@@ -868,7 +884,7 @@ local function display_entry(previewer, entry, window, buffer)
868884 return
869885 end
870886 local old_ignore = vim .o .eventignore
871- vim .o .eventignore = " all "
887+ vim .o .eventignore = PREVIEW_EVENTIGNORE
872888 local ok , res , msg = pcall (previewer .preview , previewer , entry , window )
873889 if not ok then
874890 display_default ({ res or msg or " Unable to preview current entry" }, window , buffer )
@@ -2409,15 +2425,17 @@ end
24092425--- Checks if the selection interface is currently open, this is determined by checking if both the prompt and list windows are valid.
24102426--- @return boolean True if the selection interface is open , false otherwise.
24112427function Select :isopen ()
2412- local prompt = self .prompt_window and vim .api .nvim_win_is_valid (self .prompt_window )
2428+ local prompt = not (self ._options .prompt_input ~= false )
2429+ or (self .prompt_window and vim .api .nvim_win_is_valid (self .prompt_window ))
24132430 local list = self .list_window and vim .api .nvim_win_is_valid (self .list_window )
24142431 return list ~= nil and prompt ~= nil and list and prompt
24152432end
24162433
24172434--- Checks if the selection interface is valid, meaning that it has been initialized/opened at least once and has not been destroyed by calling the `close` method which would invalidate its curent state
24182435--- @return boolean True if the select interface is still valid , false otherwise.
24192436function Select :isvalid ()
2420- local prompt = self .prompt_buffer and vim .api .nvim_buf_is_valid (self .prompt_buffer )
2437+ local prompt = not (self ._options .prompt_input ~= false )
2438+ or (self .prompt_buffer and vim .api .nvim_buf_is_valid (self .prompt_buffer ))
24212439 local list = self .list_buffer and vim .api .nvim_buf_is_valid (self .list_buffer )
24222440 return list ~= nil and prompt ~= nil and list and prompt
24232441end
@@ -2468,6 +2486,9 @@ function Select:list(entries, positions)
24682486 self ._state .positions = positions
24692487 self ._state .entries = entries
24702488 self ._state .streaming = true
2489+ if not self :isvalid () then
2490+ return
2491+ end
24712492 self :_render_list ()
24722493 elseif positions == nil then
24732494 self ._state .streaming = false
@@ -2573,8 +2594,14 @@ function Select:open()
25732594 end
25742595
25752596 if not self ._state .renderer then
2597+ -- every select has a stateful renderer, in this case this rednerer worker ensures that only the last render job that is
2598+ -- queried is run, that makes sure that intermediate render jobs that would otherwise be overridden immediately by new
2599+ -- ones are discarded. This is the worker.coalesce job type
25762600 self ._state .renderer = Worker .coalesce ()
25772601 end
2602+
2603+ -- the source window has to be remembered, that source windo is the source from which the selection interface was initiated,
2604+ -- that is then later used for a target for future select actions that are performed by the interface
25782605 self .source_window = vim .api .nvim_get_current_win ()
25792606 local factor = (opts .prompt_list and opts .preview ) and 2.0 or 1.0
25802607 local size = compute_height (opts .window_ratio , factor )
@@ -2596,7 +2623,7 @@ function Select:open()
25962623 if self ._state .query ~= query then
25972624 self :_prompt_input (query , opts .prompt_input )
25982625 if query == nil then self :close () end
2599- self ._state .query = query
2626+ self ._state .query = query or " "
26002627 end
26012628 end
26022629 })
@@ -2740,7 +2767,7 @@ function Select:open()
27402767 pattern = " *" ,
27412768 callback = function ()
27422769 if vim .tbl_contains (vim .v .event .windows , self .list_window ) and
2743- not self :_is_rendering () and vim .api .nvim_buf_line_count (list_buffer ) >= 1
2770+ self :isvalid () and vim .api .nvim_buf_line_count (list_buffer ) >= 1
27442771 then
27452772 utils .timed_call (Select ._render_list , self , false )
27462773 end
0 commit comments