Skip to content

Commit ef4db84

Browse files
committed
docstring and test
1 parent 6b0c6e0 commit ef4db84

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/textual/content.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,14 @@ def assemble(
396396
return cls("".join(text), spans)
397397

398398
def simplify(self) -> Content:
399-
"""Simplify spans in place.
399+
"""Simplify spans by joining contiguous spans together.
400400
401-
This joins contiguous spans together which can produce faster renders.
401+
This can produce faster renders but typically only worth it if you have appended a
402+
large number of Content instances together.
402403
403-
Note that this is only typically worth it if you have appended a large number of Content instances together,
404-
and it only needs to be done once.
404+
Note that this this modifies the Content instance in-place, which might appear
405+
to violate the immutability constraints, but it will not change the rendered output,
406+
nor its hash.
405407
406408
Returns:
407409
Self.

tests/test_content.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,11 @@ def test_split_and_tabs():
286286
content = Content("--- hello.py\t2024-01-15 10:30:00.000000000 -0800", spans=spans)
287287
widget = Widget()
288288
content.render_strips(0, None, Style(), RenderOptions(widget._get_style, {}))
289+
290+
291+
def test_simplify():
292+
"""Test simplify joins spans."""
293+
content = Content.from_markup("[bold]Foo[/][bold]Bar[/]")
294+
assert content.spans == [Span(0, 3, "bold"), Span(3, 6, "bold")]
295+
content.simplify()
296+
assert content.spans == [Span(0, 6, "bold")]

0 commit comments

Comments
 (0)