fix: set floating window win_options when buffer changes (#432)
* fix: set floating window win_options when buffer changes * fix: set win options even when float border is "none" --------- Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
This commit is contained in:
parent
ace46a41a1
commit
b0a6cf9898
2 changed files with 33 additions and 27 deletions
|
|
@ -286,29 +286,35 @@ M.open_float = function(dir)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Update the window title when we switch buffers
|
---Recalculate the window title for the current buffer
|
||||||
if vim.fn.has("nvim-0.9") == 1 and config.float.border ~= "none" then
|
local function get_title()
|
||||||
local function get_title()
|
local src_buf = vim.api.nvim_win_get_buf(winid)
|
||||||
local src_buf = vim.api.nvim_win_get_buf(winid)
|
local title = vim.api.nvim_buf_get_name(src_buf)
|
||||||
local title = vim.api.nvim_buf_get_name(src_buf)
|
local scheme, path = util.parse_url(title)
|
||||||
local scheme, path = util.parse_url(title)
|
if config.adapters[scheme] == "files" then
|
||||||
if config.adapters[scheme] == "files" then
|
assert(path)
|
||||||
assert(path)
|
local fs = require("oil.fs")
|
||||||
local fs = require("oil.fs")
|
title = vim.fn.fnamemodify(fs.posix_to_os_path(path), ":~")
|
||||||
title = vim.fn.fnamemodify(fs.posix_to_os_path(path), ":~")
|
|
||||||
end
|
|
||||||
return title
|
|
||||||
end
|
end
|
||||||
table.insert(
|
return title
|
||||||
autocmds,
|
end
|
||||||
vim.api.nvim_create_autocmd("BufWinEnter", {
|
|
||||||
desc = "Update oil floating window title when buffer changes",
|
table.insert(
|
||||||
pattern = "*",
|
autocmds,
|
||||||
callback = function(params)
|
vim.api.nvim_create_autocmd("BufWinEnter", {
|
||||||
local winbuf = params.buf
|
desc = "Reset local oil window options when buffer changes",
|
||||||
if not vim.api.nvim_win_is_valid(winid) or vim.api.nvim_win_get_buf(winid) ~= winbuf then
|
pattern = "*",
|
||||||
return
|
callback = function(params)
|
||||||
end
|
local winbuf = params.buf
|
||||||
|
if not vim.api.nvim_win_is_valid(winid) or vim.api.nvim_win_get_buf(winid) ~= winbuf then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for k, v in pairs(config.float.win_options) do
|
||||||
|
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Update the floating window title
|
||||||
|
if vim.fn.has("nvim-0.9") == 1 and config.float.border ~= "none" then
|
||||||
local cur_win_opts = vim.api.nvim_win_get_config(winid)
|
local cur_win_opts = vim.api.nvim_win_get_config(winid)
|
||||||
vim.api.nvim_win_set_config(winid, {
|
vim.api.nvim_win_set_config(winid, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
|
|
@ -318,10 +324,10 @@ M.open_float = function(dir)
|
||||||
height = cur_win_opts.height,
|
height = cur_win_opts.height,
|
||||||
title = get_title(),
|
title = get_title(),
|
||||||
})
|
})
|
||||||
end,
|
end
|
||||||
})
|
end,
|
||||||
)
|
})
|
||||||
end
|
)
|
||||||
|
|
||||||
vim.cmd.edit({ args = { util.escape_filename(parent_url) }, mods = { keepalt = true } })
|
vim.cmd.edit({ args = { util.escape_filename(parent_url) }, mods = { keepalt = true } })
|
||||||
-- :edit will set buflisted = true, but we may not want that
|
-- :edit will set buflisted = true, but we may not want that
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ function Progress:show(opts)
|
||||||
border = config.progress.border,
|
border = config.progress.border,
|
||||||
})
|
})
|
||||||
vim.bo[self.bufnr].filetype = "oil_progress"
|
vim.bo[self.bufnr].filetype = "oil_progress"
|
||||||
for k, v in pairs(config.preview.win_options) do
|
for k, v in pairs(config.progress.win_options) do
|
||||||
vim.api.nvim_set_option_value(k, v, { scope = "local", win = self.winid })
|
vim.api.nvim_set_option_value(k, v, { scope = "local", win = self.winid })
|
||||||
end
|
end
|
||||||
table.insert(
|
table.insert(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue