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:
icefed 2024-07-03 01:03:08 +08:00 committed by GitHub
parent ace46a41a1
commit b0a6cf9898
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 27 deletions

View file

@ -286,29 +286,35 @@ M.open_float = function(dir)
})
)
-- Update the window title when we switch buffers
if vim.fn.has("nvim-0.9") == 1 and config.float.border ~= "none" then
local function get_title()
local src_buf = vim.api.nvim_win_get_buf(winid)
local title = vim.api.nvim_buf_get_name(src_buf)
local scheme, path = util.parse_url(title)
if config.adapters[scheme] == "files" then
assert(path)
local fs = require("oil.fs")
title = vim.fn.fnamemodify(fs.posix_to_os_path(path), ":~")
end
return title
---Recalculate the window title for the current buffer
local function get_title()
local src_buf = vim.api.nvim_win_get_buf(winid)
local title = vim.api.nvim_buf_get_name(src_buf)
local scheme, path = util.parse_url(title)
if config.adapters[scheme] == "files" then
assert(path)
local fs = require("oil.fs")
title = vim.fn.fnamemodify(fs.posix_to_os_path(path), ":~")
end
table.insert(
autocmds,
vim.api.nvim_create_autocmd("BufWinEnter", {
desc = "Update oil floating window title when buffer changes",
pattern = "*",
callback = function(params)
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
return title
end
table.insert(
autocmds,
vim.api.nvim_create_autocmd("BufWinEnter", {
desc = "Reset local oil window options when buffer changes",
pattern = "*",
callback = function(params)
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)
vim.api.nvim_win_set_config(winid, {
relative = "editor",
@ -318,10 +324,10 @@ M.open_float = function(dir)
height = cur_win_opts.height,
title = get_title(),
})
end,
})
)
end
end
end,
})
)
vim.cmd.edit({ args = { util.escape_filename(parent_url) }, mods = { keepalt = true } })
-- :edit will set buflisted = true, but we may not want that

View file

@ -69,7 +69,7 @@ function Progress:show(opts)
border = config.progress.border,
})
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 })
end
table.insert(