mirror of
https://github.com/aminnairi/dotfiles.git
synced 2026-09-14 15:42:14 +02:00
added dynamic window resizing of width using nvim tree
This commit is contained in:
@@ -1,3 +1,78 @@
|
|||||||
|
local function use_nvim_tree_width(options)
|
||||||
|
if type(options) ~= "table" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type number
|
||||||
|
local offset = options.offset
|
||||||
|
|
||||||
|
---@type number
|
||||||
|
local initial_width = options.initial_width
|
||||||
|
|
||||||
|
local initial_width_type = type(initial_width)
|
||||||
|
|
||||||
|
local on_width_updated = options.on_width_updated
|
||||||
|
|
||||||
|
if type(on_width_updated) ~= "function" then
|
||||||
|
on_width_updated = function() end
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(offset) ~= "number" then
|
||||||
|
offset = 10
|
||||||
|
end
|
||||||
|
|
||||||
|
if initial_width_type ~= "number" and initial_width_type ~= "table" then
|
||||||
|
initial_width = 30
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type number|table
|
||||||
|
local previous_width = initial_width
|
||||||
|
|
||||||
|
if initial_width_type ~= "number" then
|
||||||
|
previous_width = 30
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type number|table
|
||||||
|
local width = initial_width
|
||||||
|
|
||||||
|
local function get_width()
|
||||||
|
return width
|
||||||
|
end
|
||||||
|
|
||||||
|
local function increment_width()
|
||||||
|
if type(width) == "table" then
|
||||||
|
width = previous_width
|
||||||
|
end
|
||||||
|
|
||||||
|
local new_width = width + offset
|
||||||
|
|
||||||
|
previous_width = new_width
|
||||||
|
width = new_width
|
||||||
|
|
||||||
|
on_width_updated(new_width)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function decrement_width()
|
||||||
|
if type(width) == "table" then
|
||||||
|
width = previous_width
|
||||||
|
end
|
||||||
|
|
||||||
|
local new_width = width - offset
|
||||||
|
|
||||||
|
previous_width = new_width
|
||||||
|
width = new_width
|
||||||
|
|
||||||
|
on_width_updated(new_width)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function dynamic_width()
|
||||||
|
width = {}
|
||||||
|
on_width_updated(width)
|
||||||
|
end
|
||||||
|
|
||||||
|
return get_width, increment_width, decrement_width, dynamic_width
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"nvim-tree/nvim-tree.lua",
|
"nvim-tree/nvim-tree.lua",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
@@ -10,11 +85,19 @@ return {
|
|||||||
|
|
||||||
local nvimTreeApi = require("nvim-tree.api")
|
local nvimTreeApi = require("nvim-tree.api")
|
||||||
|
|
||||||
|
local get_width, increment_width, decrement_width, dynamic_width = use_nvim_tree_width({
|
||||||
|
offset = 5,
|
||||||
|
initial_width = 30,
|
||||||
|
on_width_updated = function(width)
|
||||||
|
vim.cmd.NvimTreeResize(width)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
require("nvim-tree").setup({
|
require("nvim-tree").setup({
|
||||||
auto_reload_on_write = true,
|
auto_reload_on_write = true,
|
||||||
sort_by = "case_sensitive",
|
sort_by = "case_sensitive",
|
||||||
view = {
|
view = {
|
||||||
width = {},
|
width = get_width,
|
||||||
},
|
},
|
||||||
filters = {
|
filters = {
|
||||||
dotfiles = false,
|
dotfiles = false,
|
||||||
@@ -30,6 +113,21 @@ return {
|
|||||||
whichKey.register({
|
whichKey.register({
|
||||||
["<leader>n"] = {
|
["<leader>n"] = {
|
||||||
name = "NvimTree",
|
name = "NvimTree",
|
||||||
|
w = {
|
||||||
|
name = "NvimTree Width",
|
||||||
|
i = {
|
||||||
|
increment_width,
|
||||||
|
"Increment NvimTree Width"
|
||||||
|
},
|
||||||
|
d = {
|
||||||
|
decrement_width,
|
||||||
|
"Increment NvimTree Width"
|
||||||
|
},
|
||||||
|
a = {
|
||||||
|
dynamic_width,
|
||||||
|
"Automatic NvimTree Width"
|
||||||
|
}
|
||||||
|
},
|
||||||
t = {
|
t = {
|
||||||
function()
|
function()
|
||||||
nvimTreeApi.tree.toggle()
|
nvimTreeApi.tree.toggle()
|
||||||
|
|||||||
Reference in New Issue
Block a user