feat: add title and ui_max_width toggle options

Add options for a custom title and max width for the UI.
Keep the same default behavior as before.
This commit is contained in:
Max Zawisa 2023-12-30 12:58:12 -05:00
parent 6afc142443
commit cc409f2f2b

View File

@ -5,8 +5,10 @@ local Extensions = require("harpoon.extensions")
---@class HarpoonToggleOptions ---@class HarpoonToggleOptions
---@field border? any this value is directly passed to nvim_open_win ---@field border? any this value is directly passed to nvim_open_win
---@field title_pos? any this value is directly passed to nvim_open_win ---@field title_pos? any this value is directly passed to nvim_open_win
---@field ui_fallback_width? number ---@field title? string this value is directly passed to nvim_open_win
---@field ui_width_ratio? number ---@field ui_fallback_width? number used if we can't get the current window
---@field ui_width_ratio? number this is the ratio of the editor window to use
---@field ui_max_width? number this is the max width the window can be
---@return HarpoonToggleOptions ---@return HarpoonToggleOptions
local function toggle_config(config) local function toggle_config(config)
@ -88,11 +90,15 @@ function HarpoonUI:_create_window(toggle_opts)
width = math.floor(win[1].width * toggle_opts.ui_width_ratio) width = math.floor(win[1].width * toggle_opts.ui_width_ratio)
end end
if toggle_opts.ui_max_width and width > toggle_opts.ui_max_width then
width = toggle_opts.ui_max_width
end
local height = 8 local height = 8
local bufnr = vim.api.nvim_create_buf(false, true) local bufnr = vim.api.nvim_create_buf(false, true)
local win_id = vim.api.nvim_open_win(bufnr, true, { local win_id = vim.api.nvim_open_win(bufnr, true, {
relative = "editor", relative = "editor",
title = "Harpoon", title = toggle_opts.title or "Harpoon",
title_pos = toggle_opts.title_pos or "left", title_pos = toggle_opts.title_pos or "left",
row = math.floor(((vim.o.lines - height) / 2) - 1), row = math.floor(((vim.o.lines - height) / 2) - 1),
col = math.floor((vim.o.columns - width) / 2), col = math.floor((vim.o.columns - width) / 2),