Skip to content

Commit 7b5d4bf

Browse files
committed
Allow custom floating window
1 parent 060a625 commit 7b5d4bf

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

lua/neogit/config.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ end
9797
---@class NeogitConfigPopup Popup window options
9898
---@field kind WindowKind The type of window that should be opened
9999

100+
---@class NeogitConfigFloating
101+
---@field relative? string
102+
---@field width? number
103+
---@field height? number
104+
---@field col? number
105+
---@field row? number
106+
---@field style? string
107+
---@field border? string
108+
100109
---@alias StagedDiffSplitKind
101110
---| "split" Open in a split
102111
---| "vsplit" Open in a vertical split
@@ -319,6 +328,7 @@ end
319328
---@field sort_branches? string Value used for `--sort` for the `git branch` command
320329
---@field initial_branch_name? string Default for new branch name prompts
321330
---@field kind? WindowKind The default type of window neogit should open in
331+
---@field floating? NeogitConfigFloating The floating window style
322332
---@field disable_line_numbers? boolean Whether to disable line numbers
323333
---@field disable_relative_line_numbers? boolean Whether to disable line numbers
324334
---@field console_timeout? integer Time in milliseconds after a console is created for long running commands
@@ -379,6 +389,13 @@ function M.get_default_values()
379389
fetch_after_checkout = false,
380390
sort_branches = "-committerdate",
381391
kind = "tab",
392+
floating = {
393+
relative = "editor",
394+
width = 0.5,
395+
height = 0.5,
396+
style = "minimal",
397+
border = "rounded",
398+
},
382399
initial_branch_name = "",
383400
disable_line_numbers = true,
384401
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)