Merge pull request #215 from MaximilianLloyd/move-up

Implement move up for telescope extension
This commit is contained in:
ThePrimeagen 2022-10-06 09:50:12 -06:00 committed by GitHub
commit 4dfe94e633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,9 +50,8 @@ local generate_new_finder = function()
end end
local delete_harpoon_mark = function(prompt_bufnr) local delete_harpoon_mark = function(prompt_bufnr)
local confirmation = vim.fn.input( local confirmation =
string.format("Delete current mark(s)? [y/n]: ") vim.fn.input(string.format("Delete current mark(s)? [y/n]: "))
)
if if
string.len(confirmation) == 0 string.len(confirmation) == 0
or string.sub(string.lower(confirmation), 0, 1) ~= "y" or string.sub(string.lower(confirmation), 0, 1) ~= "y"
@ -81,6 +80,23 @@ local delete_harpoon_mark = function(prompt_bufnr)
current_picker:refresh(generate_new_finder(), { reset_prompt = true }) current_picker:refresh(generate_new_finder(), { reset_prompt = true })
end end
local move_mark_up = function(prompt_bufnr)
local selection = action_state.get_selected_entry()
local length = harpoon_mark.get_length()
if selection.index == length then
return
end
local mark_list = harpoon.get_mark_config().marks
table.remove(mark_list, selection.index)
table.insert(mark_list, selection.index + 1, selection.value)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:refresh(generate_new_finder(), { reset_prompt = true })
end
local move_mark_down = function(prompt_bufnr) local move_mark_down = function(prompt_bufnr)
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
if selection.index == 1 then if selection.index == 1 then
@ -96,20 +112,23 @@ end
return function(opts) return function(opts)
opts = opts or {} opts = opts or {}
pickers.new(opts, { pickers
prompt_title = "harpoon marks", .new(opts, {
finder = generate_new_finder(), prompt_title = "harpoon marks",
sorter = conf.generic_sorter(opts), finder = generate_new_finder(),
previewer = conf.grep_previewer(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map) previewer = conf.grep_previewer(opts),
map("i", "<c-d>", delete_harpoon_mark) attach_mappings = function(_, map)
map("n", "<c-d>", delete_harpoon_mark) map("i", "<c-d>", delete_harpoon_mark)
-- TODO: implement move_mark_up map("n", "<c-d>", delete_harpoon_mark)
-- map("i", "<c-p>", move_mark_up)
-- map("n", "<c-p>", move_mark_up) map("i", "<c-p>", move_mark_up)
map("i", "<c-n>", move_mark_down) map("n", "<c-p>", move_mark_up)
map("n", "<c-n>", move_mark_down)
return true map("i", "<c-n>", move_mark_down)
end, map("n", "<c-n>", move_mark_down)
}):find() return true
end,
})
:find()
end end