diff --git a/src/textual/widgets/_markdown.py b/src/textual/widgets/_markdown.py index bd869069ca..775fdd5bfc 100644 --- a/src/textual/widgets/_markdown.py +++ b/src/textual/widgets/_markdown.py @@ -88,6 +88,8 @@ 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: """Run a task to append markdown fragments when available.""" @@ -99,9 +101,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: