feat: no preview option
This commit is contained in:
@@ -11,7 +11,19 @@ local sorters = require('telescope.sorters')
|
|||||||
|
|
||||||
local builtin = {}
|
local builtin = {}
|
||||||
|
|
||||||
builtin.git_files = function()
|
local ifnil = function(x, was_nil, was_not_nil)
|
||||||
|
if x == nil then
|
||||||
|
return was_nil
|
||||||
|
else
|
||||||
|
return was_not_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
builtin.git_files = function(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
|
||||||
|
local show_preview = ifnil(opts.show_preview, true, opts.show_preview)
|
||||||
|
|
||||||
-- TODO: Auto select bottom row
|
-- TODO: Auto select bottom row
|
||||||
-- TODO: filter out results when they don't match at all anymore.
|
-- TODO: filter out results when they don't match at all anymore.
|
||||||
|
|
||||||
@@ -29,7 +41,7 @@ builtin.git_files = function()
|
|||||||
local file_previewer = previewers.cat
|
local file_previewer = previewers.cat
|
||||||
|
|
||||||
local file_picker = pickers.new {
|
local file_picker = pickers.new {
|
||||||
previewer = file_previewer
|
previewer = show_preview and file_previewer,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- local file_sorter = telescope.sorters.get_ngram_sorter()
|
-- local file_sorter = telescope.sorters.get_ngram_sorter()
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ local Previewer = require('telescope.previewers').Previewer
|
|||||||
|
|
||||||
local pickers = {}
|
local pickers = {}
|
||||||
|
|
||||||
|
-- Picker takes a function (`get_window_options`) that returns the configurations required for three windows:
|
||||||
|
-- prompt
|
||||||
|
-- results
|
||||||
|
-- preview
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO: Add overscroll option for results buffer
|
||||||
|
|
||||||
--- Picker is the main UI that shows up to interact w/ your results.
|
--- Picker is the main UI that shows up to interact w/ your results.
|
||||||
-- Takes a filter & a previewr
|
-- Takes a filter & a previewr
|
||||||
local Picker = {}
|
local Picker = {}
|
||||||
@@ -32,10 +40,11 @@ function Picker:new(opts)
|
|||||||
filter = opts.filter,
|
filter = opts.filter,
|
||||||
previewer = opts.previewer,
|
previewer = opts.previewer,
|
||||||
maps = opts.maps,
|
maps = opts.maps,
|
||||||
|
get_window_options = opts.get_window_options,
|
||||||
}, Picker)
|
}, Picker)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Picker._get_window_options(max_columns, max_lines, prompt_title)
|
function Picker:get_window_options(max_columns, max_lines, prompt_title)
|
||||||
local preview = {
|
local preview = {
|
||||||
border = {},
|
border = {},
|
||||||
enter = false,
|
enter = false,
|
||||||
@@ -54,7 +63,9 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
|
|||||||
-- TODO: Test with 120 width terminal
|
-- TODO: Test with 120 width terminal
|
||||||
|
|
||||||
local width_padding = 10
|
local width_padding = 10
|
||||||
if max_columns < 150 then
|
if not self.previewer then
|
||||||
|
preview.width = 0
|
||||||
|
elseif max_columns < 150 then
|
||||||
width_padding = 5
|
width_padding = 5
|
||||||
preview.width = math.floor(max_columns * 0.4)
|
preview.width = math.floor(max_columns * 0.4)
|
||||||
elseif max_columns < 200 then
|
elseif max_columns < 200 then
|
||||||
@@ -78,8 +89,12 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
|
|||||||
prompt.height = 1
|
prompt.height = 1
|
||||||
prompt.minheight = prompt.height
|
prompt.minheight = prompt.height
|
||||||
|
|
||||||
|
if self.previewer then
|
||||||
preview.height = results.height + prompt.height + 2
|
preview.height = results.height + prompt.height + 2
|
||||||
preview.minheight = preview.height
|
preview.minheight = preview.height
|
||||||
|
else
|
||||||
|
preview.height = 0
|
||||||
|
end
|
||||||
|
|
||||||
results.col = width_padding
|
results.col = width_padding
|
||||||
prompt.col = width_padding
|
prompt.col = width_padding
|
||||||
@@ -92,7 +107,7 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
|
|||||||
preview.line = results.line
|
preview.line = results.line
|
||||||
|
|
||||||
return {
|
return {
|
||||||
preview = preview,
|
preview = self.previewer and preview,
|
||||||
results = results,
|
results = results,
|
||||||
prompt = prompt,
|
prompt = prompt,
|
||||||
}
|
}
|
||||||
@@ -113,7 +128,7 @@ function Picker:find(opts)
|
|||||||
-- 1. Prompt window
|
-- 1. Prompt window
|
||||||
-- 2. Options window
|
-- 2. Options window
|
||||||
-- 3. Preview window
|
-- 3. Preview window
|
||||||
local popup_opts = Picker._get_window_options(vim.o.columns, vim.o.lines, prompt_string)
|
local popup_opts = self:get_window_options(vim.o.columns, vim.o.lines, prompt_string)
|
||||||
|
|
||||||
-- TODO: Add back the borders after fixing some stuff in popup.nvim
|
-- TODO: Add back the borders after fixing some stuff in popup.nvim
|
||||||
local results_win, results_opts = popup.create('', popup_opts.results)
|
local results_win, results_opts = popup.create('', popup_opts.results)
|
||||||
@@ -122,13 +137,17 @@ function Picker:find(opts)
|
|||||||
-- TODO: Should probably always show all the line for results win, so should implement a resize for the windows
|
-- TODO: Should probably always show all the line for results win, so should implement a resize for the windows
|
||||||
a.nvim_win_set_option(results_win, 'wrap', false)
|
a.nvim_win_set_option(results_win, 'wrap', false)
|
||||||
|
|
||||||
local preview_win, preview_opts = popup.create('', popup_opts.preview)
|
|
||||||
local preview_bufnr = a.nvim_win_get_buf(preview_win)
|
local preview_win, preview_opts, preview_bufnr
|
||||||
|
if popup_opts.preview then
|
||||||
|
preview_win, preview_opts = popup.create('', popup_opts.preview)
|
||||||
|
preview_bufnr = a.nvim_win_get_buf(preview_win)
|
||||||
|
|
||||||
-- TODO: For some reason, highlighting is kind of weird on these windows.
|
-- TODO: For some reason, highlighting is kind of weird on these windows.
|
||||||
-- It may actually be my colorscheme tho...
|
-- It may actually be my colorscheme tho...
|
||||||
a.nvim_win_set_option(preview_win, 'winhl', 'Normal:Normal')
|
a.nvim_win_set_option(preview_win, 'winhl', 'Normal:Normal')
|
||||||
a.nvim_win_set_option(preview_win, 'winblend', 1)
|
a.nvim_win_set_option(preview_win, 'winblend', 10)
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO: We need to center this and make it prettier...
|
-- TODO: We need to center this and make it prettier...
|
||||||
local prompt_win, prompt_opts = popup.create('', popup_opts.prompt)
|
local prompt_win, prompt_opts = popup.create('', popup_opts.prompt)
|
||||||
@@ -190,6 +209,8 @@ function Picker:find(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local process_complete = vim.schedule_wrap(function()
|
local process_complete = vim.schedule_wrap(function()
|
||||||
|
self:set_selection(self:get_selection_row())
|
||||||
|
|
||||||
local worst_line = self.max_results - self.manager.num_results()
|
local worst_line = self.max_results - self.manager.num_results()
|
||||||
if worst_line == 0 then
|
if worst_line == 0 then
|
||||||
return
|
return
|
||||||
@@ -257,7 +278,7 @@ function Picker:find(opts)
|
|||||||
|
|
||||||
preview_bufnr = preview_bufnr,
|
preview_bufnr = preview_bufnr,
|
||||||
preview_win = preview_win,
|
preview_win = preview_win,
|
||||||
preview_border_win = preview_opts.border.win_id,
|
preview_border_win = preview_opts and preview_opts.border.win_id,
|
||||||
|
|
||||||
picker = self,
|
picker = self,
|
||||||
previewer = self.previewer,
|
previewer = self.previewer,
|
||||||
@@ -269,6 +290,12 @@ function Picker:find(opts)
|
|||||||
vim.cmd [[startinsert]]
|
vim.cmd [[startinsert]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Picker:hide_preview()
|
||||||
|
-- 1. Hide the window (and border)
|
||||||
|
-- 2. Resize prompt & results windows accordingly
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Picker:close_windows(status)
|
function Picker:close_windows(status)
|
||||||
local prompt_win = status.prompt_win
|
local prompt_win = status.prompt_win
|
||||||
local results_win = status.results_win
|
local results_win = status.results_win
|
||||||
@@ -330,6 +357,11 @@ function Picker:set_selection(row)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local entry = self.manager:get_entry(self.max_results - row + 1)
|
local entry = self.manager:get_entry(self.max_results - row + 1)
|
||||||
|
if entry == self._selection then
|
||||||
|
log.debug("Same entry as before. Skipping set")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local status = state.get_status(self.prompt_bufnr)
|
local status = state.get_status(self.prompt_bufnr)
|
||||||
|
|
||||||
a.nvim_buf_clear_namespace(status.results_bufnr, ns_telescope_selection, 0, -1)
|
a.nvim_buf_clear_namespace(status.results_bufnr, ns_telescope_selection, 0, -1)
|
||||||
@@ -349,7 +381,7 @@ function Picker:set_selection(row)
|
|||||||
self._selection = entry
|
self._selection = entry
|
||||||
self._selection_row = row
|
self._selection_row = row
|
||||||
|
|
||||||
if self.previewer then
|
if status.preview_win and self.previewer then
|
||||||
self.previewer:preview(
|
self.previewer:preview(
|
||||||
entry,
|
entry,
|
||||||
status
|
status
|
||||||
@@ -452,7 +484,6 @@ pickers.entry_manager = function(max_results, set_entry)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function pickers.on_close_prompt(prompt_bufnr)
|
function pickers.on_close_prompt(prompt_bufnr)
|
||||||
local status = state.get_status(prompt_bufnr)
|
local status = state.get_status(prompt_bufnr)
|
||||||
local picker = status.picker
|
local picker = status.picker
|
||||||
|
|||||||
Reference in New Issue
Block a user