Scrollbar Locking to Top of Page #4481
-
TLDR; Is there a way to allow the user to control the scrollbar while repeatedly updating a markdown element? Or lock it to the bottom instead of the top? Hi! I'm working on a little chat style app that gives user access to some different tools through slash commands. Some of these stream text, and I am able to stream the text (markdown) to the display above the input box as such async def on_button_pressed(self, event : Button.Pressed) -> None:
text = self.query_one(TextArea).text
md = self.query_one(Markdown)
for item in self.msg_handler.run_query(text):
await md.update(str(item)) The issue I am running into is that when the text gets larger than the page and new text is generated the scrollbar locks at the top of the text. This means new text can't be seen and I am also prevented from scrolling down to see it. This unfortunately defeats the usefulness of streaming the text. I'd love to be able to do one of the following
I'm new to textualize, but I spent some time looking through the docs/discussions/stackoverflow and was unable to find anything related to this except for the auto_scroll which appears to be for logs/hasn't worked for the markdown, unless I am doing something wrong. If you've read this far, ty! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You probably want to place the Seems you're building something very similar to something I've been playing with in terms of layout and flow (in this case a simple LLM client) and you can see I'm essentially doing that here. |
Beta Was this translation helpful? Give feedback.
-
This code might also help. It implements the "sticky" logic you're looking for, where the chat will keep scrolling to the bottom, but if the user scrolls away, it'll stop. |
Beta Was this translation helpful? Give feedback.
-
Thank you both! Excited to try out these tonight after work. |
Beta Was this translation helpful? Give feedback.
You probably want to place the
Markdown
inside aVerticalScroll
and then, after eachupdate
of theMarkdown
(which you shouldawait
, which you are doing now), call thescroll_end
method of theVerticalScroll
.Seems you're building something very similar to something I've been playing with in terms of layout and flow (in this case a simple LLM client) and you can see I'm essentially doing that here.