From 6e36e9e93dfccb3353e586638fe28da78409d205 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:20:16 +0100 Subject: [PATCH 1/3] fix(text area): fix initial flicker in rendering Fix initial flicker in the `TextArea`, where for a brief moment each character is rendered on a new line before the size is settled. The width for the `WrappedDocument` is _slightly_ confusing where zero means no wrapping, but the current negative wrap width looks like the bug. Fixes #5841 --- src/textual/widgets/_text_area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index 1a52cace65..bbb219ac7a 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -1021,7 +1021,7 @@ def wrap_width(self) -> int: width, _ = self.scrollable_content_region.size cursor_width = 1 if self.soft_wrap: - return width - self.gutter_width - cursor_width + return max(0, width - self.gutter_width - cursor_width) return 0 def _rewrap_and_refresh_virtual_size(self) -> None: From 4653f306c7efd5dbb2168828951a72ddb20f040f Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:24:04 +0100 Subject: [PATCH 2/3] fix(text area): set attributes before calling _set_document Ensure `TextArea.__init__()` assigns attributes like `soft_wrap` *before* calling the `_set_document()` method. Currently if you create a `TextArea` with `soft_wrap=False`, the document is first wrapped with the default `soft_wrap=True`, causing an initial flicker. --- src/textual/widgets/_text_area.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index bbb219ac7a..f180c28f30 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -500,6 +500,11 @@ def __init__( self._cursor_offset = (0, 0) """The virtual offset of the cursor (not screen-space offset).""" + self.set_reactive(TextArea.soft_wrap, soft_wrap) + self.set_reactive(TextArea.read_only, read_only) + self.set_reactive(TextArea.show_line_numbers, show_line_numbers) + self.set_reactive(TextArea.line_number_start, line_number_start) + self._set_document(text, language) self.language = language @@ -510,11 +515,6 @@ def __init__( reactive is set as a string, the watcher will update this attribute to the corresponding `TextAreaTheme` object.""" - self.set_reactive(TextArea.soft_wrap, soft_wrap) - self.set_reactive(TextArea.read_only, read_only) - self.set_reactive(TextArea.show_line_numbers, show_line_numbers) - self.set_reactive(TextArea.line_number_start, line_number_start) - self.tab_behavior = tab_behavior if tooltip is not None: From aae72f2f9570432f9b3cb699a78ebcbcc238ad4b Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Thu, 5 Jun 2025 17:17:22 +0100 Subject: [PATCH 3/3] docs(changelog): add fix for text area flicker --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dad5c87e6f..c420d5a4e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed + +- Fixed issues with initial flicker in `TextArea` rendering https://github.com/Textualize/textual/issues/5841 ## [3.3.0] - 2025-06-01