diff --git a/CHANGELOG.md b/CHANGELOG.md index 67652d343d..d1a5fba160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Fixed link highlighting when the link spans multiple lines https://github.com/Textualize/textual/pull/6703 + ## [8.2.8] - 2026-06-30 ### Fixed diff --git a/src/textual/style.py b/src/textual/style.py index e14384d69b..6cceba68e8 100644 --- a/src/textual/style.py +++ b/src/textual/style.py @@ -492,7 +492,7 @@ def rich_style_with_offset(self, x: int, y: int) -> RichStyle: _meta, ) = _get_simple_attributes(self) color = None if foreground is None else background + foreground - return RichStyle( + rich_style = RichStyle( color=None if color is None else color.rich_color, bgcolor=None if background is None else background.rich_color, bold=bold, @@ -506,6 +506,9 @@ def rich_style_with_offset(self, x: int, y: int) -> RichStyle: link=link, meta={**self.meta, "offset": (x, y)}, ) + if link is not None or _meta is not None: + rich_style._link_id = f"L{id(self)}" + return rich_style @cached_property def without_color(self) -> Style: diff --git a/tests/test_style_parse.py b/tests/test_style_parse.py index 987d4852c0..6482d55442 100644 --- a/tests/test_style_parse.py +++ b/tests/test_style_parse.py @@ -54,3 +54,18 @@ def test_parse_style(markup: str, style: Style) -> None: print(parsed_style._meta) print(style._meta) assert parsed_style == style + + +@pytest.mark.parametrize( + "style", + [ + Style(link="https://textual.textualize.io"), + Style.from_meta({"@click": "app.bell"}), + ], +) +def test_rich_style_with_offset_reuses_link_id(style: Style) -> None: + + assert ( + style.rich_style_with_offset(0, 0)._link_id + == style.rich_style_with_offset(0, 1)._link_id + )