fix: clear last line

This commit is contained in:
TJ DeVries
2020-09-02 19:11:38 -04:00
parent 061307233c
commit d48a2933d5
3 changed files with 33 additions and 2 deletions

View File

@@ -246,6 +246,8 @@ end
builtin.fd = function(opts)
opts = opts or {}
local fd_string = nil
if 1 == vim.fn.executable("fd") then
fd_string = "fd"
@@ -258,9 +260,23 @@ builtin.fd = function(opts)
return
end
-- TODO: CWD not 100% supported at this moment.
-- Previewers don't work. We'll have to try out something for that later
local cwd = opts.cwd
if cwd then
cwd = vim.fn.expand(cwd)
end
pickers.new(opts, {
prompt = 'Find Files',
finder = finders.new_oneshot_job {fd_string},
finder = finders.new {
fn_command = function()
return {
command = fd_string,
cwd = cwd,
}
end,
},
previewer = previewers.cat,
sorter = sorters.get_fuzzy_file(),
}):find()

View File

@@ -125,6 +125,7 @@ function Finder:_find(prompt, process_result, process_complete)
self.job = Job:new {
command = opts.command,
args = opts.args,
cwd = opts.cwd,
maximum_results = self.maximum_results,

View File

@@ -231,6 +231,10 @@ function Picker:find()
local selection_strategy = self.selection_strategy or 'reset'
local on_lines = function(_, _, _, first_line, last_line)
if not vim.api.nvim_buf_is_valid(prompt_bufnr) then
return
end
local prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, first_line, last_line, false)[1]
self.manager = pickers.entry_manager(
@@ -306,7 +310,7 @@ function Picker:find()
self:set_selection(self.max_results)
end
local worst_line = self.max_results - self.manager.num_results()
local worst_line = self.max_results - self.manager.num_results() + 1
if worst_line <= 0 then
return
end
@@ -448,12 +452,22 @@ function Picker:reset_selection()
end
function Picker:set_selection(row)
-- TODO: Loop around behavior?
-- TODO: Scrolling past max results
if row > self.max_results then
row = self.max_results
elseif row < 1 then
row = 1
end
-- TODO: Move max results and row and entry management into an overridable funciton.
-- I have this same thing copied all over the place (and it's not good).
-- Particularly if we're going to do something like make it possible to sort
-- top to bottom, rather than bottom to top.
if row < (self.max_results - self.manager:num_results() + 1) then
return
end
local entry = self.manager:get_entry(self.max_results - row + 1)
local status = state.get_status(self.prompt_bufnr)
local results_bufnr = status.results_bufnr