From 12e42a36254c4d7e2111c623a56e3c2f05847cdf Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:08:59 -0500 Subject: [PATCH] fix(current_buffer_fuzzy_find): error on select (#2942) Previous implementation of placing the cursor on the first column of the highlight failed to take into account that the highlighter can return more than one data structure. --- lua/telescope/builtin/__files.lua | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lua/telescope/builtin/__files.lua b/lua/telescope/builtin/__files.lua index 0d55ee0..878768f 100644 --- a/lua/telescope/builtin/__files.lua +++ b/lua/telescope/builtin/__files.lua @@ -545,23 +545,26 @@ files.current_buffer_fuzzy_find = function(opts) end local current_picker = action_state.get_current_picker(prompt_bufnr) local searched_for = require("telescope.actions.state").get_current_line() - local highlighted = current_picker.sorter:highlighter(searched_for, selection.ordinal) - highlighted = highlighted or {} - local column = highlighted[1] - for _, v in ipairs(highlighted) do - if v < column then - column = v + + ---@type number[] | {start:number, end:number?, highlight:string?}[] + local highlights = current_picker.sorter:highlighter(searched_for, selection.ordinal) or {} + highlights = vim.tbl_map(function(hl) + if type(hl) == "table" and hl.start then + return hl.start + elseif type(hl) == "number" then + return hl end - end - if column then - column = column - 1 - else - column = 0 + error "Invalid higlighter fn" + end, highlights) + + local first_col = 0 + if #highlights > 0 then + first_col = math.min(unpack(highlights)) - 1 end actions.close(prompt_bufnr) vim.schedule(function() - vim.api.nvim_win_set_cursor(0, { selection.lnum, column }) + vim.api.nvim_win_set_cursor(0, { selection.lnum, first_col }) end) end)