Skip to content

Commit b70a8f1

Browse files
authored
remove flicker (#3757)
* remove flicker * changelog
1 parent bc93b21 commit b70a8f1

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Fixed
1212

1313
- Fixed mouse targeting issue in `TextArea` when tabs were not fully expanded https://github.com/Textualize/textual/pull/3725
14+
- Fixed flicker when updating Markdown https://github.com/Textualize/textual/pull/3757
1415

1516
### Added
1617

src/textual/screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def _compositor_refresh(self) -> None:
645645
def _on_timer_update(self) -> None:
646646
"""Called by the _update_timer."""
647647
self._update_timer.pause()
648-
if self.is_current:
648+
if self.is_current and not self.app._batch_count:
649649
if self._layout_required:
650650
self._refresh_layout()
651651
self._layout_required = False

src/textual/widgets/_markdown.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
from .._slug import TrackedSlugs
1515
from ..app import ComposeResult
16+
from ..await_complete import AwaitComplete
1617
from ..containers import Horizontal, Vertical, VerticalScroll
1718
from ..events import Mount
1819
from ..message import Message
1920
from ..reactive import reactive, var
20-
from ..widget import AwaitMount, Widget
21+
from ..widget import Widget
2122
from ..widgets import Static, Tree
2223

2324
TableOfContentsType: TypeAlias = "list[tuple[int, str, str | None]]"
@@ -721,7 +722,7 @@ def unhandled_token(self, token: Token) -> MarkdownBlock | None:
721722
"""
722723
return None
723724

724-
def update(self, markdown: str) -> AwaitMount:
725+
def update(self, markdown: str) -> AwaitComplete:
725726
"""Update the document with new Markdown.
726727
727728
Args:
@@ -871,9 +872,16 @@ def update(self, markdown: str) -> AwaitMount:
871872
self.post_message(
872873
Markdown.TableOfContentsUpdated(self, self._table_of_contents)
873874
)
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())
877885

878886

879887
class MarkdownTableOfContents(Widget, can_focus_children=True):

0 commit comments

Comments
 (0)