Skip to content

Commit

Permalink
fix title cyle between list and tree views
Browse files Browse the repository at this point in the history
  • Loading branch information
fdschmidt93 committed Oct 25, 2023
1 parent a8472f6 commit 8957ede
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
20 changes: 14 additions & 6 deletions lua/telescope/_extensions/file_browser/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ end
local function newly_created_root(path, cwd)
local idx
local parents = path:parents()
cwd = fb_utils.trim_right_os_sep(cwd)
cwd = fb_utils.sanitize_dir(cwd, false)
for i, p in ipairs(parents) do
if p == cwd then
idx = i
Expand Down Expand Up @@ -207,7 +207,7 @@ local batch_rename = function(prompt_bufnr, selections)
local old_path = selections[idx]:absolute()
local new_path = Path:new(file):absolute()
if old_path ~= new_path then
local is_dir = selections[idx].is_dir
local is_dir = selections[idx]:is_dir()
selections[idx]:rename { new_name = new_path }
if not is_dir then
fb_utils.rename_buf(old_path, new_path)
Expand Down Expand Up @@ -297,6 +297,7 @@ fb_actions.rename = function(prompt_bufnr)

old_path:rename { new_name = new_path.filename }
if not new_path:is_dir() then
P(old_name)
fb_utils.rename_buf(old_name, new_path:absolute())
else
fb_utils.rename_dir_buf(old_name, new_path:absolute())
Expand Down Expand Up @@ -336,9 +337,16 @@ fb_actions.move = function(prompt_bufnr)
if new_path:exists() then
table.insert(skipped, filename)
else
local old_path = selection:absolute()
selection:rename {
new_name = new_path.filename,
}
if not selection:is_dir() then
fb_utils.rename_buf(old_path, new_path)
else
fb_utils.rename_dir_buf(old_path, new_path)
end
fb_utils.rename_buf(old_path, new_path:absolute())
table.insert(moved, filename)
if idx == 1 and #selections == 1 then
fb_utils.selection_callback(current_picker, new_path:absolute())
Expand Down Expand Up @@ -393,7 +401,7 @@ fb_actions.copy = function(prompt_bufnr)
local selection, name, destination, exists
while index <= #selections do
selection = selections[index]
local is_dir = selection.is_dir
local is_dir = selection:is_dir()
local absolute = selection:absolute()
name = table.remove(selection:_split())
destination = Path:new {
Expand Down Expand Up @@ -477,7 +485,7 @@ fb_actions.remove = function(prompt_bufnr)
end, selections)

for _, sel in ipairs(selections) do
if sel.is_dir then
if sel:is_dir() then
local abs = sel:absolute()
local msg
if finder.files and Path:new(finder.path):parent():absolute() == abs then
Expand Down Expand Up @@ -609,7 +617,7 @@ end
fb_actions.change_cwd = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local finder = current_picker.finder
local entry_path = action_state.get_selected_entry().Path
local entry_path = Path:new(fb_utils.sanitize_dir(action_state.get_selected_entry(), false))
finder.path = entry_path:is_dir() and entry_path:absolute() or entry_path:parent():absolute()
finder.cwd = finder.path
vim.cmd("cd " .. finder.path)
Expand Down Expand Up @@ -790,7 +798,7 @@ fb_actions.toggle_opts = function(prompt_bufnr)
relative = "win",
row = 1,
col = vim.o.columns - 30,
width = vim.o.columns,
width = 30,
height = #KEYS + 1,
zindex = 200,
style = "minimal",
Expand Down
14 changes: 9 additions & 5 deletions lua/telescope/_extensions/file_browser/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,24 @@ fb_picker.file_browser = function(opts)

local select_buffer = opts.select_buffer
-- handle case that current buffer is a hidden file
opts.hidden = (select_buffer and vim.fn.expand("%:p:t"):sub(1, 1) == ".") and true or opts.hidden
if select_buffer then
opts.select_buffer = vim.api.nvim_buf_get_name(0)
local stat = vim.loop.fs_stat(opts.select_buffer)
if not stat or (stat and stat.type ~= "file") then
opts.select_buffer = nil
select_buffer = false
opts.hidden = (select_buffer and vim.fn.expand("%:p:t"):sub(1, 1) == ".") and true or opts.hidden
end
end
opts.finder = fb_finder.finder(opts)
-- find index of current buffer in the results
if select_buffer then
local buf_name = vim.api.nvim_buf_get_name(0)
fb_utils.selection_callback(opts, buf_name)
if select_buffer and opts.select_buffer then
fb_utils.selection_callback(opts, opts.select_buffer)
end

pickers
.new(opts, {
prompt_title = "Browser",
prompt_title = opts.initial_browser == "tree" and "Tree Browser" or "File Browser",
results_title = Path:new(opts.path):make_relative(cwd) .. os_sep,
prompt_prefix = fb_utils.relative_path_prefix(opts.finder),
previewer = conf.file_previewer(opts),
Expand Down
5 changes: 3 additions & 2 deletions lua/telescope/_extensions/file_browser/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ fb_utils.is_dir = function(path)
end

-- TODO(fdschmidt93): support multi-selections better usptream
---@return table table of plenary.path objects for multi-selections
fb_utils.get_selected_files = function(prompt_bufnr, smart)
smart = vim.F.if_nil(smart, true)
local selected = {}
local current_picker = action_state.get_current_picker(prompt_bufnr)
local selections = current_picker:get_multi_selection()
if smart and vim.tbl_isempty(selections) then
Expand Down Expand Up @@ -156,7 +156,8 @@ end
fb_utils.redraw_border_title = function(current_picker)
local finder = current_picker.finder
if current_picker.prompt_border and not finder.prompt_title then
local new_title = finder.is_tree and "File Browser" or "Tree Browser"
local browser_opts = finder.browser_opts[finder.browser]
local new_title = browser_opts.is_tree and "Tree Browser" or "File Browser"
current_picker.prompt_border:change_title(new_title)
end
if current_picker.results_border and not finder.results_title then
Expand Down

0 comments on commit 8957ede

Please sign in to comment.