From c6008505c94e98e519b14cb8e2ae2b8f07c9e627 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 5 Jan 2024 11:06:51 +0000 Subject: [PATCH] Fixing wrap width to account for scrollbars --- src/textual/widgets/_text_area.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index d855c7058c..6530142f78 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -715,13 +715,15 @@ def _watch_wrap(self) -> None: self._rewrap_and_refresh_virtual_size() @property - def available_content_width(self) -> int: - width, _ = self.content_size - return width - self.gutter_width + def wrap_width(self) -> int: + width, _ = self.scrollable_content_region.size + cursor_width = 1 + return width - self.gutter_width - cursor_width def _rewrap_and_refresh_virtual_size(self) -> None: if self.wrap: - self.wrapped_document.wrap(self.available_content_width) + print(f"wrapping at {self.wrap_width!r}") + self.wrapped_document.wrap(self.wrap_width) self._refresh_size() @property @@ -1032,7 +1034,7 @@ def edit(self, edit: Edit) -> EditResult: new_gutter_width = self.gutter_width if old_gutter_width != new_gutter_width: - self.wrapped_document.wrap(self.available_content_width) + self.wrapped_document.wrap(self.wrap_width) else: self.wrapped_document.wrap_range( edit.from_location, edit.to_location, result.end_location