mirror of
https://github.com/NotAShelf/specs.nvim.git
synced 2024-12-27 21:22:24 +00:00
Huge speed boost: reduced calls to vim.api when fading/resizing
This commit is contained in:
parent
f831f471fd
commit
432fb1195e
1 changed files with 35 additions and 31 deletions
|
@ -16,62 +16,67 @@ function M.on_cursor_moved()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.show_specs()
|
function M.show_specs()
|
||||||
|
|
||||||
local row = vim.fn.winline()-1
|
|
||||||
local col = vim.fn.wincol()
|
|
||||||
local bufh = vim.api.nvim_create_buf(false, true)
|
local bufh = vim.api.nvim_create_buf(false, true)
|
||||||
local win_id = vim.api.nvim_open_win(bufh, false, {
|
local win_id = vim.api.nvim_open_win(bufh, false, {
|
||||||
relative='win',
|
relative='win',
|
||||||
width = opts.popup.width*2 + 1,
|
width = 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
col = col,
|
col = vim.fn.wincol()-1,
|
||||||
row = row,
|
row = vim.fn.winline()-1,
|
||||||
style = 'minimal'
|
style = 'minimal'
|
||||||
})
|
})
|
||||||
vim.api.nvim_win_set_option(win_id, "winblend", opts.popup.blend)
|
|
||||||
|
|
||||||
local can_fade = true
|
local cnt = 0
|
||||||
local can_resize = true
|
|
||||||
local timer = vim.loop.new_timer()
|
local timer = vim.loop.new_timer()
|
||||||
vim.loop.timer_start(timer, opts.popup.delay_ms, opts.popup.inc_ms, vim.schedule_wrap(function()
|
vim.loop.timer_start(timer, opts.popup.delay_ms, opts.popup.inc_ms, vim.schedule_wrap(function()
|
||||||
if vim.api.nvim_win_is_valid(win_id) then
|
if vim.api.nvim_win_is_valid(win_id) then
|
||||||
if can_fade then can_fade = opts.popup.fader(win_id) end
|
local fade_done = opts.popup.fader(win_id, cnt)
|
||||||
if can_resize then can_resize = opts.popup.resizer(win_id) end
|
local resize_done = opts.popup.resizer(win_id, cnt)
|
||||||
if not (can_blend or can_resize) then
|
|
||||||
|
if fade_done or resize_done then
|
||||||
vim.loop.close(timer)
|
vim.loop.close(timer)
|
||||||
vim.api.nvim_win_close(win_id, true)
|
vim.api.nvim_win_close(win_id, true)
|
||||||
print("Timer done")
|
|
||||||
end
|
end
|
||||||
|
cnt = cnt+1
|
||||||
end
|
end
|
||||||
end))
|
end))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Used as the default fader
|
-- Used as the default fader
|
||||||
function M.linear_fader(win_id)
|
function M.linear_fader(win_id, cnt)
|
||||||
local blend = vim.api.nvim_win_get_option(win_id, "winblend")
|
if opts.popup.blend+cnt < 100 then
|
||||||
vim.api.nvim_win_set_option(win_id, "winblend", blend+1)
|
vim.api.nvim_win_set_option(win_id, "winblend", opts.popup.blend+cnt)
|
||||||
return (blend+1 < 100)
|
return false
|
||||||
|
else return true end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.pulse_fader(win_id)
|
function M.pulse_fader(win_id, cnt)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- function M.exp_fader()
|
-- function M.exp_fader()
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
function M.shrink_resizer(win_id)
|
function M.shrink_resizer(win_id, cnt)
|
||||||
local config = vim.api.nvim_win_get_config(win_id)
|
if opts.popup.width-cnt > 0 then
|
||||||
config['width'] = config['width']-1
|
local config = {
|
||||||
config['col'][false] = vim.fn.wincol()-config['width']/2
|
relative = "win",
|
||||||
vim.api.nvim_win_set_config(win_id, config)
|
row = vim.fn.winline()-1,
|
||||||
return (config['width']-1 > 0)
|
col = {
|
||||||
|
[false] = vim.fn.wincol()-(opts.popup.width-cnt)/2,
|
||||||
|
[true] = 3 -- temporary
|
||||||
|
},
|
||||||
|
}
|
||||||
|
vim.api.nvim_win_set_width(win_id, opts.popup.width-cnt)
|
||||||
|
vim.api.nvim_win_set_config(win_id, config)
|
||||||
|
return false
|
||||||
|
else return true end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.slide_resizer(win_id)
|
function M.slide_resizer(win_id, cnt)
|
||||||
local config = vim.api.nvim_win_get_config(win_id)
|
if opts.popup.width-cnt > 0 then
|
||||||
config['width'] = config['width']-1
|
vim.api.nvim_win_set_width(win_id, opts.popup.width-cnt)
|
||||||
vim.api.nvim_win_set_config(win_id, config)
|
return false
|
||||||
return (config['width']-1 > 0)
|
else return true end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- function M.exp_resizer()
|
-- function M.exp_resizer()
|
||||||
|
@ -84,8 +89,7 @@ function M.setup(user_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_autocmds(opts)
|
function M.create_autocmds(opts)
|
||||||
vim.cmd("augroup Specs")
|
vim.cmd("augroup Specs") vim.cmd("autocmd!")
|
||||||
vim.cmd("autocmd!")
|
|
||||||
if opts.show_jumps then
|
if opts.show_jumps then
|
||||||
vim.cmd("silent autocmd CursorMoved * :lua require('specs').on_cursor_moved()")
|
vim.cmd("silent autocmd CursorMoved * :lua require('specs').on_cursor_moved()")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue