Skip to content

Commit

Permalink
fix(calendar): Re-center once Neovim is resized
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Sep 25, 2024
1 parent ac6e02a commit 8ead368
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lua/orgmode/objects/calendar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ local y_offset = 2 -- one border cell and one padding cell

---@return OrgPromise<OrgDate | nil>
function Calendar:open()
local opts = {
relative = 'editor',
width = width,
height = height,
style = 'minimal',
border = config.win_border,
row = vim.o.lines / 2 - (y_offset + height) / 2,
col = vim.o.columns / 2 - (x_offset + width) / 2,
title = self.title or 'Calendar',
title_pos = 'center',
}
local get_window_opts = function()
return {
relative = 'editor',
width = width,
height = height,
style = 'minimal',
border = config.win_border,
row = vim.o.lines / 2 - (y_offset + height) / 2,
col = vim.o.columns / 2 - (x_offset + width) / 2,
title = self.title or 'Calendar',
title_pos = 'center',
}
end

self.buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(self.buf, 'orgcalendar')
self.win = vim.api.nvim_open_win(self.buf, true, opts)
self.win = vim.api.nvim_open_win(self.buf, true, get_window_opts())

local calendar_augroup = vim.api.nvim_create_augroup('org_calendar', { clear = true })
vim.api.nvim_create_autocmd('BufWipeout', {
Expand All @@ -83,6 +85,16 @@ function Calendar:open()
once = true,
})

vim.api.nvim_create_autocmd('VimResized', {
buffer = self.buf,
group = calendar_augroup,
callback = function()
if self.win then
vim.api.nvim_win_set_config(self.win, get_window_opts())
end
end,
})

self:render()

vim.api.nvim_set_option_value('winhl', 'Normal:Normal', { win = self.win })
Expand Down

0 comments on commit 8ead368

Please sign in to comment.