Skip to content

Commit

Permalink
remove flicker (#3757)
Browse files Browse the repository at this point in the history
* remove flicker

* changelog
  • Loading branch information
willmcgugan authored Nov 27, 2023
1 parent bc93b21 commit b70a8f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

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

### Added

Expand Down
2 changes: 1 addition & 1 deletion src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def _compositor_refresh(self) -> None:
def _on_timer_update(self) -> None:
"""Called by the _update_timer."""
self._update_timer.pause()
if self.is_current:
if self.is_current and not self.app._batch_count:
if self._layout_required:
self._refresh_layout()
self._layout_required = False
Expand Down
18 changes: 13 additions & 5 deletions src/textual/widgets/_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

from .._slug import TrackedSlugs
from ..app import ComposeResult
from ..await_complete import AwaitComplete
from ..containers import Horizontal, Vertical, VerticalScroll
from ..events import Mount
from ..message import Message
from ..reactive import reactive, var
from ..widget import AwaitMount, Widget
from ..widget import Widget
from ..widgets import Static, Tree

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

def update(self, markdown: str) -> AwaitMount:
def update(self, markdown: str) -> AwaitComplete:
"""Update the document with new Markdown.
Args:
Expand Down Expand Up @@ -871,9 +872,16 @@ def update(self, markdown: str) -> AwaitMount:
self.post_message(
Markdown.TableOfContentsUpdated(self, self._table_of_contents)
)
with self.app.batch_update():
self.query("MarkdownBlock").remove()
return self.mount_all(output)
markdown_block = self.query("MarkdownBlock")

async def await_update() -> None:
"""Update in a single batch."""

with self.app.batch_update():
await markdown_block.remove()
await self.mount_all(output)

return AwaitComplete(await_update())


class MarkdownTableOfContents(Widget, can_focus_children=True):
Expand Down

0 comments on commit b70a8f1

Please sign in to comment.