Skip to content

Commit 866813d

Browse files
SheffeyGCKolkey
authored andcommitted
Allow custom floating window
1 parent 141362b commit 866813d

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

lua/neogit/config.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ end
102102
---@class NeogitConfigPopup Popup window options
103103
---@field kind WindowKind The type of window that should be opened
104104

105+
---@class NeogitConfigFloating
106+
---@field relative? string
107+
---@field width? number
108+
---@field height? number
109+
---@field col? number
110+
---@field row? number
111+
---@field style? string
112+
---@field focusable? boolean
113+
---@field border? string
114+
105115
---@alias StagedDiffSplitKind
106116
---| "split" Open in a split
107117
---| "vsplit" Open in a vertical split
@@ -331,6 +341,7 @@ end
331341
---@field sort_branches? string Value used for `--sort` for the `git branch` command
332342
---@field initial_branch_name? string Default for new branch name prompts
333343
---@field kind? WindowKind The default type of window neogit should open in
344+
---@field floating? NeogitConfigFloating The floating window style
334345
---@field disable_line_numbers? boolean Whether to disable line numbers
335346
---@field disable_relative_line_numbers? boolean Whether to disable line numbers
336347
---@field console_timeout? integer Time in milliseconds after a console is created for long running commands
@@ -392,6 +403,13 @@ function M.get_default_values()
392403
fetch_after_checkout = false,
393404
sort_branches = "-committerdate",
394405
kind = "tab",
406+
floating = {
407+
relative = "editor",
408+
width = 0.5,
409+
height = 0.5,
410+
style = "minimal",
411+
border = "rounded",
412+
},
395413
initial_branch_name = "",
396414
disable_line_numbers = true,
397415
disable_relative_line_numbers = true,

lua/neogit/lib/buffer.lua

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,20 @@ function Buffer:show()
317317
elseif self.kind == "vsplit_left" then
318318
win = api.nvim_open_win(self.handle, true, { split = "left", vertical = true })
319319
elseif self.kind == "floating" then
320+
local floating = require("neogit.config").values.floating
321+
320322
-- Creates the border window
321323
local vim_height = vim.o.lines
322324
local vim_width = vim.o.columns
323325

324-
local width = math.floor(vim_width * 0.8) + 3
325-
local height = math.floor(vim_height * 0.7)
326-
local col = vim_width * 0.1 - 1
327-
local row = vim_height * 0.15
326+
floating.width = floating.width > 1 and floating.width or math.floor(vim_width * floating.width)
327+
floating.height = floating.height > 1 and floating.height or math.floor(vim_height * floating.height)
328+
floating.col = (vim_width - floating.width) / 2
329+
-- floating.row = (vim_height - floating.height) / 2
330+
floating.row = vim_height * 0.15
331+
floating.focusable = true
328332

329-
local content_window = api.nvim_open_win(self.handle, true, {
330-
relative = "editor",
331-
width = width,
332-
height = height,
333-
col = col,
334-
row = row,
335-
style = "minimal",
336-
focusable = true,
337-
border = "rounded",
338-
})
333+
local content_window = api.nvim_open_win(self.handle, true, floating)
339334

340335
api.nvim_win_set_cursor(content_window, { 1, 0 })
341336
win = content_window

0 commit comments

Comments
 (0)