diff --git a/lua/telescope/actions/set.lua b/lua/telescope/actions/set.lua index 381f3c0..80c30f7 100644 --- a/lua/telescope/actions/set.lua +++ b/lua/telescope/actions/set.lua @@ -169,6 +169,8 @@ action_set.edit = function(prompt_bufnr, command) log.debug("Failed to move to cursor:", err_msg, row, col) end end + + vim.cmd [[stopinsert]] end --- Scrolls the previewer up or down. diff --git a/lua/telescope/algos/linked_list.lua b/lua/telescope/algos/linked_list.lua index 2da6a6e..360b01e 100644 --- a/lua/telescope/algos/linked_list.lua +++ b/lua/telescope/algos/linked_list.lua @@ -1,3 +1,6 @@ +-- TODO: I think it could be cool to set different functions depending on what configuration +-- you have (so for example, if you do not pass maxsize, we never check it) + local LinkedList = {} LinkedList.__index = LinkedList @@ -16,6 +19,17 @@ function LinkedList:new(opts) track_at = track_at, _tracked_node = nil, tracked = nil, + + -- maxsize + -- Use this to keep a limit on the nodes that we have. + -- It's possible that we will insert MORE than this for some circumstances, + -- so it's not a strict limit. But if something is appended after maxsize has + -- been met, then we will just drop the item + -- + -- We could fix that limitation by fixing all the other places, but my intuition + -- is that it doesn't matter because the large percentage of additions are just appends + -- (after the track at is passed) + maxsize = opts.maxsize, }, self) end @@ -31,6 +45,10 @@ local create_node = function(item) end function LinkedList:append(item) + if self.maxsize and self.maxsize <= self.size then + return + end + local final_size = self:_increment() local node = create_node(item) diff --git a/lua/telescope/entry_manager.lua b/lua/telescope/entry_manager.lua index fddadd4..14be7f6 100644 --- a/lua/telescope/entry_manager.lua +++ b/lua/telescope/entry_manager.lua @@ -3,13 +3,17 @@ local LinkedList = require "telescope.algos.linked_list" local EntryManager = {} EntryManager.__index = EntryManager -function EntryManager:new(num_sorted) - num_sorted = num_sorted or 500 +--- Create a new entry manager +---@param max_to_sort number: How many entries to keep sorted +---@param maxsize number: The "max" number of entries to store. +---@return table +function EntryManager:new(max_to_sort, maxsize) + max_to_sort = max_to_sort or 500 return setmetatable({ dirty = true, - linked_states = LinkedList:new { track_at = num_sorted }, - num_sorted = num_sorted, + linked_states = LinkedList:new { track_at = max_to_sort, maxsize = maxsize }, + max_to_sort = max_to_sort, worst_acceptable_score = math.huge, }, self) end @@ -84,7 +88,7 @@ end function EntryManager:add_entry(picker, score, entry, prompt) score = score or 0 - local num_sorted = self.num_sorted + local max_to_sort = self.max_to_sort local worst_score = self.worst_acceptable_score local size = self.linked_states.size @@ -114,12 +118,12 @@ function EntryManager:add_entry(picker, score, entry, prompt) end -- Don't add results that are too bad. - if index >= num_sorted then + if index >= max_to_sort then return self:_append_container(picker, new_container, false) end end - if self.linked_states.size >= num_sorted then + if self.linked_states.size >= max_to_sort then self.worst_acceptable_score = math.min(self.worst_acceptable_score, score) end diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 228dcb0..5b13c72 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -1,3 +1,9 @@ +-- REMOVED: +-- pickers.debouce, not sure if that was useful at all, +-- but I think it just provides weird contention. We're not going to debounce HANDLING +-- messages, we're only going to handle debouncing display + +-- TODO: use maxsize for linked list and then try to test that it's working require "telescope" local a = vim.api @@ -54,6 +60,7 @@ function Picker:new(opts) error "layout_strategy and get_window_options are not compatible keys" end + -- TODO: Seems like we could remove this but just set some other window to be the original window if vim.fn.win_gettype() == "command" then error "Can't open telescope from command-line window. See E11" end @@ -71,24 +78,25 @@ function Picker:new(opts) local layout_strategy = get_default(opts.layout_strategy, config.values.layout_strategy) local obj = setmetatable({ + finder = assert(opts.finder, "Finder is required."), + sorter = opts.sorter or require("telescope.sorters").empty(), + prompt_title = get_default(opts.prompt_title, config.values.prompt_title), results_title = get_default(opts.results_title, config.values.results_title), -- either whats passed in by the user or whats defined by the previewer preview_title = opts.preview_title, + -- TODO: Delete this, this should be able to be configured by user. wrap_results = get_default(opts.wrap_results, config.values.wrap_results), initial_mode = get_default(opts.initial_mode, config.values.initial_mode), - _original_mode = vim.api.nvim_get_mode().mode, - debounce = get_default(tonumber(opts.debounce), nil), + _original_mode = a.nvim_get_mode().mode, default_text = opts.default_text, get_status_text = get_default(opts.get_status_text, config.values.get_status_text), _on_input_filter_cb = opts.on_input_filter_cb or function() end, - finder = assert(opts.finder, "Finder is required."), - sorter = opts.sorter or require("telescope.sorters").empty(), - + -- TODO: change to _all_previewers? all_previewers = opts.previewer, current_previewer_index = 1, @@ -100,7 +108,8 @@ function Picker:new(opts) _find_id = 0, _completion_callbacks = type(opts._completion_callbacks) == "table" and opts._completion_callbacks or {}, - -- manager = (type(opts.manager) == "table" and getmetatable(opts.manager) == EntryManager) and opts.manager, + + manager = (type(opts.manager) == "table" and getmetatable(opts.manager) == EntryManager) and opts.manager, _multi = (type(opts._multi) == "table" and getmetatable(opts._multi) == getmetatable(MultiSelect:new())) and opts._multi or MultiSelect:new(), @@ -112,10 +121,11 @@ function Picker:new(opts) file_ignore_patterns = get_default(opts.file_ignore_patterns, config.values.file_ignore_patterns), scroll_strategy = get_default(opts.scroll_strategy, config.values.scroll_strategy), + selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy), sorting_strategy = get_default(opts.sorting_strategy, config.values.sorting_strategy), tiebreak = get_default(opts.tiebreak, config.values.tiebreak), - selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy), + -- TODO: This is another example of something I'd rather see we do via functions push_cursor_on_edit = get_default(opts.push_cursor_on_edit, false), push_tagstack_on_edit = get_default(opts.push_tagstack_on_edit, false), @@ -125,10 +135,16 @@ function Picker:new(opts) __cycle_layout_list = get_default(opts.cycle_layout_list, config.values.cycle_layout_list), window = { + -- TODO: Winblend is also a bad idea. We can do this either through ftplugin or `on_window` function / list of + -- functions. For example { telescope.set.winblend(0), telescope.set.wrap(true), ... } or similar. + -- + -- We should have less of these functions winblend = get_default( opts.winblend, type(opts.window) == "table" and opts.window.winblend or config.values.winblend ), + + -- Border seems to make sense though, since that's not like a "builtin" thing border = get_default(opts.border, type(opts.window) == "table" and opts.window.border or config.values.border), borderchars = get_default( opts.borderchars, @@ -161,6 +177,7 @@ function Picker:new(opts) obj.get_window_options = opts.get_window_options or p_window.get_window_options + -- TODO: previwer.resolve(...) or something maybe. if obj.all_previewers ~= nil and obj.all_previewers ~= false then if obj.all_previewers[1] == nil then obj.all_previewers = { obj.all_previewers } @@ -175,6 +192,7 @@ function Picker:new(opts) obj.previewer = false end + -- TODO: This seems out of place as well. local __hide_previewer = opts.__hide_previewer if __hide_previewer then obj.hidden_previewer = obj.previewer @@ -186,10 +204,8 @@ function Picker:new(opts) obj.scroller = require("telescope.pickers.scroller").new(obj.scroll_strategy, obj.sorting_strategy) obj.highlighter = require("telescope.pickers.highlights").new(obj) - if opts.on_complete then - for _, on_complete_item in ipairs(opts.on_complete) do - obj:register_completion_callback(on_complete_item) - end + for _, on_complete_item in ipairs(opts.on_complete or {}) do + obj:register_completion_callback(on_complete_item) end return obj @@ -261,7 +277,7 @@ end --- A helper function for creating each of the windows in a picker ---@param bufnr number: the buffer number to be used in the window ---@param popup_opts table: options to pass to `popup.create` ----@param nowrap boolean: is |'wrap'| disabled in the created window +---@param nowrap boolean|nil: is |'wrap'| disabled in the created window function Picker:_create_window(bufnr, popup_opts, nowrap) local what = bufnr or "" local win, opts = popup.create(what, popup_opts) @@ -284,7 +300,7 @@ function Picker:find() self.original_win_id = a.nvim_get_current_win() -- User autocmd run it before create Telescope window - vim.api.nvim_exec_autocmds("User TelescopeFindPre", {}) + a.nvim_exec_autocmds("User TelescopeFindPre", {}) -- Create three windows: -- 1. Prompt window @@ -296,23 +312,7 @@ function Picker:find() line_count = line_count - 1 end - local popup_opts = self:get_window_options(vim.o.columns, line_count) - - -- `popup.nvim` massaging so people don't have to remember minheight shenanigans - popup_opts.results.minheight = popup_opts.results.height - popup_opts.results.highlight = "TelescopeResultsNormal" - popup_opts.results.borderhighlight = "TelescopeResultsBorder" - popup_opts.results.titlehighlight = "TelescopeResultsTitle" - popup_opts.prompt.minheight = popup_opts.prompt.height - popup_opts.prompt.highlight = "TelescopePromptNormal" - popup_opts.prompt.borderhighlight = "TelescopePromptBorder" - popup_opts.prompt.titlehighlight = "TelescopePromptTitle" - if popup_opts.preview then - popup_opts.preview.minheight = popup_opts.preview.height - popup_opts.preview.highlight = "TelescopePreviewNormal" - popup_opts.preview.borderhighlight = "TelescopePreviewBorder" - popup_opts.preview.titlehighlight = "TelescopePreviewTitle" - end + local popup_opts = p_window._set_additional_fields(self:get_window_options(vim.o.columns, line_count)) local results_win, results_opts, results_border_win = self:_create_window( "", @@ -358,7 +358,7 @@ function Picker:find() -- -- This just lets us stop doing stuff after tons of things. -- self.max_results = 1000 -- - -- vim.api.nvim_buf_set_lines(results_bufnr, 0, self.max_results, false, utils.repeated_table(self.max_results, "")) + -- a.nvim_buf_set_lines(results_bufnr, 0, self.max_results, false, utils.repeated_table(self.max_results, "")) -- -- local status_updater = self:get_status_updater(prompt_win, prompt_bufnr) -- local debounced_status = debounce.throttle_leading(status_updater, 50) @@ -406,7 +406,7 @@ function Picker:find() -- -- self:_reset_track() -- - -- if not vim.api.nvim_buf_is_valid(prompt_bufnr) then + -- if not a.nvim_buf_is_valid(prompt_bufnr) then -- log.debug("ON_LINES: Invalid prompt_bufnr", prompt_bufnr) -- return -- end @@ -444,8 +444,9 @@ function Picker:find() -- self:set_promptprefix(self.prompt_prefix) -- -- -- TODO: Probably should reset self.offset and what not when you type new keys?... hadn't thought about that before - -- self.offset = 0 - -- self.num_visible = popup_opts.results.height + + self.offset = 0 + self.num_visible = popup_opts.results.height local status_updater = function(opts) return self:_update_status(opts) @@ -457,10 +458,11 @@ function Picker:find() self:_redraw { do_selection = true, force = true } end) - local rx - self._tx, rx = channel.mpsc() + local tx, rx = channel.mpsc() + self._tx = tx + -- Register attach - vim.api.nvim_buf_attach(prompt_bufnr, false, { + a.nvim_buf_attach(prompt_bufnr, false, { on_lines = function() find_id = self:_next_find_id() @@ -479,20 +481,19 @@ function Picker:find() end, }) - vim.api.nvim_create_augroup("PickerInsert", {}) - -- TODO: Use WinLeave as well? - vim.api.nvim_create_autocmd("BufLeave", { + local au_picker = a.nvim_create_augroup("PickerInsert", { clear = true }) + a.nvim_create_autocmd("BufLeave", { buffer = prompt_bufnr, - group = "PickerInsert", + group = au_picker, nested = true, once = true, callback = function() require("telescope.pickers").on_close_prompt(prompt_bufnr) end, }) - vim.api.nvim_create_autocmd("VimResized", { + a.nvim_create_autocmd("VimResized", { buffer = prompt_bufnr, - group = "PickerInsert", + group = au_picker, nested = true, once = true, callback = function() @@ -552,18 +553,26 @@ function Picker:find() -- await_schedule() + local count = 0 while true do - -- Wait for the next input - rx.last() + -- Try to display as fast as possible, don't wait on the first iteration + -- This ensures that we try to display as fast as possible + if count > 0 then + -- Wait for the next input + rx.last() + end + + count = count + 1 + + -- We want to be able to do nvim things, so wait here. await_schedule() self:_reset_track() - if not vim.api.nvim_buf_is_valid(prompt_bufnr) then + if not a.nvim_buf_is_valid(prompt_bufnr) then return end - local start_time = vim.loop.hrtime() local prompt = self:_get_next_filtered_prompt() if self.cache_picker == false or not (self.cache_picker.is_cached == true) then @@ -582,13 +591,6 @@ function Picker:find() if not ok then log.warn("Finder failed with msg: ", msg) end - - local diff_time = (vim.loop.hrtime() - start_time) / 1e6 - if self.debounce and diff_time < self.debounce then - self._sleeping = true - async.util.sleep(self.debounce - diff_time) - self._sleeping = false - end else -- TODO(scroll): This can only happen once, I don't like where it is. self:_resume_picker() @@ -630,7 +632,7 @@ function Picker:recalculate_layout() popup_opts.preview.borderhighlight = "TelescopePreviewBorder" popup_opts.preview.titlehighlight = "TelescopePreviewTitle" local preview_bufnr = status.preview_bufnr ~= nil - and vim.api.nvim_buf_is_valid(status.preview_bufnr) + and a.nvim_buf_is_valid(status.preview_bufnr) and status.preview_bufnr or "" preview_win, preview_opts, preview_border_win = self:_create_window(preview_bufnr, popup_opts.preview) @@ -679,13 +681,13 @@ end local update_scroll = function(win, oldinfo, oldcursor, strategy, buf_maxline) if strategy == "ascending" then - vim.api.nvim_win_set_cursor(win, { buf_maxline, 0 }) - vim.api.nvim_win_set_cursor(win, { oldinfo.topline, 0 }) - vim.api.nvim_win_set_cursor(win, oldcursor) + a.nvim_win_set_cursor(win, { buf_maxline, 0 }) + a.nvim_win_set_cursor(win, { oldinfo.topline, 0 }) + a.nvim_win_set_cursor(win, oldcursor) elseif strategy == "descending" then - vim.api.nvim_win_set_cursor(win, { 1, 0 }) - vim.api.nvim_win_set_cursor(win, { oldinfo.botline, 0 }) - vim.api.nvim_win_set_cursor(win, oldcursor) + a.nvim_win_set_cursor(win, { 1, 0 }) + a.nvim_win_set_cursor(win, { oldinfo.botline, 0 }) + a.nvim_win_set_cursor(win, oldcursor) else error(debug.traceback("Unknown sorting strategy: " .. (strategy or ""))) end @@ -694,12 +696,12 @@ end --- A wrapper for `Picker:recalculate_layout()` that also handles maintaining cursor position function Picker:full_layout_update() local oldinfo = vim.fn.getwininfo(self.results_win)[1] - local oldcursor = vim.api.nvim_win_get_cursor(self.results_win) + local oldcursor = a.nvim_win_get_cursor(self.results_win) self:recalculate_layout() self:refresh_previewer() -- update scrolled position - local buf_maxline = #vim.api.nvim_buf_get_lines(self.results_bufnr, 0, -1, false) + local buf_maxline = #a.nvim_buf_get_lines(self.results_bufnr, 0, -1, false) -- update_scroll(self.results_win, oldinfo, oldcursor, self.sorting_strategy, buf_maxline) end @@ -761,11 +763,6 @@ function Picker:delete_selection(delete_cb) end, 50) end --- TODO: rebase -function Picker:set_prompt(text) - self:reset_prompt(text) -end - function Picker:set_promptprefix(str) self.prompt_prefix = str if self.prompt_prefix ~= "" then @@ -774,18 +771,23 @@ function Picker:set_promptprefix(str) else a.nvim_buf_set_option(self.prompt_bufnr, "buftype", "") -- TODO: Decide this - -- vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { self.default_text }) + -- a.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { self.default_text }) end end +-- TODO: rebase +function Picker:set_prompt(text) + self:reset_prompt(text) +end + function Picker:set_prompt(str) - vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { "" }) - vim.api.nvim_feedkeys(str, "n", false) + a.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { "" }) + a.nvim_feedkeys(str, "n", false) self:_reset_prefix_color() -- TODO(conni2461): As soon as prompt_buffers are fix use this: - -- vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { "" }) - -- vim.api.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, 0, { str }) + -- a.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { "" }) + -- a.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, 0, { str }) end --- Closes the windows for the prompt, results and preview @@ -800,7 +802,7 @@ function Picker.close_windows(status) utils.win_delete("preview_border_win", status.preview_border_win, true, true) -- we cant use win_delete. We first need to close and then delete the buffer - vim.api.nvim_win_close(status.prompt_win, true) + a.nvim_win_close(status.prompt_win, true) utils.buf_delete(status.prompt_bufnr) state.clear_status(status.prompt_bufnr) @@ -847,7 +849,6 @@ function Picker:shift_offset(change) self.offset = math.max(self.offset, 0) self:_redraw { force = true } ->>>>>>> 20a1519 (feat(fps): Add refresh style display for telescope) end --- Move the current selection by `change` steps @@ -994,7 +995,7 @@ function Picker:_reset_prefix_color(hl_group) self._current_prefix_hl_group = hl_group or nil if self.prompt_prefix ~= "" then - vim.api.nvim_buf_add_highlight( + a.nvim_buf_add_highlight( self.prompt_bufnr, ns_telescope_prompt_prefix, self._current_prefix_hl_group or "TelescopePromptPrefix", @@ -1019,8 +1020,8 @@ function Picker:change_prompt_prefix(new_prefix, hl_group) if new_prefix ~= "" then vim.fn.prompt_setprompt(self.prompt_bufnr, new_prefix) else - vim.api.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, self._prefix_width, {}) - vim.api.nvim_buf_set_option(self.prompt_bufnr, "buftype", "") + a.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, self._prefix_width, {}) + a.nvim_buf_set_option(self.prompt_bufnr, "buftype", "") end self.prompt_prefix = new_prefix self:_reset_prefix_color(hl_group) @@ -1030,11 +1031,11 @@ end ---@param text string function Picker:reset_prompt(text) local prompt_text = self.prompt_prefix .. (text or "") - vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { prompt_text }) + a.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { prompt_text }) self:_reset_prefix_color(self._current_prefix_hl_group) if text then - -- vim.api.nvim_win_set_cursor(self.prompt_win, { 1, #prompt_text }) + -- a.nvim_win_set_cursor(self.prompt_win, { 1, #prompt_text }) end end @@ -1090,7 +1091,7 @@ function Picker:set_selection(row) if not self:can_select_row(self:get_selection_row()) then row = self:get_row(self.manager:num_results()) else - error(string.format("Cannot select row: %s %s %s", row, self.manager:num_results(), self.num_visible)) + -- error(string.format("Cannot select row: %s %s %s", row, self.manager:num_results(), self.num_visible)) return end end @@ -1276,9 +1277,9 @@ Picker._redraw = vim.schedule_wrap(function(self, opts) -- self:_do_selection(prompt) end - -- vim.api.nvim_win_set_cursor + -- a.nvim_win_set_cursor -- print("Setting win cursor", self:get_selection_row() + 1) - -- vim.api.nvim_win_set_cursor(self.results_win, { self:get_selection_row() + 1, 0 }) + -- a.nvim_win_set_cursor(self.results_win, { self:get_selection_row() + 1, 0 }) end) local get_displayed_and_highlights = function(self, window) @@ -1317,7 +1318,7 @@ function Picker:_update_results(opts) opts = opts or {} -- Dimensions - local height = vim.api.nvim_win_get_height(self.results_win) + local height = a.nvim_win_get_height(self.results_win) local window = self.manager:window(1 + self.offset, self.num_visible + self.offset) -- Get the contents to display and associated highlights @@ -1330,7 +1331,7 @@ function Picker:_update_results(opts) end -- Display contents - vim.api.nvim_buf_set_lines(self.results_bufnr, 0, -1, false, lines) + a.nvim_buf_set_lines(self.results_bufnr, 0, -1, false, lines) return displayed, highlights end @@ -1341,7 +1342,7 @@ function Picker:_update_status(opts) local prompt_win = self.prompt_win local prompt_bufnr = self.prompt_bufnr - if self.closed or not vim.api.nvim_buf_is_valid(prompt_bufnr) then + if self.closed or not a.nvim_buf_is_valid(prompt_bufnr) then return end @@ -1350,13 +1351,13 @@ function Picker:_update_status(opts) return end - if not vim.api.nvim_win_is_valid(prompt_win) then + if not a.nvim_win_is_valid(prompt_win) then return end local text = self:get_status_text(opts) - vim.api.nvim_buf_clear_namespace(prompt_bufnr, ns_telescope_prompt, 0, -1) - vim.api.nvim_buf_set_extmark(prompt_bufnr, ns_telescope_prompt, 0, 0, { + a.nvim_buf_clear_namespace(prompt_bufnr, ns_telescope_prompt, 0, -1) + a.nvim_buf_set_extmark(prompt_bufnr, ns_telescope_prompt, 0, 0, { virt_text = { { text, "TelescopePromptCounter" } }, virt_text_pos = "right_align", }) @@ -1584,7 +1585,7 @@ function pickers.on_close_prompt(prompt_bufnr) end -- so we dont call close_windows multiple times we clear that autocmd - vim.api.nvim_clear_autocmds { + a.nvim_clear_autocmds { group = "PickerInsert", event = "BufLeave", buffer = prompt_bufnr, @@ -1602,7 +1603,7 @@ end --- Get the prompt text without the prompt prefix. function Picker:_get_prompt() - return vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]:sub(#self.prompt_prefix + 1) + return a.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]:sub(#self.prompt_prefix + 1) end function Picker:_detach() diff --git a/lua/telescope/pickers/prompt.lua b/lua/telescope/pickers/prompt.lua index 097489e..d98958a 100644 --- a/lua/telescope/pickers/prompt.lua +++ b/lua/telescope/pickers/prompt.lua @@ -1,6 +1,6 @@ local M = {} -M.set_prompt = function(picker) +M.set_prompt = function(self) self._current_prefix_hl_group = hl_group or nil if self.prompt_prefix ~= "" then diff --git a/lua/telescope/pickers/selector.lua b/lua/telescope/pickers/selector.lua new file mode 100644 index 0000000..a4ad5eb --- /dev/null +++ b/lua/telescope/pickers/selector.lua @@ -0,0 +1,29 @@ +local selector = {} + +local state = { + None = 0, + Some = 1, +} + +---@class Selection +---@field state number: The current state (None or Some) +---@field row number: The selected row +---@field entry table: The selected entry +local Selection = {} +Selection.__index = Selection + +function Selection:none() + return setmetatable({ state = state.None }, Selection) +end + +function Selection:some(row, entry) + return setmetatable({ state = state.Some, row = row, entry = entry }, Selection) +end + +--- Reset the selection of the picker +---@param picker Picker +selector.reset = function(picker) + picker._selection = Selection:some() +end + +return selector diff --git a/lua/telescope/pickers/window.lua b/lua/telescope/pickers/window.lua index 945a7e3..267f25b 100644 --- a/lua/telescope/pickers/window.lua +++ b/lua/telescope/pickers/window.lua @@ -13,6 +13,26 @@ function p_window.get_window_options(picker, max_columns, max_lines) return getter(picker, max_columns, max_lines) end +function p_window._set_additional_fields(popup_opts) + -- `popup.nvim` massaging so people don't have to remember minheight shenanigans + popup_opts.results.minheight = popup_opts.results.height + popup_opts.results.highlight = "TelescopeResultsNormal" + popup_opts.results.borderhighlight = "TelescopeResultsBorder" + popup_opts.results.titlehighlight = "TelescopeResultsTitle" + popup_opts.prompt.minheight = popup_opts.prompt.height + popup_opts.prompt.highlight = "TelescopePromptNormal" + popup_opts.prompt.borderhighlight = "TelescopePromptBorder" + popup_opts.prompt.titlehighlight = "TelescopePromptTitle" + if popup_opts.preview then + popup_opts.preview.minheight = popup_opts.preview.height + popup_opts.preview.highlight = "TelescopePreviewNormal" + popup_opts.preview.borderhighlight = "TelescopePreviewBorder" + popup_opts.preview.titlehighlight = "TelescopePreviewTitle" + end + + return popup_opts +end + function p_window.get_initial_window_options(picker) local popup_border = resolve.win_option(picker.window.border) local popup_borderchars = resolve.win_option(picker.window.borderchars) diff --git a/lua/tests/automated/linked_list_spec.lua b/lua/tests/automated/linked_list_spec.lua index bc17ba1..0a7256f 100644 --- a/lua/tests/automated/linked_list_spec.lua +++ b/lua/tests/automated/linked_list_spec.lua @@ -129,5 +129,15 @@ describe("LinkedList", function() assert.are.same("first", l.tracked) end) + + it("should discard appends after maxsize has passed", function() + local l = LinkedList:new { maxsize = 2 } + l:append(1) + l:append(2) + l:append(3) + l:append(4) + + assert.are.same(2, l.size) + end) end) end)