Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable not moving cursor into view when move_cursor invoked before scrollbar is visible in other screen #4524

Closed
SkPhilipp opened this issue May 19, 2024 · 4 comments

Comments

@SkPhilipp
Copy link

SkPhilipp commented May 19, 2024

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 is auto and the scrollbar is not yet visible.
  • The add_row and move_cursor is done during (or after?) dismissing a screen.

The result looks like so, with the cursor being 1 line below out of view:

Screenshot 2024-05-19 at 17 21 51

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;

  1. Including overflow-y: scroll; appears to move the cursor as expected:
    CSS = """
    DataTable {
        overflow-y: scroll;
    }
    """
  1. Placing the move_cursor behind a call_after_refresh.
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

I can't reproduce this. Can you test against the latest version?

@darrenburns
Copy link
Member

I'm also unable to reproduce, so closing this until we hear back or get another report.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants