Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not close preview when cd into dir #277

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ M.select = function(opts, callback)
vim.api.nvim_win_close(preview_win, true)
end
local prev_win = vim.api.nvim_get_current_win()
local keep_preview_alive
lucaseras marked this conversation as resolved.
Show resolved Hide resolved

local scheme, dir = util.parse_url(bufname)
assert(scheme and dir)
Expand Down Expand Up @@ -602,6 +603,14 @@ M.select = function(opts, callback)
vim.bo[filebufnr].buflisted = true
end

-- If a preview window is open, and we are selecting a directory,
-- persist the preview window
if not opts.preview and preview_win then
if vim.endswith(normalized_url, "/") then
keep_preview_alive = true
end
end

local cmd
if opts.preview and preview_win then
vim.api.nvim_set_current_win(preview_win)
Expand Down Expand Up @@ -643,6 +652,9 @@ M.select = function(opts, callback)
M.close()
end)
end
if keep_preview_alive then
M.select({preview = true})
end
lucaseras marked this conversation as resolved.
Show resolved Hide resolved
finish()
end)
end
Expand Down
25 changes: 25 additions & 0 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,31 @@ M.initialize = function(bufnr)
end,
})

vim.api.nvim_create_autocmd("BufWinEnter", {
desc = "Update preview window when displaying a buffer",
group = "Oil",
buffer = bufnr,
callback = function()
local oil = require("oil")
if vim.wo.previewwindow then
return
end

if vim.api.nvim_get_current_buf() ~= bufnr then
return
end
local entry = oil.get_cursor_entry()
if entry then
local preview_win_id = util.get_preview_win()
if preview_win_id then
if entry.id ~= vim.w[preview_win_id].oil_entry_id then
oil.select({ preview = true })
end
end
end
end,
})

lucaseras marked this conversation as resolved.
Show resolved Hide resolved
-- Watch for TextChanged and update the trash original path extmarks
local adapter = util.get_adapter(bufnr)
if adapter and adapter.name == "trash" then
Expand Down
Loading