mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
fix(ui): special handling for floats closed before VimEnter. Seems that WinClosed events dont execute before that. Fixes #1390
This commit is contained in:
parent
d37a76b871
commit
eefb8974d6
3 changed files with 89 additions and 26 deletions
|
@ -98,6 +98,36 @@ function M.throttle(ms, fn)
|
|||
end
|
||||
end
|
||||
|
||||
--- Creates a weak reference to an object.
|
||||
--- Calling the returned function will return the object if it has not been garbage collected.
|
||||
---@generic T: table
|
||||
---@param obj T
|
||||
---@return T|fun():T?
|
||||
function M.weak(obj)
|
||||
local weak = { _obj = obj }
|
||||
---@return table<any, any>
|
||||
local function get()
|
||||
local ret = rawget(weak, "_obj")
|
||||
return ret == nil and error("Object has been garbage collected", 2) or ret
|
||||
end
|
||||
local mt = {
|
||||
__mode = "v",
|
||||
__call = function(t)
|
||||
return rawget(t, "_obj")
|
||||
end,
|
||||
__index = function(_, k)
|
||||
return get()[k]
|
||||
end,
|
||||
__newindex = function(_, k, v)
|
||||
get()[k] = v
|
||||
end,
|
||||
__pairs = function()
|
||||
return pairs(get())
|
||||
end,
|
||||
}
|
||||
return setmetatable(weak, mt)
|
||||
end
|
||||
|
||||
---@class LazyCmdOptions: LazyFloatOptions
|
||||
---@field cwd? string
|
||||
---@field env? table<string,string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue