feat: make buffer work much better
This commit is contained in:
@@ -75,11 +75,11 @@ local function goto_file_selection(prompt_bufnr, command)
|
|||||||
a.nvim_win_set_config(preview_win, {style = ''})
|
a.nvim_win_set_config(preview_win, {style = ''})
|
||||||
end
|
end
|
||||||
|
|
||||||
actions.close(prompt_bufnr)
|
|
||||||
|
|
||||||
local original_win_id = picker.original_win_id or 0
|
local original_win_id = picker.original_win_id or 0
|
||||||
local entry_bufnr = entry.bufnr
|
local entry_bufnr = entry.bufnr
|
||||||
|
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
|
|
||||||
-- TODO: Sometimes we open something with missing line numbers and stuff...
|
-- TODO: Sometimes we open something with missing line numbers and stuff...
|
||||||
if entry_bufnr then
|
if entry_bufnr then
|
||||||
a.nvim_win_set_buf(original_win_id, entry_bufnr)
|
a.nvim_win_set_buf(original_win_id, entry_bufnr)
|
||||||
@@ -115,8 +115,10 @@ end
|
|||||||
|
|
||||||
function actions.close(prompt_bufnr)
|
function actions.close(prompt_bufnr)
|
||||||
local picker = actions.get_current_picker(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
|
local original_win_id = picker.original_win_id or 0
|
||||||
a.nvim_set_current_win(original_win_id)
|
a.nvim_set_current_win(original_win_id)
|
||||||
|
|||||||
@@ -350,10 +350,9 @@ end
|
|||||||
-- Leave this alias around for people.
|
-- Leave this alias around for people.
|
||||||
builtin.fd = builtin.find_files
|
builtin.fd = builtin.find_files
|
||||||
|
|
||||||
-- TODO: Sometimes some window options (for me, I've experience number & relativenumber)
|
-- TODO: I'd like to use the `vim_buffer` previewer, but it doesn't seem to work due to some styling problems.
|
||||||
-- don't work when we open this up.
|
|
||||||
-- I think it has something to do with nvim_open_win and style='minimal',
|
-- 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)
|
builtin.buffers = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
@@ -370,7 +369,8 @@ builtin.buffers = function(opts)
|
|||||||
results = buffers,
|
results = buffers,
|
||||||
entry_maker = make_entry.gen_from_buffer(opts)
|
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(),
|
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||||
}):find()
|
}):find()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -180,10 +180,23 @@ function make_entry.gen_from_quickfix(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function make_entry.gen_from_buffer(opts)
|
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)
|
return function(entry)
|
||||||
local bufnr_str = tostring(entry)
|
local bufnr_str = tostring(entry)
|
||||||
local bufname = vim.api.nvim_buf_get_name(entry)
|
local bufname = vim.api.nvim_buf_get_name(entry)
|
||||||
|
|
||||||
|
local position = get_position(entry)
|
||||||
|
|
||||||
if '' == bufname then
|
if '' == bufname then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -197,6 +210,8 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
|
|
||||||
bufnr = entry,
|
bufnr = entry,
|
||||||
filename = bufname,
|
filename = bufname,
|
||||||
|
|
||||||
|
lnum = position[1] or 1,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -241,6 +241,9 @@ previewers.vimgrep = defaulter(function(_)
|
|||||||
|
|
||||||
local _, _, filename, lnum, col, text = string.find(line, [[([^:]+):(%d+):(%d+):(.*)]])
|
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 context = math.floor(height / 2)
|
||||||
local start = math.max(0, lnum - context)
|
local start = math.max(0, lnum - context)
|
||||||
local finish = lnum + context
|
local finish = lnum + context
|
||||||
|
|||||||
Reference in New Issue
Block a user