Skip to content

Commit c9439ff

Browse files
authored
Merge pull request #5973 from Textualize/expand-optimal
added expand rule
2 parents 78198c1 + 201c70d commit c9439ff

33 files changed

+360
-212
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- Added `Markdown.get_stream` https://github.com/Textualize/textual/pull/5966
1515
- Added `textual.highlight` module for syntax highlighting https://github.com/Textualize/textual/pull/5966
1616
- Added `MessagePump.wait_for_refresh` method https://github.com/Textualize/textual/pull/5966
17+
- Added `Widget.container_scroll_offset` https://github.com/Textualize/textual/commit/e84600cfb31630f8b5493bf1043a4a1e7c212f7c
18+
- Added `Markdown.source` attribute to MarkdownBlocks https://github.com/Textualize/textual/commit/e84600cfb31630f8b5493bf1043a4a1e7c212f7c
19+
- Added extension mechanism to Markdown https://github.com/Textualize/textual/commit/e84600cfb31630f8b5493bf1043a4a1e7c212f7c
20+
- Added `index` to `ListView.Selected` event https://github.com/Textualize/textual/pull/5973
21+
- Added `layout` switch to Static.update https://github.com/Textualize/textual/pull/5973
1722

1823
### Changed
1924

2025
- Improved rendering of Markdown tables (replace Rich table with grid) which allows text selection https://github.com/Textualize/textual/pull/5962
2126
- Change look of command palette, to drop accented borders https://github.com/Textualize/textual/pull/5966
27+
- Some style tweaks to Markdown https://github.com/Textualize/textual/commit/e84600cfb31630f8b5493bf1043a4a1e7c212f7c
28+
2229

2330
### Removed
2431

2532
- Breaking change: Removed `Markdown.code_dark_theme`, `Markdown.code_light_theme`, `Markdown.code_indent_guides` which are no longer needed with the new code fence. https://github.com/Textualize/textual/pull/5967
33+
- Removed focus style from Markdown, as it can be a little expensive https://github.com/Textualize/textual/commit/e84600cfb31630f8b5493bf1043a4a1e7c212f7c
2634

2735
## [4.0.0] - 2025-07-12
2836

src/textual/_arrange.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ def arrange(
118118
)
119119

120120
WidgetPlacement.apply_absolute(layout_placements)
121-
122121
placements.extend(layout_placements)
123122

124-
widget.log(placements)
125123
return DockArrangeResult(placements, set(display_widgets), scroll_spacing)
126124

127125

src/textual/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ def _watch_theme(self, theme_name: str) -> None:
13751375
self.set_class(not dark, "-light-mode", update=False)
13761376
self._refresh_truecolor_filter(self.ansi_theme)
13771377
self._invalidate_css()
1378-
self.call_next(self.refresh_css)
1378+
self.call_next(partial(self.refresh_css, animate=False))
13791379
self.call_next(self.theme_changed_signal.publish, theme)
13801380

13811381
def _invalidate_css(self) -> None:

