move tabufline related functions to ui repo

This commit is contained in:
siduck 2022-09-15 07:51:13 +05:30
parent 97062ae15f
commit 83572cc15b
3 changed files with 11 additions and 78 deletions

View file

@ -59,14 +59,6 @@ M.general = {
-- new buffer
["<leader>b"] = { "<cmd> enew <CR>", "new buffer" },
-- close buffer + hide terminal buffer
["<leader>x"] = {
function()
require("core.utils").close_buffer()
end,
"close buffer",
},
},
t = { ["<C-x>"] = { termcodes "<C-\\><C-N>", "escape terminal mode" } },
@ -92,20 +84,28 @@ M.tabufline = {
-- cycle through buffers
["<TAB>"] = {
function()
require("core.utils").tabuflineNext()
require("nvchad_ui.tabufline").tabuflineNext()
end,
"goto next buffer",
},
["<S-Tab>"] = {
function()
require("core.utils").tabuflinePrev()
require("nvchad_ui.tabufline").tabuflinePrev()
end,
"goto prev buffer",
},
-- pick buffers via numbers
["<Bslash>"] = { "<cmd> TbufPick <CR>", "Pick buffer" },
-- close buffer + hide terminal buffer
["<leader>x"] = {
function()
require("nvchad_ui.tabufline").close_buffer()
end,
"close buffer",
},
},
}

View file

@ -1,18 +1,6 @@
local M = {}
local api = vim.api
local merge_tb = vim.tbl_deep_extend
M.close_buffer = function(bufnr)
if vim.bo.buftype == "terminal" then
vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
else
bufnr = bufnr or api.nvim_get_current_buf()
require("core.utils").tabuflinePrev()
vim.cmd("confirm bd" .. bufnr)
end
end
M.load_config = function()
local config = require "core.default_config"
local chadrc_exists, chadrc = pcall(require, "custom.chadrc")
@ -201,59 +189,4 @@ M.packer_sync = function(...)
end
end
M.bufilter = function()
local bufs = vim.t.bufs or nil
if not bufs then
return {}
end
for i = #bufs, 1, -1 do
if not vim.api.nvim_buf_is_valid(bufs[i]) then
table.remove(bufs, i)
end
end
return bufs
end
M.tabuflineNext = function()
local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
vim.cmd(i == #bufs and "b" .. bufs[1] or "b" .. bufs[i + 1])
break
end
end
end
M.tabuflinePrev = function()
local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
vim.cmd(i == 1 and "b" .. bufs[#bufs] or "b" .. bufs[i - 1])
break
end
end
end
-- closes tab + all of its buffers
M.closeAllBufs = function(action)
local bufs = vim.t.bufs
if action == "closeTab" then
vim.cmd "tabclose"
end
for _, buf in ipairs(bufs) do
M.close_buffer(buf)
end
if action ~= "closeTab" then
vim.cmd "enew"
end
end
return M

View file

@ -195,7 +195,7 @@ local plugins = {
["folke/which-key.nvim"] = {
disable = true,
module = "which-key",
keys = { "<leader>", "\"", "'", "`" },
keys = { "<leader>", '"', "'", "`" },
config = function()
require "plugins.configs.whichkey"
end,