Skip to content

Commit

Permalink
feat(calendar-ui): support count in keymappings
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas authored and vhyrro committed Jun 27, 2024
1 parent 4bcd274 commit 6b4751c
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lua/neorg/modules/core/ui/calendar/views/monthly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ module.private = {
31,
30,
31,
})[month]
})[((month - 1) % 12) + 1]
end,

is_leap_year = function(year)
Expand Down Expand Up @@ -581,12 +581,17 @@ module.public = {
view:render_view(ui_info, date, nil, options)

do
---helper to get the count multiplier
local count = function()
return (vim.v.count == 0 and 1 or vim.v.count)
end

-- TODO: Make cursor wrapping behaviour configurable
vim.keymap.set("n", "l", function()
local new_date = reformat_time({
year = date.year,
month = date.month,
day = date.day + 1,
day = date.day + 1 * count(),
})
view:render_view(ui_info, new_date, date, options)
date = new_date
Expand All @@ -596,7 +601,7 @@ module.public = {
local new_date = reformat_time({
year = date.year,
month = date.month,
day = date.day - 1,
day = date.day - 1 * count(),
})
view:render_view(ui_info, new_date, date, options)
date = new_date
Expand All @@ -606,7 +611,7 @@ module.public = {
local new_date = reformat_time({
year = date.year,
month = date.month,
day = date.day + 7,
day = date.day + 7 * count(),
})
view:render_view(ui_info, new_date, date, options)
date = new_date
Expand All @@ -616,7 +621,7 @@ module.public = {
local new_date = reformat_time({
year = date.year,
month = date.month,
day = date.day - 7,
day = date.day - 7 * count(),
})
view:render_view(ui_info, new_date, date, options)
date = new_date
Expand All @@ -637,24 +642,18 @@ module.public = {
vim.keymap.set("n", "L", function()
local new_date = reformat_time({
year = date.year,
month = date.month + 1,
month = date.month + count(),
day = date.day,
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "H", function()
local length_of_current_month = module.private.get_month_length(date.month, date.year)
local length_of_previous_month = (
date.month == 1 and module.private.get_month_length(12, date.year - 1)
or module.private.get_month_length(date.month - 1, date.year)
)

local new_date = reformat_time({
year = date.year,
month = date.month - 1,
day = date.day == length_of_current_month and length_of_previous_month or date.day,
month = date.month - count(),
day = date.day,
})
view:render_view(ui_info, new_date, date, options)
date = new_date
Expand All @@ -663,7 +662,7 @@ module.public = {
vim.keymap.set("n", "m", function()
local new_date = reformat_time({
year = date.year,
month = date.month + 1,
month = date.month + count(),
day = 1,
})
view:render_view(ui_info, new_date, date, options)
Expand All @@ -673,7 +672,7 @@ module.public = {
vim.keymap.set("n", "M", function()
local new_date = reformat_time({
year = date.year,
month = date.month - 1,
month = date.month - count(),
day = 1,
})
view:render_view(ui_info, new_date, date, options)
Expand All @@ -682,7 +681,7 @@ module.public = {

vim.keymap.set("n", "y", function()
local new_date = reformat_time({
year = date.year + 1,
year = date.year + count(),
month = date.month,
day = date.day,
})
Expand All @@ -692,7 +691,7 @@ module.public = {

vim.keymap.set("n", "Y", function()
local new_date = reformat_time({
year = date.year - 1,
year = date.year - count(),
month = date.month,
day = date.day,
})
Expand Down

0 comments on commit 6b4751c

Please sign in to comment.