Skip to content

Commit

Permalink
Fixing wrap width to account for scrollbars
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jan 5, 2024
1 parent 8f6b152 commit c600850
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c600850

Please sign in to comment.