Skip to content

Commit

Permalink
fix(current_buffer_fuzzy_find): error on select (#2942)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamestrew authored Feb 24, 2024
1 parent a5b69af commit 12e42a3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 12e42a3

Please sign in to comment.