diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-07-31 00:05:22 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-07-31 00:05:22 -0400 |
| commit | fa0382d93e73b66e7ec769cec27b9fbb21020641 (patch) | |
| tree | 624d5dc3de80426956a1c46447f1f26443a87a64 /lua/telescope/mappings.lua | |
| parent | ababfbfd88334ca6d94d5d0a8b6324dd6600d602 (diff) | |
Streamed some refactoring. More work to do
Diffstat (limited to 'lua/telescope/mappings.lua')
| -rw-r--r-- | lua/telescope/mappings.lua | 61 |
1 files changed, 10 insertions, 51 deletions
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index 3c6de18..a3704a6 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -1,12 +1,10 @@ -- TODO: Customize keymap local a = vim.api -local ns_telescope_selection = a.nvim_create_namespace('telescope_selection') local state = require('telescope.state') local mappings = {} local keymap = {} -local telescope_selections = {} mappings.set_keymap = function(prompt_bufnr, results_bufnr) local function default_mapper(map_key, table_key) @@ -31,31 +29,8 @@ mappings.set_keymap = function(prompt_bufnr, results_bufnr) default_mapper('<CR>', 'enter') end -local function update_current_selection(prompt_bufnr, results_bufnr, row) - local status = state.get_status(prompt_bufnr) - - a.nvim_buf_clear_namespace(results_bufnr, ns_telescope_selection, 0, -1) - a.nvim_buf_add_highlight( - results_bufnr, - ns_telescope_selection, - 'Error', - row, - 0, - -1 - ) - - telescope_selections[prompt_bufnr] = row - - if status.previewer then - vim.g.got_here = true - - status.previewer:preview( - status.preview_win, - status.preview_bufnr, - status.results_bufnr, - row - ) - end +local function update_current_selection(prompt_bufnr, change) + state.get_status(prompt_bufnr).picker:move_selection(change) end @@ -68,34 +43,16 @@ end -- TODO: Refactor this to use shared code. -- TODO: Move from top to bottom, etc. -- TODO: It seems like doing this brings us back to the beginning of the prompt, which is not great. -keymap["control-n"] = function(prompt_bufnr, results_bufnr) - if telescope_selections[prompt_bufnr] == nil then - telescope_selections[prompt_bufnr] = 0 - end - - local row = telescope_selections[prompt_bufnr] + 1 - update_current_selection(prompt_bufnr, results_bufnr, row) +keymap["control-n"] = function(prompt_bufnr, _) + update_current_selection(prompt_bufnr, 1) end -keymap["control-p"] = function(prompt_bufnr, results_bufnr) - if telescope_selections[prompt_bufnr] == nil then - telescope_selections[prompt_bufnr] = 0 - end - - local row = telescope_selections[prompt_bufnr] - 1 - update_current_selection(prompt_bufnr, results_bufnr, row) +keymap["control-p"] = function(prompt_bufnr, _) + update_current_selection(prompt_bufnr, -1) end keymap["enter"] = function(prompt_bufnr, results_bufnr) - local extmark = a.nvim_buf_get_extmarks( - results_bufnr, - ns_telescope_selection, - 0, - -1, - {} - ) - - local row = extmark[1][2] + local row = state.get_status(prompt_bufnr).picker:get_selection() if row == nil then print("Could not do anything...") return @@ -117,7 +74,9 @@ keymap["enter"] = function(prompt_bufnr, results_bufnr) local bufnr = vim.fn.bufnr(filename, true) a.nvim_set_current_buf(bufnr) a.nvim_buf_set_option(bufnr, 'buflisted', true) - a.nvim_win_set_cursor(0, {row, col}) + if row and col then + a.nvim_win_set_cursor(0, {row, col}) + end end end |