src/textual/content.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ def styled(
335335
if not text:
336336
return Content("")
337337
span_length = cell_len(text) if cell_length is None else cell_length
338-
new_content = cls(text, [Span(0, span_length, style)], span_length)
338+
new_content = cls(
339+
text, [Span(0, span_length, style)] if style else None, span_length
340+
)
339341
return new_content
340342

341343
@classmethod
@@ -822,6 +824,7 @@ def iter_content() -> Iterable[Content]:
822824
extend_spans(
823825
_Span(offset + start, offset + end, style)
824826
for start, end, style in content._spans
827+
if style
825828
)
826829
offset += len(content._text)
827830
if total_cell_length is not None:
@@ -1122,7 +1125,7 @@ def render(
11221125
get_style: Callable[[str | Style], Style]
11231126
if parse_style is None:
11241127

1125-
def get_style(style: str | Style) -> Style:
1128+
def _get_style(style: str | Style) -> Style:
11261129
"""The default get_style method."""
11271130
if isinstance(style, Style):
11281131
return style
@@ -1132,6 +1135,8 @@ def get_style(style: str | Style) -> Style:
11321135
visual_style = Style.null()
11331136
return visual_style
11341137

1138+
get_style = _get_style
1139+
11351140
else:
11361141
get_style = parse_style
11371142

src/textual/css/_help_text.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
VALID_ALIGN_HORIZONTAL,
1313
VALID_ALIGN_VERTICAL,
1414
VALID_BORDER,
15+
VALID_EXPAND,
1516
VALID_KEYLINE,
1617
VALID_LAYOUT,
1718
VALID_POSITION,
@@ -788,6 +789,23 @@ def position_help_text(property_name: str) -> HelpText:
788789
)
789790

790791

792+
def expand_help_text(property_name: str) -> HelpText:
793+
"""Help text to show when the user supplies the wrong value for expand.
794+
795+
Args:
796+
property_name: The name of the property.
797+
798+
Returns:
799+
Renderable for displaying the help text for this property.
800+
"""
801+
return HelpText(
802+
summary=f"Invalid value for [i]{property_name}[/]",
803+
bullets=[
804+
Bullet(f"Valid values are {friendly_list(VALID_EXPAND)}"),
805+
],
806+
)
807+
808+
791809
def style_flags_property_help_text(
792810
property_name: str, value: str, context: StylingContext
793811
) -> HelpText:

src/textual/css/_styles_builder.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
border_property_help_text,
1717
color_property_help_text,
1818
dock_property_help_text,
19+
expand_help_text,
1920
fractional_property_help_text,
2021
integer_help_text,
2122
keyline_help_text,
@@ -44,6 +45,7 @@
4445
VALID_CONSTRAIN,
4546
VALID_DISPLAY,
4647
VALID_EDGE,
48+
VALID_EXPAND,
4749
VALID_HATCH,
4850
VALID_KEYLINE,
4951
VALID_OVERFLOW,
@@ -1256,6 +1258,17 @@ def process_hatch(self, name: str, tokens: list[Token]) -> None:
12561258

12571259
self.styles._rules[name] = (character or " ", color.multiply_alpha(opacity))
12581260

1261+
def process_expand(self, name: str, tokens: list[Token]):
1262+
if not tokens:
1263+
return
1264+
if len(tokens) != 1:
1265+
self.error(name, tokens[0], offset_single_axis_help_text(name))
1266+
else:
1267+
token = tokens[0]
1268+
if token.value not in VALID_EXPAND:
1269+
self.error(name, tokens[0], expand_help_text(name))
1270+
self.styles._rules["expand"] = token.value
1271+
12591272
def _get_suggested_property_name_for_rule(self, rule_name: str) -> str | None:
12601273
"""
12611274
Returns a valid CSS property "Python" name, or None if no close matches could be found.

src/textual/css/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
VALID_HATCH: Final = {"left", "right", "cross", "vertical", "horizontal"}
8888
VALID_TEXT_WRAP: Final = {"wrap", "nowrap"}
8989
VALID_TEXT_OVERFLOW: Final = {"clip", "fold", "ellipsis"}
90+
VALID_EXPAND: Final = {"greedy", "optimal"}
9091

9192
HATCHES: Final = {
9293
"left": "╲",

src/textual/css/scalar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ def resolve(
283283

284284
if unit == Unit.PERCENT:
285285
unit = percent_unit
286-
# elif unit == Unit.AUTO:
287-
# unit = Unit.FRACTION
288286
try:
289287
dimension = RESOLVE_MAP[unit](
290288
value, size, viewport, fraction_unit or _FRACTION_ONE

src/textual/css/styles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
VALID_BOX_SIZING,
4444
VALID_CONSTRAIN,
4545
VALID_DISPLAY,
46+
VALID_EXPAND,
4647
VALID_OVERFLOW,
4748
VALID_OVERLAY,
4849
VALID_POSITION,
@@ -61,6 +62,7 @@
6162
BoxSizing,
6263
Constrain,
6364
Display,
65+
Expand,
6466
Overflow,
6567
Overlay,
6668
ScrollbarGutter,
@@ -203,6 +205,7 @@ class RulesMap(TypedDict, total=False):
203205

204206
text_wrap: TextWrap
205207
text_overflow: TextOverflow
208+
expand: Expand
206209

207210
line_pad: int
208211

@@ -492,6 +495,7 @@ class StylesBase:
492495
text_overflow: StringEnumProperty[TextOverflow] = StringEnumProperty(
493496
VALID_TEXT_OVERFLOW, "fold"
494497
)
498+
expand: StringEnumProperty[Expand] = StringEnumProperty(VALID_EXPAND, "greedy")
495499
line_pad = IntegerProperty(default=0, layout=True)
496500
"""Padding added to left and right of lines."""
497501

@@ -1288,6 +1292,8 @@ def append_declaration(name: str, value: str) -> None:
12881292
append_declaration("text-wrap", self.text_wrap)
12891293
if "text_overflow" in rules:
12901294
append_declaration("text-overflow", self.text_overflow)
1295+
if "expand" in rules:
1296+
append_declaration("expand", self.expand)
12911297
if "line_pad" in rules:
12921298
append_declaration("line-pad", str(self.line_pad))
12931299
lines.sort()

src/textual/css/stylesheet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ def replace_rules(
697697

698698
for key in modified_rule_keys:
699699
setattr(base_styles, key, get_rule(key))
700-
701700
node.notify_style_update()
702701

703702
def update(self, root: DOMNode, animate: bool = False) -> None:

0 commit comments

Comments
 (0)