@@ -221,6 +221,10 @@ function Picker:clear_extra_rows(results_bufnr)
221221end
222222
223223function Picker :highlight_one_row (results_bufnr , prompt , display , row )
224+ if not self .sorter .highlighter then
225+ return
226+ end
227+
224228 local highlights = self .sorter :highlighter (prompt , display )
225229
226230 if highlights then
@@ -355,7 +359,7 @@ function Picker:find()
355359 local debounced_status = debounce .throttle_leading (status_updater , 50 )
356360
357361 local tx , rx = channel .mpsc ()
358- self .__on_lines = tx .send
362+ self ._on_lines = tx .send
359363
360364 local find_id = self :_next_find_id ()
361365
@@ -400,19 +404,7 @@ function Picker:find()
400404
401405 local start_time = vim .loop .hrtime ()
402406
403- local prompt = self :_get_prompt ()
404- local on_input_result = self ._on_input_filter_cb (prompt ) or {}
405-
406- local new_prompt = on_input_result .prompt
407- if new_prompt then
408- prompt = new_prompt
409- end
410-
411- local new_finder = on_input_result .updated_finder
412- if new_finder then
413- self .finder :close ()
414- self .finder = new_finder
415- end
407+ local prompt = self :_get_next_filtered_prompt ()
416408
417409 -- TODO: Entry manager should have a "bulk" setter. This can prevent a lot of redraws from display
418410 if self .cache_picker == false or not (self .cache_picker .is_cached == true ) then
@@ -436,25 +428,8 @@ function Picker:find()
436428 async .util .sleep (self .debounce - diff_time )
437429 end
438430 else
439- -- resume previous picker
440- local index = 1
441- for entry in self .manager :iter () do
442- self :entry_adder (index , entry , _ , true )
443- index = index + 1
444- end
445- self .cache_picker .is_cached = false
446- -- if text changed, required to set anew to restart finder; otherwise hl and selection
447- if self .cache_picker .cached_prompt ~= self .default_text then
448- self :reset_prompt ()
449- self :set_prompt (self .default_text )
450- else
451- -- scheduling required to apply highlighting and selection appropriately
452- await_schedule (function ()
453- if self .cache_picker .selection_row ~= nil then
454- self :set_selection (self .cache_picker .selection_row )
455- end
456- end )
457- end
431+ -- TODO(scroll): This can only happen once, I don't like where it is.
432+ self :_resume_picker ()
458433 end
459434 end
460435 end )
@@ -464,10 +439,10 @@ function Picker:find()
464439 on_lines = function (...)
465440 find_id = self :_next_find_id ()
466441
467- self ._result_completed = false
468442 status_updater { completed = false }
469443 tx .send (... )
470444 end ,
445+
471446 on_detach = function ()
472447 self :_detach ()
473448 end ,
@@ -741,7 +716,7 @@ function Picker:refresh(finder, opts)
741716 self ._multi = MultiSelect :new ()
742717 end
743718
744- self .__on_lines (nil , nil , nil , 0 , 1 )
719+ self ._on_lines (nil , nil , nil , 0 , 1 )
745720end
746721
747722function Picker :set_selection (row )
@@ -1081,8 +1056,6 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda
10811056 self .sorter :_finish (prompt )
10821057
10831058 self :_on_complete ()
1084-
1085- self ._result_completed = true
10861059 end )
10871060end
10881061
@@ -1228,6 +1201,46 @@ function Picker:_detach()
12281201 self .closed = true
12291202end
12301203
1204+ function Picker :_get_next_filtered_prompt ()
1205+ local prompt = self :_get_prompt ()
1206+ local on_input_result = self ._on_input_filter_cb (prompt ) or {}
1207+
1208+ local new_prompt = on_input_result .prompt
1209+ if new_prompt then
1210+ prompt = new_prompt
1211+ end
1212+
1213+ local new_finder = on_input_result .updated_finder
1214+ if new_finder then
1215+ self .finder :close ()
1216+ self .finder = new_finder
1217+ end
1218+
1219+ return prompt
1220+ end
1221+
1222+ function Picker :_resume_picker ()
1223+ -- resume previous picker
1224+ local index = 1
1225+ for entry in self .manager :iter () do
1226+ self :entry_adder (index , entry , _ , true )
1227+ index = index + 1
1228+ end
1229+ self .cache_picker .is_cached = false
1230+ -- if text changed, required to set anew to restart finder; otherwise hl and selection
1231+ if self .cache_picker .cached_prompt ~= self .default_text then
1232+ self :reset_prompt ()
1233+ self :set_prompt (self .default_text )
1234+ else
1235+ -- scheduling required to apply highlighting and selection appropriately
1236+ await_schedule (function ()
1237+ if self .cache_picker .selection_row ~= nil then
1238+ self :set_selection (self .cache_picker .selection_row )
1239+ end
1240+ end )
1241+ end
1242+ end
1243+
12311244pickers ._Picker = Picker
12321245
12331246return pickers
0 commit comments