summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-08-29 22:15:40 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-08-29 22:15:40 -0400
commitae9b76929957a1eb20ea016c6ce9d34bc0d8b213 (patch)
tree4b129c1d53e9df1c7cb663a6bacb9b6dc84605d7
parent711536859370510531744f6b239004a67c2e1a7e (diff)
feat: Add selection and start actions
-rw-r--r--lua/telescope/actions.lua25
-rw-r--r--lua/telescope/mappings.lua9
-rw-r--r--lua/telescope/pickers.lua25
-rw-r--r--plugin/telescope.vim50
4 files changed, 77 insertions, 32 deletions
diff --git a/lua/telescope/actions.lua b/lua/telescope/actions.lua
new file mode 100644
index 0000000..a03323b
--- /dev/null
+++ b/lua/telescope/actions.lua
@@ -0,0 +1,25 @@
+-- Actions functions that are useful for people creating their own mappings.
+
+local state = require('telescope.state')
+
+local actions = {}
+
+
+--- Get the current picker object for the prompt
+function actions.get_current_picker(prompt_bufnr)
+ return state.get_status(prompt_bufnr).picker
+end
+
+--- Move the current selection of a picker {change} rows.
+--- Handles not overflowing / underflowing the list.
+function actions.shift_current_selection(prompt_bufnr, change)
+ actions.get_current_picker(prompt_bufnr):move_selection(change)
+end
+
+--- Get the current entry
+function actions.get_selected_entry(prompt_bufnr)
+ return actions.get_current_picker(prompt_bufnr):get_selection()
+end
+
+
+return actions
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua
index 1bcf1d2..6bbbac5 100644
--- a/lua/telescope/mappings.lua
+++ b/lua/telescope/mappings.lua
@@ -1,6 +1,7 @@
-- TODO: Customize keymap
local a = vim.api
+local actions = require('telescope.actions')
local state = require('telescope.state')
local mappings = {}
@@ -29,10 +30,6 @@ mappings.set_keymap = function(prompt_bufnr, results_bufnr)
default_mapper('<CR>', 'enter')
end
-local function update_current_selection(prompt_bufnr, change)
- state.get_status(prompt_bufnr).picker:move_selection(change)
-end
-
function __TelescopeMapping(prompt_bufnr, results_bufnr, characters)
if keymap[characters] then
@@ -44,11 +41,11 @@ end
-- 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, _)
- update_current_selection(prompt_bufnr, 1)
+ actions.shift_current_selection(prompt_bufnr, 1)
end
keymap["control-p"] = function(prompt_bufnr, _)
- update_current_selection(prompt_bufnr, -1)
+ actions.shift_current_selection(prompt_bufnr, -1)
end
keymap["enter"] = function(prompt_bufnr, results_bufnr)
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index fc191bd..95476f1 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -193,6 +193,7 @@ function Picker:find(opts)
return
end
+ -- TODO: This really isn't the place to do this.
local display = entry.display
if has_devicons then
@@ -200,6 +201,8 @@ function Picker:find(opts)
display = (icon or ' ') .. ' ' .. display
end
+ display = ' ' .. display
+
-- log.info("Setting row", row, "with value", entry)
vim.api.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {display})
end
@@ -388,17 +391,33 @@ function Picker:set_selection(row)
end
local status = state.get_status(self.prompt_bufnr)
+ local results_bufnr = status.results_bufnr
+
+ -- Handle adding '> ' to beginning of selections
+ if self._selection_row then
+ a.nvim_buf_set_lines(results_bufnr, self._selection_row, self._selection_row + 1, false, {' ' .. a.nvim_buf_get_lines(results_bufnr, self._selection_row, self._selection_row + 1, false)[1]:sub(3)})
+ end
+
+ a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {'> ' .. a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1]:sub(3)})
- a.nvim_buf_clear_namespace(status.results_bufnr, ns_telescope_selection, 0, -1)
+ a.nvim_buf_clear_namespace(results_bufnr, ns_telescope_selection, 0, -1)
a.nvim_buf_add_highlight(
- status.results_bufnr,
+ results_bufnr,
ns_telescope_selection,
- 'Error',
+ 'TelescopeSelection',
row,
0,
-1
)
+
+ -- if self._match_id then
+ -- -- vim.fn.matchdelete(self._match_id)
+ -- vim.fn.clearmatches(results_win)
+ -- end
+
+ -- self._match_id = vim.fn.matchaddpos("Conceal", { {row + 1, 1, 2} }, 0, -1, { window = results_win, conceal = ">" })
+
-- TODO: Don't let you go over / under the buffer limits
-- TODO: Make sure you start exactly at the bottom selected
diff --git a/plugin/telescope.vim b/plugin/telescope.vim
index 50627bf..48a39e0 100644
--- a/plugin/telescope.vim
+++ b/plugin/telescope.vim
@@ -1,28 +1,32 @@
+
+highlight default link TelescopeSelection Visual
+
+
" let s:term_command = "rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}' --print0"
" let s:term_command = "rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}' > file.txt"
-let s:term_command = "(rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}')"
-
-function! s:on_exit() abort
- let g:result = readfile('file.txt')
-endfunction
-
-function! TestFunc() abort
- let g:term_output_stdout = []
- let g:term_output_stderr = []
- let g:term_output_onexit = []
-
- vnew
- let term_id = termopen(s:term_command, {
- \ 'on_stdout': { j, d, e -> add(g:term_output_stdout, d) },
- \ 'on_stderr': { j, d, e -> add(g:term_output_stderr, d) },
- \ 'on_exit': { j, d, e -> s:on_exit() },
- \ 'stdout_buffered': v:false,
- \ })
-endfunction
-
-function! PrintStuff() abort
- echo len(g:term_output_stdout) len(g:term_output_stderr) len(g:term_output_onexit)
-endfunction
+" let s:term_command = "(rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}')"
+
+" function! s:on_exit() abort
+" let g:result = readfile('file.txt')
+" endfunction
+
+" function! TestFunc() abort
+" let g:term_output_stdout = []
+" let g:term_output_stderr = []
+" let g:term_output_onexit = []
+
+" vnew
+" let term_id = termopen(s:term_command, {
+" \ 'on_stdout': { j, d, e -> add(g:term_output_stdout, d) },
+" \ 'on_stderr': { j, d, e -> add(g:term_output_stderr, d) },
+" \ 'on_exit': { j, d, e -> s:on_exit() },
+" \ 'stdout_buffered': v:false,
+" \ })
+" endfunction
+
+" function! PrintStuff() abort
+" echo len(g:term_output_stdout) len(g:term_output_stderr) len(g:term_output_onexit)
+" endfunction
" call TestFunc()