mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
docstring and test
This commit is contained in:
@@ -396,12 +396,14 @@ class Content(Visual):
|
||||
return cls("".join(text), spans)
|
||||
|
||||
def simplify(self) -> Content:
|
||||
"""Simplify spans in place.
|
||||
"""Simplify spans by joining contiguous spans together.
|
||||
|
||||
This joins contiguous spans together which can produce faster renders.
|
||||
This can produce faster renders but typically only worth it if you have appended a
|
||||
large number of Content instances together.
|
||||
|
||||
Note that this is only typically worth it if you have appended a large number of Content instances together,
|
||||
and it only needs to be done once.
|
||||
Note that this this modifies the Content instance in-place, which might appear
|
||||
to violate the immutability constraints, but it will not change the rendered output,
|
||||
nor its hash.
|
||||
|
||||
Returns:
|
||||
Self.
|
||||
|
||||
@@ -286,3 +286,11 @@ def test_split_and_tabs():
|
||||
content = Content("--- hello.py\t2024-01-15 10:30:00.000000000 -0800", spans=spans)
|
||||
widget = Widget()
|
||||
content.render_strips(0, None, Style(), RenderOptions(widget._get_style, {}))
|
||||
|
||||
|
||||
def test_simplify():
|
||||
"""Test simplify joins spans."""
|
||||
content = Content.from_markup("[bold]Foo[/][bold]Bar[/]")
|
||||
assert content.spans == [Span(0, 3, "bold"), Span(3, 6, "bold")]
|
||||
content.simplify()
|
||||
assert content.spans == [Span(0, 6, "bold")]
|
||||
|
||||
Reference in New Issue
Block a user