Closed
Description
This is a bug report for DataTable.move_cursor
. When invoking add_row
then move_cursor
, the cursor doesn't move into view under the following conditions;
overflow-y
isauto
and the scrollbar is not yet visible.- The
add_row
andmove_cursor
is done during (or after?) dismissing a screen.
The result looks like so, with the cursor being 1 line below out of view:

The code to reproduce:
#!/usr/bin/env python
from textual.app import App, ComposeResult
from textual.screen import ModalScreen
from textual.widgets import DataTable, Footer
class ModalScreenEmpty(ModalScreen):
BINDINGS = [
("escape", "modal_cancel", "Cancel"),
]
def action_modal_cancel(self):
self.dismiss(123)
class MyApp(App):
BINDINGS = [
("q", "quit", "Quit"),
("d", "duplicate", "Duplicate, then hit Escape"),
]
def compose(self) -> ComposeResult:
yield DataTable()
yield Footer()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_column("name")
for _ in range(5):
table.add_row("Alice")
table.add_row("Bob")
def action_duplicate(self):
table = self.query_one(DataTable)
def callback(_: any):
row_key = table.add_row("Eve")
row_index = table.get_row_index(row_key)
table.move_cursor(row=row_index)
self.push_screen(ModalScreenEmpty(), callback)
app = MyApp()
app.run()
To reproduce the issue, hit D
followed by Escape
repeatedly until a line is added that is just outside of view.
Workarounds;
- Including
overflow-y: scroll;
appears to move the cursor as expected:
CSS = """
DataTable {
overflow-y: scroll;
}
"""
- Placing the
move_cursor
behind acall_after_refresh
.
Metadata
Metadata
Assignees
Labels
No labels