mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2025-12-06 06:46:10 +00:00
chore: cleanup file lnum col
This commit is contained in:
@@ -208,6 +208,12 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
end)
|
||||
end
|
||||
|
||||
local prompt_location = picker:get_local_key "prompt_location"
|
||||
if prompt_location then
|
||||
row = prompt_location.row or 0
|
||||
col = prompt_location.col or 0
|
||||
end
|
||||
|
||||
local pos = vim.api.nvim_win_get_cursor(0)
|
||||
if col == nil then
|
||||
if row == pos[1] then
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local state = require "telescope.state"
|
||||
local action_state = require "telescope.actions.state"
|
||||
local action_set = require "telescope.actions.set"
|
||||
local actions = require "telescope.actions"
|
||||
@@ -385,6 +386,17 @@ files.find_files = function(opts)
|
||||
.new(opts, {
|
||||
prompt_title = "Find Files",
|
||||
files_picker = true,
|
||||
on_input_filter_cb = function(prompt, picker)
|
||||
local filename, lnum, col = utils.separate_file_path_location(prompt)
|
||||
|
||||
if lnum or col then
|
||||
picker:set_local_key("prompt_location", { row = lnum, col = col })
|
||||
elseif state.get_global_key "prompt_location" then
|
||||
picker:get_local_key("prompt_location", nil)
|
||||
end
|
||||
|
||||
return { prompt = filename }
|
||||
end,
|
||||
finder = finders.new_oneshot_job(find_command, opts),
|
||||
previewer = conf.file_previewer(opts),
|
||||
sorter = conf.file_sorter(opts),
|
||||
|
||||
@@ -320,7 +320,7 @@ function Picker:new(opts)
|
||||
|
||||
__scrolling_limit = tonumber(vim.F.if_nil(opts.temp__scrolling_limit, 250)),
|
||||
|
||||
allow_location_input = opts.files_picker or false,
|
||||
__local_state = {},
|
||||
}, self)
|
||||
|
||||
obj.create_layout = opts.create_layout or config.values.create_layout or default_create_layout
|
||||
@@ -628,24 +628,6 @@ function Picker:find()
|
||||
local start_time = vim.loop.hrtime()
|
||||
|
||||
local prompt = self:_get_next_filtered_prompt()
|
||||
if self.allow_location_input == true then
|
||||
local filename, line_number, column_number = utils.separate_file_path_location(prompt)
|
||||
|
||||
if line_number or column_number then
|
||||
state.set_global_key("prompt_location", { row = line_number, col = column_number })
|
||||
self:refresh_previewer()
|
||||
elseif state.get_global_key "prompt_location" then
|
||||
state.set_global_key("prompt_location", nil)
|
||||
self:refresh_previewer()
|
||||
end
|
||||
|
||||
-- it is important to continue behaving as if there is no location in prompt
|
||||
prompt = filename
|
||||
elseif state.get_global_key "prompt_location" then
|
||||
-- in case new picker that does not support locations is opened clear the location
|
||||
-- without refreshing previewer
|
||||
state.set_global_key("prompt_location", nil)
|
||||
end
|
||||
|
||||
-- TODO: Entry manager should have a "bulk" setter. This can prevent a lot of redraws from display
|
||||
if self.cache_picker == false or self.cache_picker.is_cached ~= true then
|
||||
@@ -1067,12 +1049,6 @@ function Picker:set_selection(row)
|
||||
|
||||
local entry = self.manager:get_entry(self:get_index(row))
|
||||
|
||||
local prompt_location = state.get_global_key "prompt_location"
|
||||
if entry and prompt_location then
|
||||
entry.lnum = prompt_location.row or 0
|
||||
entry.col = prompt_location.col or 0
|
||||
end
|
||||
|
||||
state.set_global_key("selected_entry", entry)
|
||||
|
||||
if not entry then
|
||||
@@ -1651,11 +1627,12 @@ end
|
||||
|
||||
function Picker:_get_next_filtered_prompt()
|
||||
local prompt = self:_get_prompt()
|
||||
local on_input_result = self._on_input_filter_cb(prompt) or {}
|
||||
local on_input_result = self._on_input_filter_cb(prompt, self) or {}
|
||||
|
||||
local new_prompt = on_input_result.prompt
|
||||
if new_prompt then
|
||||
prompt = new_prompt
|
||||
self:refresh_previewer()
|
||||
end
|
||||
|
||||
local new_finder = on_input_result.updated_finder
|
||||
@@ -1697,6 +1674,14 @@ function Picker:_resume_picker()
|
||||
end
|
||||
end
|
||||
|
||||
function Picker:set_local_key(key, value)
|
||||
self.__local_state[key] = value
|
||||
end
|
||||
|
||||
function Picker:get_local_key(key)
|
||||
return self.__local_state[key]
|
||||
end
|
||||
|
||||
pickers._Picker = Picker
|
||||
|
||||
return pickers
|
||||
|
||||
@@ -488,9 +488,10 @@ end
|
||||
previewers.cat = defaulter(function(opts)
|
||||
opts = opts or {}
|
||||
local cwd = opts.cwd or vim.loop.cwd()
|
||||
local function jump_to_line(bufnr, winid)
|
||||
local function jump_to_line(bufnr, winid, picker)
|
||||
pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns_previewer, 0, -1)
|
||||
local location = global_state.get_global_key "prompt_location"
|
||||
local location = picker:get_local_key "prompt_location"
|
||||
print(location)
|
||||
|
||||
if location and location.row > 0 then
|
||||
local highlight_range = location.col and location.col > 0 and { location.col - 1, location.col } or { 0, -1 }
|
||||
@@ -521,7 +522,7 @@ previewers.cat = defaulter(function(opts)
|
||||
return from_entry.path(entry, false)
|
||||
end,
|
||||
|
||||
define_preview = function(self, entry)
|
||||
define_preview = function(self, entry, status)
|
||||
local p = from_entry.path(entry, true)
|
||||
if p == nil or p == "" then
|
||||
return
|
||||
@@ -532,7 +533,7 @@ previewers.cat = defaulter(function(opts)
|
||||
preview = opts.preview,
|
||||
file_encoding = opts.file_encoding,
|
||||
callback = function(bufnr)
|
||||
jump_to_line(bufnr, self.state.winid)
|
||||
jump_to_line(bufnr, self.state.winid, status.picker)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user