From 312e5bc276b426b59fd31fe9c4534ec9909f6a1a Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 24 Jul 2025 21:32:59 +0100 Subject: [PATCH 1/2] Stream fix --- src/textual/widgets/_markdown.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index bd869069ca..67cf074835 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -88,6 +88,7 @@ async def write(self, markdown_fragment: str) -> None: # Append the new fragment, and set an event to tell the _run loop to wake up self._pending.append(markdown_fragment) self._new_markup.set() + await asyncio.sleep(0) async def _run(self) -> None: """Run a task to append markdown fragments when available.""" @@ -99,9 +100,11 @@ async def _run(self) -> None: await asyncio.shield(self.markdown_widget.append(new_markdown)) except asyncio.CancelledError: # Task has been cancelled, add any outstanding markdown - new_markdown = "".join(self._pending) - if new_markdown: - await self.markdown_widget.append(new_markdown) + pass + + new_markdown = "".join(self._pending) + if new_markdown: + await self.markdown_widget.append(new_markdown) class Navigator: From 7b9310af68ddf4ae0b3a378ccf54d2dc2f1599dc Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 24 Jul 2025 21:38:31 +0100 Subject: [PATCH 2/2] comment --- src/textual/widgets/_markdown.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index 67cf074835..775fdd5bfc 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -88,6 +88,7 @@ async def write(self, markdown_fragment: str) -> None: # Append the new fragment, and set an event to tell the _run loop to wake up self._pending.append(markdown_fragment) self._new_markup.set() + # Allow the task to wake up and actually display the new markdown await asyncio.sleep(0) async def _run(self) -> None: