Skip to content

Commit

Permalink
Merge pull request #1262 from pimutils/fix/1200
Browse files Browse the repository at this point in the history
fix #1200
  • Loading branch information
geier authored Jun 7, 2023
2 parents 9509967 + 9dcfa90 commit fbbd3be
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ not released yet
* FIX duplicating an event using `p` in ikhal
* NEW Add ability to change the minimum number of months displayed with
`min_calendar_display`
* FIX ikhal don't crash when jumping long distances in time

0.11.1
======
Expand Down
62 changes: 31 additions & 31 deletions khal/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@

# Overview of how this all meant to fit together:
#
# +--ClassicView(Pane)---------------------------------------+
# | |
# | +-CalendarWidget--+ +----EventColumn-------------------+ |
# | | | | | |
# | | | | +-DListBox---------------------+ | |
# | | | | | | | |
# | | | | | +-DayWalker----------------+ | | |
# | | | | | | | | | |
# | | | | | | +-BoxAdapter-----------+ | | | |
# | | | | | | | | | | | |
# | | | | | | | +-DateListBox------+ | | | | |
# | | | | | | | | DateHeader | | | | | |
# | | | | | | | | U_Event | | | | | |
# | | | | | | | | ... | | | | | |
# | | | | | | | | U_Event | | | | | |
# | | | | | | | +------------------+ | | | | |
# | | | | | | +----------------------+ | | | |
# | | | | | | ... | | | |
# | | | | | | +-BoxAdapter-----------+ | | | |
# | | | | | | | | | | | |
# | | | | | | | +-DateListBox------+ | | | | |
# | | | | | | | | DateHeader | | | | | |
# | | | | | | | | U_Event | | | | | |
# | | | | | | | | ... | | | | | |
# | | | | | | | | U_Event | | | | | |
# | | | | | | | +------------------+ | | | | |
# | | | | | | +----------------------+ | | | |
# | | | | | +--------------------------+ | | |
# | | | | +------------------------------+ | |
# | +-----------------+ +----------------------------------+ |
# +----------------------------------------------------------+
# ┌──ClassicView(Pane)────────────────────────────────────────┐
#
# │ ┌─CalendarWidget──┐ ┌────EventColumn───────────────────┐ │
# │ │ │ │ │ │
# │ │ │ │ ┌─DListBox─────────────────────┐ │ │
# │ │ │ │ │ │ │ │
# │ │ │ │ │ ┌─DayWalker────────────────┐ │ │ │
# │ │ │ │ │ │ │ │ │ │
# │ │ │ │ │ │ ┌─BoxAdapter───────────┐ │ │ │ │
# │ │ │ │ │ │ │ │ │ │ │ │
# │ │ │ │ │ │ │ ┌─DateListBox──────┐ │ │ │ │ │
# │ │ │ │ │ │ │ │ DateHeader │ │ │ │ │ │
# │ │ │ │ │ │ │ │ U_Event │ │ │ │ │ │
# │ │ │ │ │ │ │ │ ... │ │ │ │ │ │
# │ │ │ │ │ │ │ │ U_Event │ │ │ │ │ │
# │ │ │ │ │ │ │ └──────────────────┘ │ │ │ │ │
# │ │ │ │ │ │ └──────────────────────┘ │ │ │ │
# │ │ │ │ │ │ ... │ │ │ │
# │ │ │ │ │ │ ┌─BoxAdapter───────────┐ │ │ │ │
# │ │ │ │ │ │ │ │ │ │ │ │
# │ │ │ │ │ │ │ ┌─DateListBox──────┐ │ │ │ │ │
# │ │ │ │ │ │ │ │ DateHeader │ │ │ │ │ │
# │ │ │ │ │ │ │ │ U_Event │ │ │ │ │ │
# │ │ │ │ │ │ │ │ ... │ │ │ │ │ │
# │ │ │ │ │ │ │ │ U_Event │ │ │ │ │ │
# │ │ │ │ │ │ │ └──────────────────┘ │ │ │ │ │
# │ │ │ │ │ │ └──────────────────────┘ │ │ │ │
# │ │ │ │ │ └──────────────────────────┘ │ │ │
# │ │ │ │ └──────────────────────────────┘ │ │
# │ └─────────────────┘ └──────────────────────────────────┘ │
# └───────────────────────────────────────────────────────────┘

ALL = 1
INSTANCES = 2
Expand Down
4 changes: 2 additions & 2 deletions khal/ui/calendarwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,14 @@ def get_date_pos(self, a_day):
# will lead to an autoprepend which will f*ck up our estimation,
# therefore better autoprepending anyway, even if it might not be
# necessary
if new_focus <= 1:
while new_focus <= 1:
self._autoprepend()
week_diff = int((self.focus_date - a_day).days / 7)
new_focus = self.focus - week_diff
for offset in [0, -1, 1]: # we might be off by a week
row = new_focus + offset
try:
if row >= len(self):
while row >= len(self):
self._autoextend()
column = self[row].get_date_column(a_day)
return row, column
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/test_calendarwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,22 @@ def test_set_focus_date_weekstart_6():
day = today + dt.timedelta(days=diff)
frame.set_focus_date(day)
assert frame.focus_date == day


def test_set_focus_far_future():
future_date = dt.date.today() + dt.timedelta(days=1000)
frame = CalendarWidget(on_date_change=lambda _: None,
keybindings=keybindings,
on_press=on_press,
weeknumbers='right')
frame.set_focus_date(future_date)
assert frame.focus_date == future_date

def test_set_focus_far_past():
future_date = dt.date.today() - dt.timedelta(days=1000)
frame = CalendarWidget(on_date_change=lambda _: None,
keybindings=keybindings,
on_press=on_press,
weeknumbers='right')
frame.set_focus_date(future_date)
assert frame.focus_date == future_date

0 comments on commit fbbd3be

Please sign in to comment.