mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Tracking row_key to row_index using internal mapping
This commit is contained in:
@@ -45,7 +45,7 @@ class StringKey:
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
# If a string is supplied, we use the hash of the string. If no string was
|
# If a string is supplied, we use the hash of the string. If no string was
|
||||||
# supplied, we use the default hash to ensure uniqueness amongst instances.
|
# supplied, we use the default hash to ensure uniqueness amongst instances.
|
||||||
return hash(self.value) if self.value is not None else super().__hash__(self)
|
return hash(self.value) if self.value is not None else id(self)
|
||||||
|
|
||||||
def __eq__(self, other: object) -> bool:
|
def __eq__(self, other: object) -> bool:
|
||||||
# Strings will match Keys containing the same string value.
|
# Strings will match Keys containing the same string value.
|
||||||
@@ -225,7 +225,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
self._row_locations: TwoWayMapping[RowKey, int] = TwoWayMapping({})
|
self._row_locations: TwoWayMapping[RowKey, int] = TwoWayMapping({})
|
||||||
|
|
||||||
# Maps y-coordinate (from top of table) to (row_index, y-coord within row) pairs
|
# Maps y-coordinate (from top of table) to (row_index, y-coord within row) pairs
|
||||||
self._y_offsets: list[tuple[RowKey, int]] = []
|
# TODO: Update types
|
||||||
|
self._y_offsets: list[tuple[int, int]] = []
|
||||||
self._row_render_cache: LRUCache[
|
self._row_render_cache: LRUCache[
|
||||||
tuple[RowKey, int, Style, int, int], tuple[SegmentLines, SegmentLines]
|
tuple[RowKey, int, Style, int, int], tuple[SegmentLines, SegmentLines]
|
||||||
]
|
]
|
||||||
@@ -539,6 +540,9 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
row_index = self.row_count
|
row_index = self.row_count
|
||||||
row_key = RowKey(key)
|
row_key = RowKey(key)
|
||||||
|
|
||||||
|
# Map the key of this row to its current index
|
||||||
|
self._row_locations[row_key] = row_index
|
||||||
|
|
||||||
self.data[row_index] = list(cells)
|
self.data[row_index] = list(cells)
|
||||||
self.rows[row_index] = Row(row_key, row_index, height, self._line_no)
|
self.rows[row_index] = Row(row_key, row_index, height, self._line_no)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user