Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `Screen.size` https://github.com/Textualize/textual/pull/6105
- Added `compact` to Binding.Group https://github.com/Textualize/textual/pull/6132
- Added `Screen.get_hover_widgets_at` https://github.com/Textualize/textual/pull/6132
- Added `Content.wrap` https://github.com/Textualize/textual/pull/6138

### Fixed

- Fixed issue where Segments with a style of `None` aren't rendered https://github.com/Textualize/textual/pull/6109
- Fixed visual glitches and crash when changing `DataTable.header_height` https://github.com/Textualize/textual/pull/6128
- Fixed TextArea.placeholder not handling multi-lines https://github.com/Textualize/textual/pull/6138

## [6.1.0] - 2025-08-01

Expand Down
20 changes: 20 additions & 0 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,26 @@ def iter_content() -> Iterable[Content]:

return Content("".join(text), spans, total_cell_length)

def wrap(
self, width: int, *, align: TextAlign = "left", overflow: TextOverflow = "fold"
) -> list[Content]:
"""Wrap text so that it fits within the given dimensions.

Note that Textual will automatically wrap Content in widgets.
This method is only required if you need some additional processing to lines.

Args:
width: Maximum width of the line (in cells).
align: Alignment of lines.
overflow: Overflow of lines (what happens when the text doesn't fit).

Returns:
A list of Content objects, one per line.
"""
lines = self._wrap_and_format(width, align, overflow)
content_lines = [line.content for line in lines]
return content_lines

def get_style_at_offset(self, offset: int) -> Style:
"""Get the style of a character at give offset.

Expand Down
34 changes: 17 additions & 17 deletions src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,24 +1206,24 @@ def render_line(self, y: int) -> Strip:
Returns:
A rendered line.
"""
if y == 0 and not self.text and self.placeholder:
style = self.get_visual_style("text-area--placeholder")
content = (
Content(self.placeholder)
if isinstance(self.placeholder, str)
else self.placeholder
)
content = content.stylize(style)
if self._draw_cursor:
theme = self._theme
cursor_style = theme.cursor_style if theme else None
if cursor_style:
content = content.stylize(
ContentStyle.from_rich_style(cursor_style), 0, 1
)
return Strip(
content.render_segments(self.visual_style), content.cell_length

if not self.text and self.placeholder:
placeholder_lines = Content.from_text(self.placeholder).wrap(
self.content_size.width
)
if y < len(placeholder_lines):
style = self.get_visual_style("text-area--placeholder")
content = placeholder_lines[y].stylize(style)
if self._draw_cursor and y == 0:
theme = self._theme
cursor_style = theme.cursor_style if theme else None
if cursor_style:
content = content.stylize(
ContentStyle.from_rich_style(cursor_style), 0, 1
)
return Strip(
content.render_segments(self.visual_style), content.cell_length
)

scroll_x, scroll_y = self.scroll_offset
absolute_y = scroll_y + y
Expand Down
Loading
Loading