From fac5da839e23e7a4c17a332a640541cd59ebfbd5 Mon Sep 17 00:00:00 2001 From: Anton Kastritskii Date: Thu, 15 Feb 2024 02:01:13 +0000 Subject: [PATCH] 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 --- lua/telescope/builtin/__files.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lua/telescope/builtin/__files.lua b/lua/telescope/builtin/__files.lua index 5071374..26d46bf 100644 --- a/lua/telescope/builtin/__files.lua +++ b/lua/telescope/builtin/__files.lua @@ -537,16 +537,22 @@ files.current_buffer_fuzzy_find = function(opts) sorter = conf.generic_sorter(opts), previewer = conf.grep_previewer(opts), attach_mappings = function() - action_set.select:enhance { - post = function() - local selection = action_state.get_selected_entry() - if not selection then - return - end + actions.select_default:replace(function(prompt_bufnr) + local selection = action_state.get_selected_entry() + if not selection then + utils.__warn_no_selection "builtin.current_buffer_fuzzy_find" + return + 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 }) - end, - } + actions.close(prompt_bufnr) + vim.schedule(function() + vim.api.nvim_win_set_cursor(0, { selection.lnum, column }) + end) + end) return true end,