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
6 changes: 3 additions & 3 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,10 @@ def __add__(self, other: Content | str) -> Content:
return content
return NotImplemented

def __radd__(self, other: Content | str) -> Content:
if not isinstance(other, (Content, str)):
def __radd__(self, other: str) -> Content:
if not isinstance(other, str):
return NotImplemented
return self + other
return Content(other) + self

@classmethod
def _trim_spans(cls, text: str, spans: list[Span]) -> list[Span]:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ def test_add() -> None:
assert content.spans == [Span(0, 3, "red"), Span(4, 7, "blue")]
assert content.cell_length == 7

def test_radd() -> None:
"""Test reverse addition."""
assert "foo" + Content("bar") == Content("foobar")

# Test spans after addition
content = "foo " + Content.styled("bar", "blue")
assert str(content) == "foo bar"
assert content.spans == [Span(4, 7, "blue")]

def test_from_markup():
"""Test simple parsing of content markup."""
Expand Down
Loading