Folke Lemaitre 2024-11-18 16:25:17 +01:00 committed by GitHub
parent 063525196a
commit d540fa607c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 2506 additions and 43 deletions

View file

@ -119,11 +119,13 @@ local win_opts = {
"zindex",
}
vim.api.nvim_set_hl(0, "SnacksBackdrop", { bg = "#000000", default = true })
vim.api.nvim_set_hl(0, "SnacksNormal", { link = "NormalFloat", default = true })
vim.api.nvim_set_hl(0, "SnacksNormalNC", { link = "NormalFloat", default = true })
vim.api.nvim_set_hl(0, "SnacksWinBar", { link = "Title", default = true })
vim.api.nvim_set_hl(0, "SnacksWinBarNC", { link = "SnacksWinBar", default = true })
Snacks.util.set_hl({
Backdrop = { bg = "#000000" },
Normal = "NormalFloat",
NormalNC = "NormalFloat",
WinBar = "Title",
WinBarNC = "SnacksWinBar",
}, { prefix = "Snacks", default = true })
M.transparent = false
@ -329,8 +331,8 @@ end
function M:update()
if self:valid() then
self:set_options("buf")
self:set_options("win")
Snacks.util.bo(self.buf, self.opts.bo)
Snacks.util.wo(self.win, self.opts.wo)
if self:is_floating() then
local opts = self:win_opts()
opts.noautocmd = nil
@ -351,7 +353,7 @@ function M:show()
-- OPTIM: prevent treesitter or syntax highlighting to attach on FileType if it's not already enabled
local optim_hl = not vim.b[self.buf].ts_highlight and vim.bo[self.buf].syntax == ""
vim.b[self.buf].ts_highlight = optim_hl or vim.b[self.buf].ts_highlight
self:set_options("buf")
Snacks.util.bo(self.buf, self.opts.bo)
vim.b[self.buf].ts_highlight = not optim_hl and vim.b[self.buf].ts_highlight or nil
if self.opts.on_buf then
@ -362,7 +364,7 @@ function M:show()
if M.transparent then
self.opts.wo.winblend = 0
end
self:set_options("win")
Snacks.util.wo(self.win, self.opts.wo)
if self.opts.on_win then
self.opts.on_win(self)
end
@ -540,26 +542,6 @@ function M:border_text_width()
return ret
end
---@private
---@param type "win" | "buf"
function M:set_options(type)
local opts = type == "win" and self.opts.wo or self.opts.bo
---@diagnostic disable-next-line: no-unknown
for k, v in pairs(opts or {}) do
---@diagnostic disable-next-line: no-unknown
local ok, err = pcall(vim.api.nvim_set_option_value, k, v, type == "win" and {
scope = "local",
win = self.win,
} or { buf = self.buf })
if not ok then
Snacks.notify.error(
"Error setting option `" .. tostring(k) .. "=" .. tostring(v) .. "`\n\n" .. err,
{ title = "Snacks Float" }
)
end
end
end
function M:buf_valid()
return self.buf and vim.api.nvim_buf_is_valid(self.buf)
end