diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2020-11-23 16:11:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-23 10:11:46 -0500 |
| commit | 863328a96d81d4b93bcfaa0038d429ea24880b0b (patch) | |
| tree | 4560fcbb47d2c084711d228f70ab58983182d874 /lua/telescope/pickers.lua | |
| parent | 2ac0582c06d8a52a42907dde106983e44ae989ef (diff) | |
feat: Buffers rework (indicators and sorting) (#208)
Diffstat (limited to 'lua/telescope/pickers.lua')
| -rw-r--r-- | lua/telescope/pickers.lua | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index adc2dca..b066bd6 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -79,6 +79,7 @@ function Picker:new(opts) finder = opts.finder, sorter = opts.sorter, previewer = opts.previewer, + default_selection_index = opts.default_selection_index, _completion_callbacks = {}, @@ -470,18 +471,30 @@ function Picker:find() -- TODO: We should either: always leave one result or make sure we actually clean up the results when nothing matches if selection_strategy == 'row' then - self:set_selection(self:get_selection_row()) + if self._selection_row == nil and self.default_selection_index ~= nil then + self:set_selection(self:get_row(self.default_selection_index)) + else + self:set_selection(self:get_selection_row()) + end elseif selection_strategy == 'follow' then - local index = self.manager:find_entry(self:get_selection()) - - if index then - local follow_row = self:get_row(index) - self:set_selection(follow_row) + if self._selection_row == nil and self.default_selection_index ~= nil then + self:set_selection(self:get_row(self.default_selection_index)) else - self:set_selection(self:get_reset_row()) + local index = self.manager:find_entry(self:get_selection()) + + if index then + local follow_row = self:get_row(index) + self:set_selection(follow_row) + else + self:set_selection(self:get_reset_row()) + end end elseif selection_strategy == 'reset' then - self:set_selection(self:get_reset_row()) + if self.default_selection_index ~= nil then + self:set_selection(self:get_row(self.default_selection_index)) + else + self:set_selection(self:get_reset_row()) + end else error('Unknown selection strategy: ' .. selection_strategy) end |
