Skip to content

Commit

Permalink
fix performance issues using set_reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed May 24, 2024
1 parent 6d56462 commit f4549ca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/textual/widgets/_month_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ def _on_datatable_cell_highlighted(
table.cursor_coordinate = date_coordinate
else:
cursor_row, cursor_column = event.coordinate
highlighted_date = self._calendar_dates[cursor_row][cursor_column]
assert isinstance(highlighted_date, datetime.date)
self.date = highlighted_date
new_date = self._calendar_dates[cursor_row][cursor_column]
assert isinstance(new_date, datetime.date)
# Avoid possible race condition by setting the `date` reactive
# without invoking the watcher. When mashing the arrow keys, this
# otherwise would cause the app to lag or freeze entirely.
old_date = self.date
self.set_reactive(MonthCalendar.date, new_date)
if (new_date.month != old_date.month) or (new_date.year != old_date.year):
self._calendar_dates = self._get_calendar_dates()
self._update_calendar_table(update_week_header=False)

self.post_message(MonthCalendar.DateHighlighted(self, self.date))

@on(DataTable.CellSelected)
Expand Down

0 comments on commit f4549ca

Please sign in to comment.