From 23b9ac6d84b6f1896ebbd1b141023be81e6bc602 Mon Sep 17 00:00:00 2001
From: Darren Burns <darrenb900@gmail.com>
Date: Tue, 17 Oct 2023 16:17:45 +0100
Subject: [PATCH] Scroll datatable cursor after refresh, since new rows may be
 measured in on_idle

---
 src/textual/widgets/_data_table.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py
index f603947130e..93cf5f4c3bb 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."""
@@ -1615,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()