summaryrefslogtreecommitdiff
path: root/lua/telescope/actions.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-08-31 00:06:33 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-08-31 00:06:53 -0400
commit6b066cf9e866729b9c8292d7ab3e8071abdd7d45 (patch)
tree20049f31c35f46d18607d65cbaec3139d7c02f75 /lua/telescope/actions.lua
parenta6fe9721ac0791bdf18a04594c31b28e879ed63e (diff)
feat: Add better mapping support
Diffstat (limited to 'lua/telescope/actions.lua')
-rw-r--r--lua/telescope/actions.lua61
1 files changed, 59 insertions, 2 deletions
diff --git a/lua/telescope/actions.lua b/lua/telescope/actions.lua
index a03323b..abd5bf8 100644
--- a/lua/telescope/actions.lua
+++ b/lua/telescope/actions.lua
@@ -1,9 +1,14 @@
-- Actions functions that are useful for people creating their own mappings.
-local state = require('telescope.state')
+local a = vim.api
-local actions = {}
+local state = require('telescope.state')
+local actions = setmetatable({}, {
+ __index = function(t, k)
+ error("Actions does not have a value: " .. tostring(k))
+ end
+})
--- Get the current picker object for the prompt
function actions.get_current_picker(prompt_bufnr)
@@ -16,10 +21,62 @@ function actions.shift_current_selection(prompt_bufnr, change)
actions.get_current_picker(prompt_bufnr):move_selection(change)
end
+function actions.move_selection_next(prompt_bufnr)
+ actions.shift_current_selection(prompt_bufnr, 1)
+end
+
+function actions.move_selection_previous(prompt_bufnr)
+ actions.shift_current_selection(prompt_bufnr, -1)
+end
+
--- Get the current entry
function actions.get_selected_entry(prompt_bufnr)
return actions.get_current_picker(prompt_bufnr):get_selection()
end
+function actions.goto_file_selection(prompt_bufnr)
+ local picker = actions.get_current_picker(prompt_bufnr)
+ local entry = actions.get_selected_entry(prompt_bufnr)
+
+ if not entry then
+ print("[telescope] Nothing currently selected")
+ return
+ else
+ local value = entry.value
+ if not value then
+ print("Could not do anything with blank line...")
+ return
+ end
+
+ -- TODO: This is not great.
+ if type(value) == "table" then
+ value = entry.display
+ end
+
+ local sections = vim.split(value, ":")
+
+ local filename = sections[1]
+ local row = tonumber(sections[2])
+ local col = tonumber(sections[3])
+
+ vim.cmd(string.format([[bwipeout! %s]], prompt_bufnr))
+
+ a.nvim_set_current_win(picker.original_win_id or 0)
+ vim.cmd(string.format(":e %s", filename))
+
+ local bufnr = vim.api.nvim_get_current_buf()
+ a.nvim_buf_set_option(bufnr, 'buflisted', true)
+ if row and col then
+ a.nvim_win_set_cursor(0, {row, col})
+ end
+
+ vim.cmd [[stopinsert]]
+ end
+end
+
+actions.close = function(prompt_bufnr)
+ vim.cmd(string.format([[bwipeout! %s]], prompt_bufnr))
+end
+
return actions