Skip to content

Commit

Permalink
fix for content
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 24, 2025
1 parent 2197fd0 commit 79734ee
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
58 changes: 29 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions src/textual/_compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,14 @@ def get_style_at(self, x: int, y: int) -> Style:
x -= region.x
y -= region.y

# TODO: This prompts a render, can we avoid that?
visible_screen_stack.set(widget.app._background_screens)
line = widget.render_line(y)
# lines = widget.render_lines(Region(0, y, region.width, 1))
lines = widget.render_lines(Region(0, y, region.width, 1))

# if not lines:
# return Style.null()
if not lines:
return Style.null()
end = 0

for segment in line:
for segment in lines[0]:
end += segment.cell_length
if x < end:
return segment.style or Style.null()
Expand Down Expand Up @@ -898,18 +896,15 @@ def get_widget_and_offset_at(
if y >= widget.content_region.bottom:
x, y = widget.content_region.bottom_right_inclusive

x -= region.x
y -= region.y
gutter_left, gutter_right = widget.gutter.top_left
x -= region.x + gutter_left
y -= region.y + gutter_right

visible_screen_stack.set(widget.app._background_screens)
# lines = widget.render_lines(Region(0, y, region.width, 1))
line = widget.render_line(y)

# if not lines:
# return widget, None
end = 0
start = 0

offset_y: int | None = None
offset_x = 0
offset_x2 = 0
Expand Down
5 changes: 3 additions & 2 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def render_strips(
lines = self._wrap_and_format(
width,
align=widget.styles.text_align,
overflow="ellipsis",
overflow="fold",
no_wrap=False,
tab_size=8,
selection=widget.selection,
Expand Down Expand Up @@ -825,10 +825,11 @@ def stylize_before(

def render(
self,
base_style: Style,
base_style: Style = Style.null(),
end: str = "\n",
parse_style: Callable[[str], Style] | None = None,
) -> Iterable[tuple[str, Style]]:

if not self._spans:
yield (self._text, base_style)
if end:
Expand Down
5 changes: 4 additions & 1 deletion src/textual/css/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ def parse_style(self, style_text: str) -> Style:
"""
if style_text in self._style_parse_cache:
return self._style_parse_cache[style_text]
style = style_parse(style_text, None)
try:
style = style_parse(style_text, None)
except Exception:
style = Style.null()
self._style_parse_cache[style_text] = style
return style

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,7 @@ def test_static_markup(snap_compare):
You should see 3 labels.
This first label contains an invalid style, and should have tags removed.
The second label should have the word "markup" boldened.
The second label should have the word "markup" emboldened.
The third label has markup disabled, and should show tags without styles.
"""

Expand Down

0 comments on commit 79734ee

Please sign in to comment.