Skip to content

Commit

Permalink
implement workaround and suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Conni2461 committed Jul 9, 2021
1 parent 0d22956 commit affe310
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 30 deletions.
12 changes: 10 additions & 2 deletions lua/telescope/actions/history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ end
---@param picker table: the current picker object
---@return string: the next history item
function histories.History:get_next(line, picker)
if not self.enabled then return end
if not self.enabled then
print("You are cycling to next the history item but history is disabled.",
"Read ':help telescope.defaults.history_handler'")
return false
end
if self._pre_get then self._pre_get(self, line, picker) end

local next_idx = self.index + 1
Expand All @@ -121,7 +125,11 @@ end
---@param picker table: the current picker object
---@return string: the previous history item
function histories.History:get_prev(line, picker)
if not self.enabled then return end
if not self.enabled then
print("You are cycling to previous the history item but history is disabled.",
"Read ':help telescope.defaults.history_handler'")
return false
end
if self._pre_get then self._pre_get(self, line, picker) end

local next_idx = self.index - 1
Expand Down
63 changes: 49 additions & 14 deletions lua/telescope/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,53 @@ function actions.center(_)
vim.cmd(':normal! zz')
end

function actions.select_default(prompt_bufnr)
return action_set.select(prompt_bufnr, "default")
end
actions.select_default = {
pre = function(prompt_bufnr)
action_state.get_current_history():append(
action_state.get_current_line(),
action_state.get_current_picker(prompt_bufnr)
)
end,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "default")
end
}

function actions.select_horizontal(prompt_bufnr)
return action_set.select(prompt_bufnr, "horizontal")
end
actions.select_horizontal = {
pre = function(prompt_bufnr)
action_state.get_current_history():append(
action_state.get_current_line(),
action_state.get_current_picker(prompt_bufnr)
)
end,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "horizontal")
end
}

function actions.select_vertical(prompt_bufnr)
return action_set.select(prompt_bufnr, "vertical")
end
actions.select_vertical = {
pre = function(prompt_bufnr)
action_state.get_current_history():append(
action_state.get_current_line(),
action_state.get_current_picker(prompt_bufnr)
)
end,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "vertical")
end
}

function actions.select_tab(prompt_bufnr)
return action_set.select(prompt_bufnr, "tab")
end
actions.select_tab = {
pre = function(prompt_bufnr)
action_state.get_current_history():append(
action_state.get_current_line(),
action_state.get_current_picker(prompt_bufnr)
)
end,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "tab")
end
}

-- TODO: consider adding float!
-- https://github.com/nvim-telescope/telescope.nvim/issues/365
Expand Down Expand Up @@ -702,8 +734,10 @@ actions.cycle_history_next = function(prompt_bufnr)
local line = action_state.get_current_line()

local entry = history:get_next(line, current_picker)
if entry == false then return end

current_picker:reset_prompt()
if entry then
if entry ~= nil then
current_picker:set_prompt(entry)
end
end
Expand All @@ -714,7 +748,8 @@ actions.cycle_history_prev = function(prompt_bufnr)
local line = action_state.get_current_line()

local entry = history:get_prev(line, current_picker)
if entry then
if entry == false then return end
if entry ~= nil then
current_picker:reset_prompt()
current_picker:set_prompt(entry)
end
Expand Down
29 changes: 17 additions & 12 deletions lua/telescope/actions/set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,23 @@ end
---@param prompt_bufnr number: The prompt bufnr
---@param type string: The type of selection to make
-- Valid types include: "default", "horizontal", "vertical", "tabedit"
action_set.select = {
-- Will not be called if `select_default` is replaced rather than `action_set.select` because we never get here
pre = function(prompt_bufnr)
action_state.get_current_history():append(
action_state.get_current_line(),
action_state.get_current_picker(prompt_bufnr)
)
end,
action = function(prompt_bufnr, type)
return action_set.edit(prompt_bufnr, action_state.select_key_to_edit_key(type))
end
}
action_set.select = function(prompt_bufnr, type)
return action_set.edit(prompt_bufnr, action_state.select_key_to_edit_key(type))
end

-- goal: currently we have a workaround in actions/init.lua where we do this for all files
-- action_set.select = {
-- -- Will not be called if `select_default` is replaced rather than `action_set.select` because we never get here
-- pre = function(prompt_bufnr)
-- action_state.get_current_history():append(
-- action_state.get_current_line(),
-- action_state.get_current_picker(prompt_bufnr)
-- )
-- end,
-- action = function(prompt_bufnr, type)
-- return action_set.edit(prompt_bufnr, action_state.select_key_to_edit_key(type))
-- end
-- }

local edit_buffer
do
Expand Down
4 changes: 2 additions & 2 deletions scripts/gendocs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ docs.test = function()
local input_files = {
"./lua/telescope/init.lua",
"./lua/telescope/builtin/init.lua",
"./lua/telescope/themes.lua",
"./lua/telescope/pickers/layout_strategies.lua",
"./lua/telescope/config/resolve.lua",
"./lua/telescope/actions/init.lua",
"./lua/telescope/actions/state.lua",
"./lua/telescope/actions/set.lua",
"./lua/telescope/actions/utils.lua",
"./lua/telescope/previewers/init.lua",
"./lua/telescope/config/resolve.lua",
"./lua/telescope/themes.lua",
"./lua/telescope/actions/history.lua",
}

Expand Down

0 comments on commit affe310

Please sign in to comment.