mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
DataTable - fix crash when selection made in empty table (#1973)
This commit is contained in:
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
- Fixed bug that prevented pilot from pressing some keys https://github.com/Textualize/textual/issues/1815
|
- Fixed bug that prevented pilot from pressing some keys https://github.com/Textualize/textual/issues/1815
|
||||||
- DataTable race condition that caused crash https://github.com/Textualize/textual/pull/1962
|
- DataTable race condition that caused crash https://github.com/Textualize/textual/pull/1962
|
||||||
|
- DataTable crash when enter pressed when table is empty https://github.com/Textualize/textual/pull/1973
|
||||||
|
|
||||||
## [0.13.0] - 2023-03-02
|
## [0.13.0] - 2023-03-02
|
||||||
|
|
||||||
|
|||||||
@@ -1975,6 +1975,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
"""Post the appropriate message for a selection based on the `cursor_type`."""
|
"""Post the appropriate message for a selection based on the `cursor_type`."""
|
||||||
cursor_coordinate = self.cursor_coordinate
|
cursor_coordinate = self.cursor_coordinate
|
||||||
cursor_type = self.cursor_type
|
cursor_type = self.cursor_type
|
||||||
|
if len(self._data) == 0:
|
||||||
|
return
|
||||||
cell_key = self.coordinate_to_cell_key(cursor_coordinate)
|
cell_key = self.coordinate_to_cell_key(cursor_coordinate)
|
||||||
if cursor_type == "cell":
|
if cursor_type == "cell":
|
||||||
self.post_message(
|
self.post_message(
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from rich.style import Style
|
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
from textual._wait import wait_for_idle
|
from textual._wait import wait_for_idle
|
||||||
from textual.actions import SkipAction
|
from textual.actions import SkipAction
|
||||||
from textual.app import App
|
from textual.app import App
|
||||||
from textual.coordinate import Coordinate
|
from textual.coordinate import Coordinate
|
||||||
from textual.events import Click, MouseMove
|
|
||||||
from textual.geometry import Offset
|
from textual.geometry import Offset
|
||||||
from textual.message import Message
|
from textual.message import Message
|
||||||
from textual.widgets import DataTable
|
from textual.widgets import DataTable
|
||||||
@@ -166,6 +164,13 @@ async def test_datatable_message_emission():
|
|||||||
assert app.message_names == expected_messages
|
assert app.message_names == expected_messages
|
||||||
|
|
||||||
|
|
||||||
|
async def test_empty_table_interactions():
|
||||||
|
app = DataTableApp()
|
||||||
|
async with app.run_test() as pilot:
|
||||||
|
await pilot.press("enter", "up", "down", "left", "right")
|
||||||
|
assert app.message_names == []
|
||||||
|
|
||||||
|
|
||||||
async def test_add_rows():
|
async def test_add_rows():
|
||||||
app = DataTableApp()
|
app = DataTableApp()
|
||||||
async with app.run_test():
|
async with app.run_test():
|
||||||
|
|||||||
Reference in New Issue
Block a user