Skip to content
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

ref(calendar): implemented distance (monthly view) and run make format #858

Merged
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
12 changes: 6 additions & 6 deletions lua/neorg/modules/core/ui/calendar/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.setup = function()
return {
requires = {
"core.ui",
"core.ui.calendar.views.monthly"
"core.ui.calendar.views.monthly",
},
}
end
Expand Down Expand Up @@ -35,7 +35,7 @@ module.private = {
print("Error: view not set or not available")
end,

extract_ui_info = function (buffer, window)
extract_ui_info = function(buffer, window)
local width = vim.api.nvim_win_get_width(window)
local height = vim.api.nvim_win_get_height(window)

Expand All @@ -52,15 +52,15 @@ module.private = {
}
end,

open_window = function (options)
open_window = function(options)
local buffer, window = module.required["core.ui"].create_split(
"calendar",
{},
options.height or math.floor(vim.opt.lines:get() * 0.3)
)

return buffer, window
end
end,
}

module.public = {
Expand All @@ -73,12 +73,12 @@ module.public = {
end,

create_calendar = function(buffer, window, options)
local callback_and_close = function (result)
local callback_and_close = function(result)
if options.callback ~= nil then
options.callback(result)
end

module.required['core.ui'].delete_window(buffer)
module.required["core.ui"].delete_window(buffer)
end

local mode = module.private.get_mode(options.mode, callback_and_close)
Expand Down
35 changes: 23 additions & 12 deletions lua/neorg/modules/core/ui/calendar/views/monthly.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
local module = neorg.modules.create('core.ui.calendar.views.monthly')
local module = neorg.modules.create("core.ui.calendar.views.monthly")

local function reformat_time(date)
return os.date("*t", os.time(date))
end

module.setup = function ()
module.setup = function()
return {
requires = {
'core.ui.calendar'
}
"core.ui.calendar",
},
}
end

Expand Down Expand Up @@ -168,13 +168,25 @@ module.private = {
weekdays_string_length = weekdays_string_length + (i ~= 7 and 4 or 2)
end

-- This serves as the index of this week banner extmark inside the extmark table
local absolute_offset = offset + (offset < 0 and (-offset * 100) or 0)

local extmark_position = 0

-- Calculate offset position only for the previous and following months
if offset ~= 0 then
extmark_position = (weekdays_string_length * math.abs(offset)) + (distance * math.abs(offset))
end

-- For previous months, revert the offset
if offset < 0 then
extmark_position = -extmark_position
end

local weekday_banner_id = module.private.set_decorational_extmark(
ui_info,
6,
(weekdays_string_length * offset)
+ (offset < 0 and -distance or (offset > 0 and distance or 0)) * math.abs(offset),
extmark_position,
weekdays_string_length,
weekdays,
"center",
Expand Down Expand Up @@ -295,7 +307,7 @@ module.private = {
module.private.render_month_banner(ui_info, positive_target_date, weekday_banner)
module.private.render_month(ui_info, positive_target_date, weekday_banner)

weekday_banner = module.private.render_weekday_banner(ui_info, i * -1)
weekday_banner = module.private.render_weekday_banner(ui_info, i * -1, options.distance)

local negative_target_date = reformat_time({
year = date.year,
Expand Down Expand Up @@ -511,7 +523,7 @@ module.public = {

view_name = "monthly",

setup = function (ui_info, mode, options)
setup = function(ui_info, mode, options)
options.distance = options.distance or 4

module.private.current_mode = mode
Expand Down Expand Up @@ -574,12 +586,11 @@ module.public = {
end
end, { buffer = ui_info.buffer })
end

end
end,
}

module.load = function ()
module.required['core.ui.calendar'].add_view(module.public.view_name, module.public)
module.load = function()
module.required["core.ui.calendar"].add_view(module.public.view_name, module.public)
end

return module
4 changes: 2 additions & 2 deletions lua/neorg/modules/core/ui/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.setup = function()
"text_popup",
},
requires = {
"core.ui.calendar"
}
"core.ui.calendar",
},
}
end

Expand Down