|
2 | 2 |
|
3 | 3 | --- @class Integration |
4 | 4 | --- @field filetype Filetype |
| 5 | +--- @field min_width? number |
5 | 6 |
|
6 | 7 | --- @class Config |
7 | 8 | --- @field main? { width: number | fun(): number; } |
8 | 9 | --- @field top? Integration[] |
9 | | ---- @field right? { min_width?: number; [number]: Integration[]} |
| 10 | +--- @field right? Integration[] |
10 | 11 | --- @field bottom? Integration[] |
11 | | ---- @field left? { min_width?: number; [number]: Integration[]} |
| 12 | +--- @field left? Integration[] |
12 | 13 |
|
13 | 14 | --- @class ConfigOptions |
14 | 15 | --- @field main { width: number | fun(): number; } |
15 | 16 | --- @field top Integration[] |
16 | | ---- @field right { min_width: number; [number]: Integration[]} |
| 17 | +--- @field right Integration[] |
17 | 18 | --- @field bottom Integration[] |
18 | | ---- @field left { min_width: number; [number]: Integration[]} |
| 19 | +--- @field left Integration[] |
19 | 20 |
|
20 | 21 | local default_width = 148 |
21 | 22 | --- @type ConfigOptions |
22 | 23 | local opts = { |
23 | 24 | main = { width = default_width }, |
24 | 25 | top = {}, |
25 | | - right = { min_width = 46 }, |
| 26 | + right = { { filetype = "*", min_width = 46 } }, |
26 | 27 | bottom = {}, |
27 | | - left = { min_width = 46 }, |
| 28 | + left = { { filetype = "*", min_width = 46 } }, |
28 | 29 | } |
29 | 30 | local state = { |
30 | 31 | [vim.api.nvim_get_current_tabpage()] = { left = nil, right = nil }, |
|
69 | 70 | ---@return boolean |
70 | 71 | local function is_filetype(target, filetype) |
71 | 72 | if type(filetype) == "string" then |
72 | | - return filetype == target |
| 73 | + return filetype ~= "*" and filetype == target |
73 | 74 | elseif type(filetype) == "table" then |
74 | 75 | return vim.tbl_contains(filetype, target) |
75 | 76 | end |
76 | 77 | return false |
77 | 78 | end |
78 | 79 |
|
| 80 | +---@param position "left" | "right" |
| 81 | +---@param filetype string |
| 82 | +---@return number |
| 83 | +local function get_min_width(position, filetype) |
| 84 | + local wildcard_width = 0 |
| 85 | + for _, integration in ipairs(opts[position]) do |
| 86 | + if type(integration) == "table" then |
| 87 | + if integration.min_width and integration.filetype ~= "*" and is_filetype(filetype, integration.filetype) then |
| 88 | + return integration.min_width |
| 89 | + end |
| 90 | + if integration.filetype == "*" and integration.min_width then |
| 91 | + wildcard_width = integration.min_width |
| 92 | + end |
| 93 | + end |
| 94 | + end |
| 95 | + return wildcard_width |
| 96 | +end |
| 97 | + |
79 | 98 | ---@return number |
80 | 99 | local function get_side_buffer(position) |
81 | 100 | local current_tabpage = vim.api.nvim_get_current_tabpage() |
@@ -262,8 +281,8 @@ local function setup(options) |
262 | 281 | for _, position in ipairs({ "right", "left" }) do |
263 | 282 | for _, integration in pairs(opts[position]) do |
264 | 283 | ---@diagnostic disable-next-line: undefined-field |
265 | | - if type(integration) == "table" and integration.filetype == filetype then |
266 | | - local new_width = math.max(opts[position].min_width, math.floor((vim.o.columns - get_main_width()) / 2)) |
| 284 | + if type(integration) == "table" and is_filetype(filetype, integration.filetype) then |
| 285 | + local new_width = math.max(get_min_width(position, filetype), math.floor((vim.o.columns - get_main_width()) / 2)) |
267 | 286 | vim.api.nvim_win_set_width(buf_info[1].windows[1], new_width) |
268 | 287 | return |
269 | 288 | end |
@@ -460,6 +479,19 @@ local function setup(options) |
460 | 479 | end |
461 | 480 | end |
462 | 481 | end |
| 482 | + |
| 483 | + if position == "left" or position == "right" then |
| 484 | + local min_width = get_min_width(position, filetype) |
| 485 | + if min_width > 0 then |
| 486 | + local win = vim.fn.bufwinid(args.buf) |
| 487 | + if win ~= -1 then |
| 488 | + local current_width = vim.api.nvim_win_get_width(win) |
| 489 | + if current_width < min_width then |
| 490 | + vim.api.nvim_win_set_width(win, min_width) |
| 491 | + end |
| 492 | + end |
| 493 | + end |
| 494 | + end |
463 | 495 | end |
464 | 496 | end |
465 | 497 | end |
|
0 commit comments