|
13 | 13 |
|
14 | 14 | from .._slug import TrackedSlugs |
15 | 15 | from ..app import ComposeResult |
| 16 | +from ..await_complete import AwaitComplete |
16 | 17 | from ..containers import Horizontal, Vertical, VerticalScroll |
17 | 18 | from ..events import Mount |
18 | 19 | from ..message import Message |
19 | 20 | from ..reactive import reactive, var |
20 | | -from ..widget import AwaitMount, Widget |
| 21 | +from ..widget import Widget |
21 | 22 | from ..widgets import Static, Tree |
22 | 23 |
|
23 | 24 | TableOfContentsType: TypeAlias = "list[tuple[int, str, str | None]]" |
@@ -721,7 +722,7 @@ def unhandled_token(self, token: Token) -> MarkdownBlock | None: |
721 | 722 | """ |
722 | 723 | return None |
723 | 724 |
|
724 | | - def update(self, markdown: str) -> AwaitMount: |
| 725 | + def update(self, markdown: str) -> AwaitComplete: |
725 | 726 | """Update the document with new Markdown. |
726 | 727 |
|
727 | 728 | Args: |
@@ -871,9 +872,16 @@ def update(self, markdown: str) -> AwaitMount: |
871 | 872 | self.post_message( |
872 | 873 | Markdown.TableOfContentsUpdated(self, self._table_of_contents) |
873 | 874 | ) |
874 | | - with self.app.batch_update(): |
875 | | - self.query("MarkdownBlock").remove() |
876 | | - return self.mount_all(output) |
| 875 | + markdown_block = self.query("MarkdownBlock") |
| 876 | + |
| 877 | + async def await_update() -> None: |
| 878 | + """Update in a single batch.""" |
| 879 | + |
| 880 | + with self.app.batch_update(): |
| 881 | + await markdown_block.remove() |
| 882 | + await self.mount_all(output) |
| 883 | + |
| 884 | + return AwaitComplete(await_update()) |
877 | 885 |
|
878 | 886 |
|
879 | 887 | class MarkdownTableOfContents(Widget, can_focus_children=True): |
|
0 commit comments