feat(builtin.current_buffer_fuzzy_find): jump to first matched char (#2909)

* feat(builtin.current_buffer_fuzzy_find): jump to first matched char

* use highlighter to detect column to jump to

* replace default select

* handle non 0 based column index

* handle no highlight scenario

---------

Co-authored-by: James Trew <j.trew10@gmail.com>
This commit is contained in:
Anton Kastritskii
2024-02-15 02:01:13 +00:00
committed by GitHub
parent eb88dc6434
commit fac5da839e

View File

@@ -537,16 +537,22 @@ files.current_buffer_fuzzy_find = function(opts)
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
previewer = conf.grep_previewer(opts), previewer = conf.grep_previewer(opts),
attach_mappings = function() attach_mappings = function()
action_set.select:enhance { actions.select_default:replace(function(prompt_bufnr)
post = function()
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
if not selection then if not selection then
utils.__warn_no_selection "builtin.current_buffer_fuzzy_find"
return return
end 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)
local column = math.min(unpack(highlighted) or 1) - 1
vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 }) actions.close(prompt_bufnr)
end, vim.schedule(function()
} vim.api.nvim_win_set_cursor(0, { selection.lnum, column })
end)
end)
return true return true
end, end,