This commit is contained in:
Will McGugan 2023-07-28 21:54:04 +01:00
parent fa0a62a72b
commit 482dcee134
3 changed files with 29 additions and 2 deletions

View file

@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Fixed Text.expand_tabs not expanding spans.
### Added
- Added Text.extend_style method.
## [13.4.2] - 2023-06-12
### Changed

View file

@ -565,12 +565,12 @@ class Text(JupyterMixin):
return style
def extend_style(self, spaces: int) -> None:
"""Extend the Text and styles by a given number of spaces.
"""Extend the Text given number of spaces where the spaces have the same style as the last character.
Args:
spaces (int): Number of spaces to add to the Text.
"""
if not spaces:
if spaces <= 0:
return
spans = self.spans
new_spaces = " " * spaces

View file

@ -898,3 +898,19 @@ def test_markup_property():
== "[bold]foo [italic]bar[/bold] baz[/italic]"
)
assert Text("[bold]foo").markup == "\\[bold]foo"
def test_extend_style():
text = Text.from_markup("[red]foo[/red] [bold]bar")
text.extend_style(0)
assert text.plain == "foo bar"
assert text.spans == [Span(0, 3, "red"), Span(4, 7, "bold")]
text.extend_style(-1)
assert text.plain == "foo bar"
assert text.spans == [Span(0, 3, "red"), Span(4, 7, "bold")]
text.extend_style(2)
assert text.plain == "foo bar "
assert text.spans == [Span(0, 3, "red"), Span(4, 9, "bold")]