feat: current buffer fuzzy find improvements (#694)

If you don't want to have a previewer disable it with `:Telescope current_buffer_fuzzy_find previewer=false`
To ignore empty lines do: `:Telescope current_buffer_fuzzy_find skip_empty_lines=true`
This commit is contained in:
August Masquelier
2021-04-04 05:04:06 -06:00
committed by GitHub
parent 0944c4a88f
commit d0cf646f65
2 changed files with 47 additions and 14 deletions

View File

@@ -329,34 +329,35 @@ files.treesitter = function(opts)
end
files.current_buffer_fuzzy_find = function(opts)
-- All actions are on the current buffer
local bufnr = vim.api.nvim_get_current_buf()
local filename = vim.fn.expand(vim.api.nvim_buf_get_name(bufnr))
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local lines_with_numbers = {}
for k, v in ipairs(lines) do
table.insert(lines_with_numbers, {k, v})
end
local bufnr = vim.api.nvim_get_current_buf()
for lnum, line in ipairs(lines) do
table.insert(lines_with_numbers, {
lnum = lnum,
line = line,
bufnr = bufnr,
filename = filename,
})
end
pickers.new(opts, {
prompt_title = 'Current Buffer Fuzzy',
finder = finders.new_table {
results = lines_with_numbers,
entry_maker = function(enumerated_line)
return {
bufnr = bufnr,
display = enumerated_line[2],
ordinal = enumerated_line[2],
lnum = enumerated_line[1],
}
end
entry_maker = opts.entry_maker or make_entry.gen_from_buffer_lines(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()
vim.api.nvim_win_set_cursor(0, {selection.lnum, 0})
vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 })
end,
}