From cc409f2f2b6c5428bb404fa253d70e0ff82fadd9 Mon Sep 17 00:00:00 2001 From: Max Zawisa Date: Sat, 30 Dec 2023 12:58:12 -0500 Subject: [PATCH] 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. --- lua/harpoon/ui.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index ad2c359..d04441f 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -5,8 +5,10 @@ local Extensions = require("harpoon.extensions") ---@class HarpoonToggleOptions ---@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 ui_fallback_width? number ----@field ui_width_ratio? number +---@field title? string this value is directly passed to nvim_open_win +---@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 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) 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 bufnr = vim.api.nvim_create_buf(false, true) local win_id = vim.api.nvim_open_win(bufnr, true, { relative = "editor", - title = "Harpoon", + title = toggle_opts.title or "Harpoon", title_pos = toggle_opts.title_pos or "left", row = math.floor(((vim.o.lines - height) / 2) - 1), col = math.floor((vim.o.columns - width) / 2),