Skip to content

Commit

Permalink
Allow custom floating window
Browse files Browse the repository at this point in the history
  • Loading branch information
SheffeyG committed Jan 16, 2025
1 parent 060a625 commit 7b5d4bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
17 changes: 17 additions & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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 @@ -319,6 +328,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 @@ -379,6 +389,13 @@ function M.get_default_values()
fetch_after_checkout = false,
sort_branches = "-committerdate",
kind = "tab",
floating = {
relative = "editor",
width = 0.5,
height = 0.5,
style = "minimal",
border = "rounded",
},
initial_branch_name = "",
disable_line_numbers = true,
disable_relative_line_numbers = true,
Expand Down
23 changes: 9 additions & 14 deletions lua/neogit/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,20 @@ 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
local floating = require("neogit.config").values.floating

-- Creates the border window
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
floating.width = floating.width > 1 and floating.width or math.floor(vim_width * floating.width)
floating.height = floating.height > 1 and floating.height or math.floor(vim_height * floating.height)
floating.col = (vim_width - floating.width) / 2
-- floating.row = (vim_height - floating.height) / 2
floating.row = vim_height * 0.15
floating.focusable = true

local content_window = api.nvim_open_win(self.handle, true, {
relative = "editor",
width = width,
height = height,
col = col,
row = row,
style = "minimal",
focusable = true,
border = "rounded",
})
local content_window = api.nvim_open_win(self.handle, true, floating)

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

0 comments on commit 7b5d4bf

Please sign in to comment.