diff options
author | Christian Geier <geier@lostpackets.de> | 2023-06-07 20:41:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-07 20:41:32 +0200 |
commit | fbbd3be6b131b08f7802dfedb391532e9a52ab0e (patch) | |
tree | e192f6834d5940cdd23324c0d3f40655d186b7bc | |
parent | 9509967dcb6e734915f7c7073a4cc183159e96fb (diff) | |
parent | 9dcfa9007de3ae50fc7f3907ec5f4d70e1e93b35 (diff) |
Merge pull request #1262 from pimutils/fix/1200
fix #1200
-rw-r--r-- | CHANGELOG.rst | 1 | ||||
-rw-r--r-- | khal/ui/__init__.py | 62 | ||||
-rw-r--r-- | khal/ui/calendarwidget.py | 4 | ||||
-rw-r--r-- | tests/ui/test_calendarwidget.py | 19 |
4 files changed, 53 insertions, 33 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7b975827..53399663 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ====== diff --git a/khal/ui/__init__.py b/khal/ui/__init__.py index b05308c7..3a9f4379 100644 --- a/khal/ui/__init__.py +++ b/khal/ui/__init__.py @@ -40,37 +40,37 @@ logger = logging.getLogger('khal') # 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 diff --git a/khal/ui/calendarwidget.py b/khal/ui/calendarwidget.py index fe911dd0..da2df441 100644 --- a/khal/ui/calendarwidget.py +++ b/khal/ui/calendarwidget.py @@ -418,14 +418,14 @@ class CalendarWalker(urwid.SimpleFocusListWalker): # 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 diff --git a/tests/ui/test_calendarwidget.py b/tests/ui/test_calendarwidget.py index fdce3cbc..82a76e46 100644 --- a/tests/ui/test_calendarwidget.py +++ b/tests/ui/test_calendarwidget.py @@ -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 |