@@ -135,7 +135,6 @@ function Calendar:open()
135135 self :set_time ()
136136 end , map_opts )
137137 if self :has_time () then
138- print (' apply clear_time' )
139138 vim .keymap .set (' n' , ' T' , function ()
140139 self :clear_time ()
141140 end , map_opts )
@@ -206,7 +205,7 @@ function Calendar:render()
206205 if self .select_state == SelState .DAY then
207206 table.insert (content , ' [t] - enter time [T] - clear time' )
208207 else
209- table.insert (content , ' [d] - enter time [T] - clear time' )
208+ table.insert (content , ' [d] - select day [T] - clear time' )
210209 end
211210 else
212211 table.insert (content , ' [t] - enter time' )
@@ -314,7 +313,15 @@ function Calendar:has_time()
314313 return not self .date .date_only
315314end
316315
316+ --- @private
317+ function Calendar :_ensure_day ()
318+ if self .select_state ~= SelState .DAY then
319+ self :set_day ()
320+ end
321+ end
322+
317323function Calendar :forward ()
324+ self :_ensure_day ()
318325 self .month = self .month :add ({ month = vim .v .count1 })
319326 self :render ()
320327 vim .fn .cursor (2 , 1 )
@@ -323,6 +330,7 @@ function Calendar:forward()
323330end
324331
325332function Calendar :backward ()
333+ self :_ensure_day ()
326334 self .month = self .month :subtract ({ month = vim .v .count1 })
327335 self :render ()
328336 vim .fn .cursor (vim .fn .line (' $' ), 0 )
@@ -490,6 +498,7 @@ function Calendar:cursor_down()
490498end
491499
492500function Calendar :reset ()
501+ self :_ensure_day ()
493502 local today = self .month :set_todays_date ()
494503 self .month = today :set ({ day = 1 })
495504 self :render ()
@@ -556,12 +565,13 @@ function Calendar:clear_date()
556565end
557566
558567function Calendar :read_date ()
559- local default = self :get_selected_date ():to_string ()
560- vim .ui .input ({ prompt = ' Enter date: ' , default = default }, function (result )
568+ self :_ensure_day ()
569+ local current_date = self :get_selected_date ()
570+ vim .ui .input ({ prompt = ' Enter date: ' , default = current_date :to_string () }, function (result )
561571 if result then
562572 local date = Date .from_string (result )
563573 if not date then
564- date = self : get_selected_date () :adjust (result )
574+ date = current_date :adjust (result )
565575 end
566576
567577 self .date = date
0 commit comments