diff --git a/CHANGELOG.md b/CHANGELOG.md index 3843679e06..bcb6083900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `Input.cursor_blink` reactive not changing blink state after `Input` was mounted https://github.com/Textualize/textual/pull/3498 - Fixed `Tabs.active` attribute value not being re-assigned after removing a tab or clearing https://github.com/Textualize/textual/pull/3498 - Fixed `DirectoryTree` race-condition crash when changing path https://github.com/Textualize/textual/pull/3498 -- Fixed issue with LRUCache.discard https://github.com/Textualize/textual/issues/3537 +- Fixed issue with `LRUCache.discard` https://github.com/Textualize/textual/issues/3537 +- Fixed `DataTable` not scrolling to rows that were just added https://github.com/Textualize/textual/pull/3552 +- Fixed cache bug with `DataTable.update_cell` https://github.com/Textualize/textual/pull/3551 ### Changed diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index 1aa6931a4c..93cf5f4c3b 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -1116,9 +1116,10 @@ def move_cursor( cursor_row = row if column is not None: cursor_column = column + destination = Coordinate(cursor_row, cursor_column) self.cursor_coordinate = destination - self._scroll_cursor_into_view(animate=animate) + self.call_after_refresh(self._scroll_cursor_into_view, animate=animate) def _highlight_coordinate(self, coordinate: Coordinate) -> None: """Apply highlighting to the cell at the coordinate, and post event.""" @@ -1230,6 +1231,7 @@ def _update_column_widths(self, updated_cells: set[CellKey]) -> None: column = self.columns.get(column_key) if column is None: continue + console = self.app.console label_width = measure(console, column.label, 1) content_width = column.content_width @@ -1287,6 +1289,8 @@ def _update_dimensions(self, new_rows: Iterable[RowKey]) -> None: if row.auto_height: auto_height_rows.append((row_index, row, cells_in_row)) + self._clear_caches() + # If there are rows that need to have their height computed, render them correctly # so that we can cache this rendering for later. if auto_height_rows: @@ -1612,9 +1616,11 @@ def remove_row(self, row_key: RowKey | str) -> None: Raises: RowDoesNotExist: If the row key does not exist. """ + if row_key not in self._row_locations: raise RowDoesNotExist(f"Row key {row_key!r} is not valid.") + self._new_rows.discard(row_key) self._require_update_dimensions = True self.check_idle() @@ -1690,9 +1696,9 @@ async def _on_idle(self, _: events.Idle) -> None: if self._updated_cells: # Cell contents have already been updated at this point. # Now we only need to worry about measuring column widths. - updated_columns = self._updated_cells.copy() + updated_cells = self._updated_cells.copy() self._updated_cells.clear() - self._update_column_widths(updated_columns) + self._update_column_widths(updated_cells) if self._require_update_dimensions: # Add the new rows *before* updating the column widths, since