Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8ead368

Browse files
fix(calendar): Re-center once Neovim is resized
1 parent ac6e02a commit 8ead368

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

lua/orgmode/objects/calendar.lua

+24-12
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,23 @@ local y_offset = 2 -- one border cell and one padding cell
5757

5858
---@return OrgPromise<OrgDate | nil>
5959
function Calendar:open()
60-
local opts = {
61-
relative = 'editor',
62-
width = width,
63-
height = height,
64-
style = 'minimal',
65-
border = config.win_border,
66-
row = vim.o.lines / 2 - (y_offset + height) / 2,
67-
col = vim.o.columns / 2 - (x_offset + width) / 2,
68-
title = self.title or 'Calendar',
69-
title_pos = 'center',
70-
}
60+
local get_window_opts = function()
61+
return {
62+
relative = 'editor',
63+
width = width,
64+
height = height,
65+
style = 'minimal',
66+
border = config.win_border,
67+
row = vim.o.lines / 2 - (y_offset + height) / 2,
68+
col = vim.o.columns / 2 - (x_offset + width) / 2,
69+
title = self.title or 'Calendar',
70+
title_pos = 'center',
71+
}
72+
end
7173

7274
self.buf = vim.api.nvim_create_buf(false, true)
7375
vim.api.nvim_buf_set_name(self.buf, 'orgcalendar')
74-
self.win = vim.api.nvim_open_win(self.buf, true, opts)
76+
self.win = vim.api.nvim_open_win(self.buf, true, get_window_opts())
7577

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

88+
vim.api.nvim_create_autocmd('VimResized', {
89+
buffer = self.buf,
90+
group = calendar_augroup,
91+
callback = function()
92+
if self.win then
93+
vim.api.nvim_win_set_config(self.win, get_window_opts())
94+
end
95+
end,
96+
})
97+
8698
self:render()
8799

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

0 commit comments

Comments
 (0)