Skip to content

Allow custom floating window style #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ neogit.setup {
initial_branch_name = "",
-- Change the default way of opening neogit
kind = "tab",
-- Floating window style
floating = {
relative = "editor",
width = 0.8,
height = 0.7,
style = "minimal",
border = "rounded",
},
-- Disable line numbers
disable_line_numbers = true,
-- Disable relative line numbers
Expand Down
8 changes: 8 additions & 0 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ to Neovim users.
initial_branch_name = "",
-- Change the default way of opening neogit
kind = "tab",
-- Floating window style
floating = {
relative = "editor",
width = 0.8,
height = 0.7,
style = "minimal",
border = "rounded",
},
-- Disable line numbers
disable_line_numbers = true,
-- Disable relative line numbers
Expand Down
24 changes: 24 additions & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ end
---@class NeogitConfigPopup Popup window options
---@field kind WindowKind The type of window that should be opened

---@class NeogitConfigFloating
---@field relative? string
---@field width? number
---@field height? number
---@field col? number
---@field row? number
---@field style? string
---@field border? string

---@alias StagedDiffSplitKind
---| "split" Open in a split
---| "vsplit" Open in a vertical split
Expand Down Expand Up @@ -331,6 +340,7 @@ end
---@field sort_branches? string Value used for `--sort` for the `git branch` command
---@field initial_branch_name? string Default for new branch name prompts
---@field kind? WindowKind The default type of window neogit should open in
---@field floating? NeogitConfigFloating The floating window style
---@field disable_line_numbers? boolean Whether to disable line numbers
---@field disable_relative_line_numbers? boolean Whether to disable line numbers
---@field console_timeout? integer Time in milliseconds after a console is created for long running commands
Expand Down Expand Up @@ -392,6 +402,13 @@ function M.get_default_values()
fetch_after_checkout = false,
sort_branches = "-committerdate",
kind = "tab",
floating = {
relative = "editor",
width = 0.8,
height = 0.7,
style = "minimal",
border = "rounded",
},
initial_branch_name = "",
disable_line_numbers = true,
disable_relative_line_numbers = true,
Expand Down Expand Up @@ -1136,6 +1153,13 @@ function M.validate_config()
validate_type(config.notification_icon, "notification_icon", "string")
validate_type(config.console_timeout, "console_timeout", "number")
validate_kind(config.kind, "kind")
if validate_type(config.floating, "floating", "table") then
validate_type(config.floating.relative, "relative", "string")
validate_type(config.floating.width, "width", "number")
validate_type(config.floating.height, "height", "number")
validate_type(config.floating.style, "style", "string")
validate_type(config.floating.border, "border", "string")
end
validate_type(config.disable_line_numbers, "disable_line_numbers", "boolean")
validate_type(config.disable_relative_line_numbers, "disable_relative_line_numbers", "boolean")
validate_type(config.auto_show_console, "auto_show_console", "boolean")
Expand Down
21 changes: 10 additions & 11 deletions lua/neogit/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local util = require("neogit.lib.util")

local signs = require("neogit.lib.signs")
local Ui = require("neogit.lib.ui")
local config = require("neogit.config")

local Path = require("plenary.path")

Expand Down Expand Up @@ -317,24 +318,22 @@ function Buffer:show()
elseif self.kind == "vsplit_left" then
win = api.nvim_open_win(self.handle, true, { split = "left", vertical = true })
elseif self.kind == "floating" then
-- Creates the border window
local width = config.values.floating.width
local height = config.values.floating.height
local vim_height = vim.o.lines
local vim_width = vim.o.columns

local width = math.floor(vim_width * 0.8) + 3
local height = math.floor(vim_height * 0.7)
local col = vim_width * 0.1 - 1
local row = vim_height * 0.15
width = width > 1 and width or math.floor(vim_width * width)
height = height > 1 and height or math.floor(vim_height * height)

local content_window = api.nvim_open_win(self.handle, true, {
relative = "editor",
width = width,
height = height,
col = col,
row = row,
style = "minimal",
relative = config.values.floating.relative,
border = config.values.floating.border,
style = config.values.floating.style,
col = config.values.floating.col or (vim_width - width) / 2,
row = config.values.floating.row or (vim_height - height) / 2,
focusable = true,
border = "rounded",
})

api.nvim_win_set_cursor(content_window, { 1, 0 })
Expand Down
Loading