mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 03:41:14 +01:00
Add: Open alpha window on every new tab.
This commit is contained in:
@@ -113,11 +113,12 @@ vim.keymap.set('n', '<leader>tv', '<Cmd>split | wincmd j | terminal<CR>i', { nor
|
||||
-- In a horizontal split (right side)
|
||||
vim.keymap.set('n', '<leader>th', '<Cmd>vsplit | wincmd l | terminal<CR>i', { noremap = true, silent = true, desc = 'Open terminal in vertical split' })
|
||||
|
||||
-- [[ Create an empty buffer in a new tab ]]
|
||||
-- [[ Create an empty buffer in a new tab and open Alpha ]]
|
||||
vim.keymap.set('n', '<Leader>e', function()
|
||||
vim.cmd 'tabnew' -- create a new tab
|
||||
vim.cmd 'enew' -- create a new empty buffer in it
|
||||
end, { noremap = true, silent = true, desc = 'Create an empty buffer' })
|
||||
require('alpha').start(true) -- open Alpha dashboard in this new tab
|
||||
end, { noremap = true, silent = true, desc = 'Create a new tab' })
|
||||
|
||||
-- [[ Horizontal split with new empty buffer below ]]
|
||||
vim.keymap.set('n', '<leader>sv', function()
|
||||
|
||||
@@ -134,14 +134,32 @@ return {
|
||||
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
|
||||
local modified = vim.api.nvim_buf_get_option(buf, 'modified')
|
||||
-- PATCH: Treat Alpha dashboard as empty
|
||||
-- PATCH: Treat Alpha dashboard as empty buffer and restore normal options
|
||||
if is_alpha_buffer(buf) or (bufname == '' and buftype == '' and not modified) then
|
||||
empty_buf = buf
|
||||
vim.api.nvim_set_current_win(win)
|
||||
-- Clear Alpha buffer if it's Alpha
|
||||
if is_alpha_buffer(buf) then
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
vim.api.nvim_buf_set_option(buf, 'modifiable', true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {}) -- clear contents
|
||||
vim.api.nvim_buf_set_option(buf, 'buftype', '')
|
||||
vim.api.nvim_buf_set_option(buf, 'modified', false)
|
||||
end
|
||||
-- Open the file in this window
|
||||
vim.cmd('edit! ' .. vim.fn.fnameescape(path)) -- force edit
|
||||
-- Restore normal buffer/window options
|
||||
local normal_win_opts = {
|
||||
number = true, -- enable line numbers
|
||||
relativenumber = true, -- enable relative line numbers
|
||||
signcolumn = 'yes', -- show sign column
|
||||
cursorline = false, -- no cursorline by default
|
||||
foldenable = true, -- enable folds
|
||||
wrap = false, -- no line wrap
|
||||
spell = false, -- disable spell
|
||||
}
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
for opt, val in pairs(normal_win_opts) do
|
||||
vim.api.nvim_win_set_option(win, opt, val)
|
||||
end
|
||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,12 +56,6 @@ return {
|
||||
local actions = require 'telescope.actions'
|
||||
local action_state = require 'telescope.actions.state'
|
||||
|
||||
-- Helper function to detect Alpha dashboard buffer
|
||||
local function is_alpha_buffer(buf)
|
||||
local ft = vim.api.nvim_buf_get_option(buf, 'filetype')
|
||||
return ft == 'alpha'
|
||||
end
|
||||
|
||||
local function smart_open(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry()
|
||||
if not entry then
|
||||
@@ -93,16 +87,34 @@ return {
|
||||
local name = vim.api.nvim_buf_get_name(buf)
|
||||
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
|
||||
local modified = vim.api.nvim_buf_get_option(buf, 'modified')
|
||||
local ft = vim.api.nvim_buf_get_option(buf, 'filetype')
|
||||
-- PATCH: also treat Alpha dashboard buffer as empty
|
||||
if (name == '' and buftype == '' and not modified) or is_alpha_buffer(buf) then
|
||||
if (name == '' and buftype == '' and not modified) or ft == 'alpha' then
|
||||
vim.api.nvim_set_current_win(win)
|
||||
-- DELETE Alpha buffer if it's in this window
|
||||
if is_alpha_buffer(buf) then
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
-- DELETE Alpha buffer contents if it's Alpha
|
||||
if ft == 'alpha' then
|
||||
vim.api.nvim_buf_set_option(buf, 'modifiable', true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {}) -- clear contents
|
||||
vim.api.nvim_buf_set_option(buf, 'buftype', '')
|
||||
vim.api.nvim_buf_set_option(buf, 'modified', false)
|
||||
end
|
||||
-- Now open the file in this window
|
||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||
-- Stop further processing
|
||||
vim.cmd('edit! ' .. vim.fn.fnameescape(path)) -- note the !
|
||||
|
||||
-- Restore normal buffer/window options after opening a file
|
||||
local normal_win_opts = {
|
||||
number = true, -- enable line numbers
|
||||
relativenumber = true, -- enable relative line numbers
|
||||
signcolumn = 'yes', -- show sign column
|
||||
cursorline = false, -- no cursorline by default
|
||||
foldenable = true, -- enable folds
|
||||
wrap = false, -- no line wrap
|
||||
spell = false, -- disable spell
|
||||
}
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
for opt, val in pairs(normal_win_opts) do
|
||||
vim.api.nvim_win_set_option(win, opt, val)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user