mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
Merge pull request #463 from maxrzaw/add-more-toggle-options
feat: add title and ui_max_width toggle options
This commit is contained in:
commit
3f51d3284e
@ -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),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user