feat: make buffer work much better

This commit is contained in:
TJ DeVries
2020-09-11 15:28:32 -04:00
parent a9404201a9
commit f47f1dc037
4 changed files with 27 additions and 7 deletions

View File

@@ -75,11 +75,11 @@ local function goto_file_selection(prompt_bufnr, command)
a.nvim_win_set_config(preview_win, {style = ''})
end
actions.close(prompt_bufnr)
local original_win_id = picker.original_win_id or 0
local entry_bufnr = entry.bufnr
actions.close(prompt_bufnr)
-- TODO: Sometimes we open something with missing line numbers and stuff...
if entry_bufnr then
a.nvim_win_set_buf(original_win_id, entry_bufnr)
@@ -115,8 +115,10 @@ end
function actions.close(prompt_bufnr)
local picker = actions.get_current_picker(prompt_bufnr)
local prompt_win = state.get_status(prompt_bufnr).prompt_win
vim.cmd(string.format([[bwipeout! %s]], prompt_bufnr))
vim.api.nvim_win_close(prompt_win, true)
vim.cmd(string.format([[bdelete! %s]], prompt_bufnr))
local original_win_id = picker.original_win_id or 0
a.nvim_set_current_win(original_win_id)

View File

@@ -350,10 +350,9 @@ end
-- Leave this alias around for people.
builtin.fd = builtin.find_files
-- TODO: Sometimes some window options (for me, I've experience number & relativenumber)
-- don't work when we open this up.
-- TODO: I'd like to use the `vim_buffer` previewer, but it doesn't seem to work due to some styling problems.
-- I think it has something to do with nvim_open_win and style='minimal',
-- but I can't figure that part out at the moment...
-- Status, currently operational.
builtin.buffers = function(opts)
opts = opts or {}
@@ -370,7 +369,8 @@ builtin.buffers = function(opts)
results = buffers,
entry_maker = make_entry.gen_from_buffer(opts)
},
previewer = previewers.vim_buffer.new(opts),
-- previewer = previewers.vim_buffer.new(opts),
previewer = previewers.vimgrep.new(opts),
sorter = sorters.get_generic_fuzzy_sorter(),
}):find()
end

View File

@@ -180,10 +180,23 @@ function make_entry.gen_from_quickfix(opts)
end
function make_entry.gen_from_buffer(opts)
local get_position = function(entry)
local tabpage_wins = vim.api.nvim_tabpage_list_wins(0)
for k, v in ipairs(tabpage_wins) do
if entry == vim.api.nvim_win_get_buf(v) then
return vim.api.nvim_win_get_cursor(v)
end
end
return {}
end
return function(entry)
local bufnr_str = tostring(entry)
local bufname = vim.api.nvim_buf_get_name(entry)
local position = get_position(entry)
if '' == bufname then
return nil
end
@@ -197,6 +210,8 @@ function make_entry.gen_from_buffer(opts)
bufnr = entry,
filename = bufname,
lnum = position[1] or 1,
}
end
end

View File

@@ -241,6 +241,9 @@ previewers.vimgrep = defaulter(function(_)
local _, _, filename, lnum, col, text = string.find(line, [[([^:]+):(%d+):(%d+):(.*)]])
filename = filename or entry.filename
lnum = lnum or entry.lnum or 0
local context = math.floor(height / 2)
local start = math.max(0, lnum - context)
local finish = lnum + context