question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scroll_end off by one

See original GitHub issue

It looks like Widget.scroll_end() is off by one line. Here’s an app to reproduce:

from textual.app import App, ComposeResult
from textual.widgets import DataTable, Footer


class Test(App):
    BINDINGS = [("a", "add_row", "Add a row")]
    DEFAULT_CSS = """
    DataTable {
        height: 5;
    }
    """

    def compose(self) -> ComposeResult:
        rows = (
            ("1", "one"),
            ("2", "two"),
            ("3", "three"),
            ("4", "four"),
            ("5", "five"),
        )

        self.table = DataTable()
        self.table.add_columns("#", "number")
        self.table.add_rows(rows)

        yield self.table
        yield Footer()

    def action_add_row(self) -> None:
        self.table.add_row("6", "six")
        self.table.scroll_end()


Test().run()

After adding the sixth row, the DataTable scrolls to the fifth row.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rstomallencommented, Dec 6, 2022

Ah, thanks for the explanation, I changed it, thanks. Yes, it does work, albeit slowly. My end use case is a MUD/telnet client which will scroll a lot more lines, faster. I’ll play around with using the call_later callback.

Thanks again!

tom


From: Dave Pearson @.> Sent: Tuesday, December 6, 2022 9:09 AM To: Textualize/textual @.> Cc: Tom Allen @.>; Comment @.> Subject: [EXTERNAL]Re: [Textualize/textual] scroll_end off by one (Issue #1215)

self.call_later(self.body.scroll_end(animate=False, duration=0.01, easing=“linear”))

Note that what you’ve done there isn’t the same as what will suggested though. You’re passing the result of scroll_end to call_later, whereas well is passing the function scroll_end to call_later. call_laterhttps://textual.textualize.io/api/message_pump/#textual.message_pump.MessagePump.call_later takes a callback function.

Try it how Will wrote it.

— Reply to this email directly, view it on GitHubhttps://github.com/Textualize/textual/issues/1215#issuecomment-1339445570, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AVAFQFTZ6IQOBSD4YE6AZ2LWL5CLDANCNFSM6AAAAAASEAMEUU. You are receiving this because you commented.Message ID: @.***>

1reaction
lxnncommented, Nov 19, 2022

Hello

I believe because action_add_row() is synchronous, the relevant dimensions won’t have been updated by the time scroll_end() is called.

(Details: add_row() does some stuff then calls check_idle(), sending out a message which is eventually handled by DataTable.on_idle(), where the dimensions are updated.)

I’m not sure if there’s a simple way to guarantee the behavior you want, but the following worked the few times I tested it:

    async def action_add_row(self) -> None:
        self.table.add_row("6", "six")
        await asyncio.sleep(0)
        self.table.scroll_end()

Some other methods, such as Widget.mount(), return an awaitable. It could be useful if DataTable.add_row() did too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you turn off synchronous scrolling?
I'm a writer. I use Word 2010. I want to work on two different Word documents while they're displayed on one screen.
Read more >
View Side by Side in Word - Instructions and Video Lesson
To turn off synchronous scrolling, click the button again. Instructions on How to Change Window Sizes When Comparing Two Documents in Word. To ......
Read more >
[TUTORIAL] How to VIEW 2 Word Docs SIDE-BY ... - YouTube
In one of the documents, click the View tab. 3. In the "Window" section, click on "View Side by Side To turn off...
Read more >
Turning Off Synchronous Scrolling - Excel Ribbon Tips
You can turn it off, on a case-by-case basis, by simply displaying the View tab of the ribbon and then clicking the Synchronous...
Read more >
disable scrolling on specific page - css - Stack Overflow
Is there any way to disable scroll on one single page? I tried to set overflow: hidden on the specific page but that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found