Skip to content

Commit f56d490

Browse files
authored
Merge pull request #1641 from SheffeyG/feat-custom-float-window
2 parents 141362b + 3ceaa8c commit f56d490

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ neogit.setup {
128128
initial_branch_name = "",
129129
-- Change the default way of opening neogit
130130
kind = "tab",
131+
-- Floating window style
132+
floating = {
133+
relative = "editor",
134+
width = 0.8,
135+
height = 0.7,
136+
style = "minimal",
137+
border = "rounded",
138+
},
131139
-- Disable line numbers
132140
disable_line_numbers = true,
133141
-- Disable relative line numbers

doc/neogit.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ to Neovim users.
155155
initial_branch_name = "",
156156
-- Change the default way of opening neogit
157157
kind = "tab",
158+
-- Floating window style
159+
floating = {
160+
relative = "editor",
161+
width = 0.8,
162+
height = 0.7,
163+
style = "minimal",
164+
border = "rounded",
165+
},
158166
-- Disable line numbers
159167
disable_line_numbers = true,
160168
-- Disable relative line numbers

lua/neogit/config.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ 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 border? string
113+
105114
---@alias StagedDiffSplitKind
106115
---| "split" Open in a split
107116
---| "vsplit" Open in a vertical split
@@ -331,6 +340,7 @@ end
331340
---@field sort_branches? string Value used for `--sort` for the `git branch` command
332341
---@field initial_branch_name? string Default for new branch name prompts
333342
---@field kind? WindowKind The default type of window neogit should open in
343+
---@field floating? NeogitConfigFloating The floating window style
334344
---@field disable_line_numbers? boolean Whether to disable line numbers
335345
---@field disable_relative_line_numbers? boolean Whether to disable line numbers
336346
---@field console_timeout? integer Time in milliseconds after a console is created for long running commands
@@ -392,6 +402,13 @@ function M.get_default_values()
392402
fetch_after_checkout = false,
393403
sort_branches = "-committerdate",
394404
kind = "tab",
405+
floating = {
406+
relative = "editor",
407+
width = 0.8,
408+
height = 0.7,
409+
style = "minimal",
410+
border = "rounded",
411+
},
395412
initial_branch_name = "",
396413
disable_line_numbers = true,
397414
disable_relative_line_numbers = true,
@@ -1136,6 +1153,13 @@ function M.validate_config()
11361153
validate_type(config.notification_icon, "notification_icon", "string")
11371154
validate_type(config.console_timeout, "console_timeout", "number")
11381155
validate_kind(config.kind, "kind")
1156+
if validate_type(config.floating, "floating", "table") then
1157+
validate_type(config.floating.relative, "relative", "string")
1158+
validate_type(config.floating.width, "width", "number")
1159+
validate_type(config.floating.height, "height", "number")
1160+
validate_type(config.floating.style, "style", "string")
1161+
validate_type(config.floating.border, "border", "string")
1162+
end
11391163
validate_type(config.disable_line_numbers, "disable_line_numbers", "boolean")
11401164
validate_type(config.disable_relative_line_numbers, "disable_relative_line_numbers", "boolean")
11411165
validate_type(config.auto_show_console, "auto_show_console", "boolean")

lua/neogit/lib/buffer.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local util = require("neogit.lib.util")
55

66
local signs = require("neogit.lib.signs")
77
local Ui = require("neogit.lib.ui")
8+
local config = require("neogit.config")
89

910
local Path = require("plenary.path")
1011

@@ -317,24 +318,22 @@ function Buffer:show()
317318
elseif self.kind == "vsplit_left" then
318319
win = api.nvim_open_win(self.handle, true, { split = "left", vertical = true })
319320
elseif self.kind == "floating" then
320-
-- Creates the border window
321+
local width = config.values.floating.width
322+
local height = config.values.floating.height
321323
local vim_height = vim.o.lines
322324
local vim_width = vim.o.columns
323-
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
325+
width = width > 1 and width or math.floor(vim_width * width)
326+
height = height > 1 and height or math.floor(vim_height * height)
328327

329328
local content_window = api.nvim_open_win(self.handle, true, {
330-
relative = "editor",
331329
width = width,
332330
height = height,
333-
col = col,
334-
row = row,
335-
style = "minimal",
331+
relative = config.values.floating.relative,
332+
border = config.values.floating.border,
333+
style = config.values.floating.style,
334+
col = config.values.floating.col or (vim_width - width) / 2,
335+
row = config.values.floating.row or (vim_height - height) / 2,
336336
focusable = true,
337-
border = "rounded",
338337
})
339338

340339
api.nvim_win_set_cursor(content_window, { 1, 0 })

0 commit comments

Comments
 (0)