mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 00:21:15 +01:00
Fix: ascii_art changed when switching to old tabs
This commit is contained in:
24
init.lua
24
init.lua
@@ -388,28 +388,8 @@ require 'buffer_deleted'
|
|||||||
-- [[ Pastebin ]]
|
-- [[ Pastebin ]]
|
||||||
require('pastebin').setup()
|
require('pastebin').setup()
|
||||||
|
|
||||||
-- [[ Autocmd to refresh Alpha when switching to a tab with Alpha buffer ]]
|
-- [[ Refresh Alpha when switching to a tab to replace breakage ]]
|
||||||
vim.api.nvim_create_autocmd('TabEnter', {
|
require 'alpha_fix'
|
||||||
pattern = '*',
|
|
||||||
callback = function()
|
|
||||||
if just_created_tab then
|
|
||||||
just_created_tab = false
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local buf = vim.api.nvim_get_current_buf()
|
|
||||||
local buftype = vim.api.nvim_buf_get_option(buf, 'filetype')
|
|
||||||
if buftype == 'alpha' then
|
|
||||||
vim.schedule(function()
|
|
||||||
local alpha_loaded, alpha = pcall(require, 'alpha')
|
|
||||||
if not alpha_loaded then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
vim.cmd 'enew'
|
|
||||||
alpha.start(true)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- The line beneath this is called `modeline`. See `:help modeline`
|
-- The line beneath this is called `modeline`. See `:help modeline`
|
||||||
-- vim: ts=2 sts=2 sw=2 et
|
-- vim: ts=2 sts=2 sw=2 et
|
||||||
|
|||||||
75
lua/alpha_fix.lua
Normal file
75
lua/alpha_fix.lua
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
-- Manages Alpha refresh when switching and preserves ASCII art
|
||||||
|
|
||||||
|
_G.alpha_tab_ascii = {}
|
||||||
|
|
||||||
|
local last_tab_count = #vim.api.nvim_list_tabpages()
|
||||||
|
|
||||||
|
-- Save ASCII art
|
||||||
|
vim.api.nvim_create_autocmd('TabLeave', {
|
||||||
|
pattern = '*',
|
||||||
|
callback = function()
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
local buftype = vim.api.nvim_buf_get_option(buf, 'filetype')
|
||||||
|
if buftype == 'alpha' then
|
||||||
|
local dashboard_loaded, dashboard = pcall(require, 'alpha.themes.dashboard')
|
||||||
|
if dashboard_loaded then
|
||||||
|
local tab = vim.api.nvim_get_current_tabpage()
|
||||||
|
-- Save the current ASCII for this tab
|
||||||
|
_G.alpha_tab_ascii[tab] = vim.deepcopy(dashboard.section.header.val)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Refresh Alpha when switching to a tab with Alpha buffer
|
||||||
|
vim.api.nvim_create_autocmd('TabEnter', {
|
||||||
|
pattern = '*',
|
||||||
|
callback = function()
|
||||||
|
local current_tab_count = #vim.api.nvim_list_tabpages()
|
||||||
|
|
||||||
|
if current_tab_count > last_tab_count then
|
||||||
|
last_tab_count = current_tab_count
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
last_tab_count = current_tab_count
|
||||||
|
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
local buftype = vim.api.nvim_buf_get_option(buf, 'filetype')
|
||||||
|
if buftype == 'alpha' then
|
||||||
|
vim.schedule(function()
|
||||||
|
local alpha_loaded, alpha = pcall(require, 'alpha')
|
||||||
|
if not alpha_loaded then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local dashboard_loaded, dashboard = pcall(require, 'alpha.themes.dashboard')
|
||||||
|
if not dashboard_loaded then
|
||||||
|
vim.cmd 'enew'
|
||||||
|
alpha.start(true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local tab = vim.api.nvim_get_current_tabpage()
|
||||||
|
|
||||||
|
if _G.alpha_tab_ascii[tab] then
|
||||||
|
dashboard.section.header.val = _G.alpha_tab_ascii[tab]
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd 'enew'
|
||||||
|
alpha.start(true)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Clean
|
||||||
|
vim.api.nvim_create_autocmd('TabClosed', {
|
||||||
|
pattern = '*',
|
||||||
|
callback = function()
|
||||||
|
local closed_tab = tonumber(vim.fn.expand '<afile>')
|
||||||
|
if closed_tab then
|
||||||
|
_G.alpha_tab_ascii[closed_tab] = nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
@@ -104,7 +104,13 @@ return {
|
|||||||
vim.api.nvim_create_autocmd('User', {
|
vim.api.nvim_create_autocmd('User', {
|
||||||
pattern = 'AlphaReady',
|
pattern = 'AlphaReady',
|
||||||
callback = function()
|
callback = function()
|
||||||
refresh_header()
|
local tab = vim.api.nvim_get_current_tabpage()
|
||||||
|
-- Only refresh if this tab doesn't have stored ASCII
|
||||||
|
if not _G.alpha_tab_ascii[tab] then
|
||||||
|
refresh_header()
|
||||||
|
local dashboard = require 'alpha.themes.dashboard'
|
||||||
|
_G.alpha_tab_ascii[tab] = vim.deepcopy(dashboard.section.header.val)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user