@@ -181,7 +181,6 @@ function Picker:is_done()
181181 end
182182end
183183
184- -- TODO(scroll)
185184function Picker :clear_extra_rows (results_bufnr )
186185 if self :is_done () then
187186 log .trace " Not clearing due to being already complete"
@@ -214,7 +213,7 @@ function Picker:clear_extra_rows(results_bufnr)
214213 end
215214
216215 if not ok then
217- log .debug (msg )
216+ log .debug (" Failed to set lines: " , msg )
218217 end
219218
220219 log .trace (" Clearing:" , worst_line )
@@ -268,8 +267,6 @@ function Picker:_next_find_id()
268267end
269268
270269function Picker :find ()
271- self .result_limit = 100000
272-
273270 self :close_existing_pickers ()
274271 self :reset_selection ()
275272
@@ -344,17 +341,14 @@ function Picker:find()
344341 self .prompt_prefix = prompt_prefix
345342 self :_reset_prefix_color ()
346343
347- -- First thing we want to do is set all the lines to blank.
348- self .max_results = 10000 or popup_opts .results .height
344+ -- TODO: This could be configurable in the future, but I don't know why you would
345+ -- want to scroll through more than 10,000 items.
346+ --
347+ -- This just lets us stop doing stuff after tons of things.
348+ self .max_results = 10000
349349
350- -- TODO(scrolling): This may be a hack when we get a little further into implementing scrolling.
351350 vim .api .nvim_buf_set_lines (results_bufnr , 0 , self .max_results , false , utils .repeated_table (self .max_results , " " ))
352351
353- -- TODO(status): I would love to get the status text not moving back and forth. Perhaps it is just a problem with
354- -- virtual text & prompt buffers or something though. I can't figure out why it would redraw the way it does.
355- --
356- -- A "hacked" version of this would be to calculate where the area I want the status to go and put a new window there.
357- -- With this method, I do not need to worry about padding or antying, just make it take up X characters or something.
358352 local status_updater = self :get_status_updater (prompt_win , prompt_bufnr )
359353 local debounced_status = debounce .throttle_leading (status_updater , 50 )
360354
@@ -440,7 +434,7 @@ function Picker:find()
440434 find_id = self :_next_find_id ()
441435
442436 status_updater { completed = false }
443- tx . send (... )
437+ self . _on_lines (... )
444438 end ,
445439
446440 on_detach = function ()
@@ -883,44 +877,41 @@ function Picker:entry_adder(index, entry, _, insert)
883877
884878 self :_increment " displayed"
885879
886- -- TODO: Don't need to schedule this if we schedule the adder.
887880 local offset = insert and 0 or 1
888- vim .schedule (function ()
889- if not vim .api .nvim_buf_is_valid (self .results_bufnr ) then
890- log .debug " ON_ENTRY: Invalid buffer"
891- return
892- end
881+ if not vim .api .nvim_buf_is_valid (self .results_bufnr ) then
882+ log .debug " ON_ENTRY: Invalid buffer"
883+ return
884+ end
893885
894- -- TODO: Does this every get called?
895- -- local line_count = vim.api.nvim_win_get_height(self.results_win)
896- local line_count = vim .api .nvim_buf_line_count (self .results_bufnr )
897- if row > line_count then
898- return
899- end
886+ -- TODO: Does this every get called?
887+ -- local line_count = vim.api.nvim_win_get_height(self.results_win)
888+ local line_count = vim .api .nvim_buf_line_count (self .results_bufnr )
889+ if row > line_count then
890+ return
891+ end
900892
901- if insert then
902- if self .sorting_strategy == " descending" then
903- vim .api .nvim_buf_set_lines (self .results_bufnr , 0 , 1 , false , {})
904- end
893+ if insert then
894+ if self .sorting_strategy == " descending" then
895+ vim .api .nvim_buf_set_lines (self .results_bufnr , 0 , 1 , false , {})
905896 end
897+ end
906898
907- local set_ok , msg = pcall (vim .api .nvim_buf_set_lines , self .results_bufnr , row , row + offset , false , { display })
908- if set_ok and display_highlights then
909- self .highlighter :hi_display (row , prefix , display_highlights )
910- self :highlight_one_row (self .results_bufnr , self :_get_prompt (), display , row )
911- end
899+ local set_ok , msg = pcall (vim .api .nvim_buf_set_lines , self .results_bufnr , row , row + offset , false , { display })
900+ if set_ok and display_highlights then
901+ self .highlighter :hi_display (row , prefix , display_highlights )
902+ self :highlight_one_row (self .results_bufnr , self :_get_prompt (), display , row )
903+ end
912904
913- if not set_ok then
914- log .debug (" Failed to set lines..." , msg )
915- end
905+ if not set_ok then
906+ log .debug (" Failed to set lines..." , msg )
907+ end
916908
917- -- This pretty much only fails when people leave newlines in their results.
918- -- So we'll clean it up for them if it fails.
919- if not set_ok and display :find " \n " then
920- display = display :gsub (" \n " , " | " )
921- vim .api .nvim_buf_set_lines (self .results_bufnr , row , row + 1 , false , { display })
922- end
923- end )
909+ -- This pretty much only fails when people leave newlines in their results.
910+ -- So we'll clean it up for them if it fails.
911+ if not set_ok and display :find " \n " then
912+ display = display :gsub (" \n " , " | " )
913+ vim .api .nvim_buf_set_lines (self .results_bufnr , row , row + 1 , false , { display })
914+ end
924915end
925916
926917function Picker :_reset_track ()
@@ -991,17 +982,11 @@ function Picker:get_status_updater(prompt_win, prompt_bufnr)
991982end
992983
993984function Picker :get_result_processor (find_id , prompt , status_updater )
994- local stopped = false
995- local added = 0
985+ local count = 0
996986
997987 local cb_add = function (score , entry )
998988 self .manager :add_entry (self , score , entry )
999989 status_updater { completed = false }
1000-
1001- added = added + 1
1002- if added > self .result_limit then
1003- stopped = true
1004- end
1005990 end
1006991
1007992 local cb_filter = function (_ )
@@ -1013,16 +998,14 @@ function Picker:get_result_processor(find_id, prompt, status_updater)
1013998 return true
1014999 end
10151000
1016- if stopped then
1017- return true
1018- end
1019-
10201001 self :_increment " processed"
10211002
10221003 if not entry or entry .valid == false then
10231004 return
10241005 end
10251006
1007+ count = count + 1
1008+
10261009 -- TODO: Probably should asyncify this / cache this / do something because this probably takes
10271010 -- a ton of time on large results.
10281011 log .trace (" Processing result... " , entry )
@@ -1038,6 +1021,13 @@ function Picker:get_result_processor(find_id, prompt, status_updater)
10381021 end
10391022
10401023 self .sorter :score (prompt , entry , cb_add , cb_filter )
1024+
1025+ -- Only on the first addition do we want to set the selection.
1026+ -- This allows us to handle moving the cursor to the bottom or top of the window
1027+ -- depending on the strategy.
1028+ if count == 1 then
1029+ self :_do_selection (prompt )
1030+ end
10411031 end
10421032end
10431033
0 commit comments