Skip to content

Commit a066560

Browse files
authored
Merge pull request #6522 from Textualize/fence-offsets
offsets fix
2 parents 5fdea0d + 551d4ff commit a066560

8 files changed

Lines changed: 36 additions & 32 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unlreleased
9+
10+
### Fixed
11+
12+
- Fixed selection to the right of code fence blocks (may break some snapshots)
13+
814
## [8.2.5] - 2026-04-30
915

1016
### Added

src/textual/_compositor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,16 @@ def get_widget_and_offset_at(
937937

938938
from rich.cells import get_character_cell_size
939939

940+
offset: Offset | None = None
940941
for segment in line:
941942
end += segment.cell_length
942943
style = segment.style
943944
if style is not None and style._meta is not None:
944945
meta = style.meta
945946
if "offset" in meta:
946-
offset_x, offset_y = style.meta["offset"]
947+
offset_x, offset_y = meta["offset"]
948+
if offset_y is None:
949+
continue
947950
offset_x2 = offset_x + len(segment.text)
948951

949952
if x < end and x >= start:
@@ -955,14 +958,14 @@ def get_widget_and_offset_at(
955958
break
956959
segment_cell_length += get_character_cell_size(character)
957960
segment_offset += 1
958-
return widget, (
959-
None
960-
if offset_y is None
961-
else Offset(offset_x + segment_offset, offset_y)
962-
)
961+
962+
offset = Offset(offset_x + segment_offset, offset_y)
963+
break
963964
start = end
964965

965-
return widget, (None if offset_y is None else Offset(offset_x2, offset_y))
966+
if offset is None and offset_y is not None:
967+
offset = Offset(offset_x2, offset_y)
968+
return widget, offset
966969

967970
def find_widget(self, widget: Widget) -> MapGeometry:
968971
"""Get information regarding the relative position of a widget in the Compositor.

src/textual/widgets/_markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def set_content(self, content: Content) -> None:
940940
self.query_one("#code-content", Label).update(content)
941941

942942
def compose(self) -> ComposeResult:
943-
yield Label(self._highlighted_code, id="code-content")
943+
yield Label(self._highlighted_code, id="code-content", expand=True)
944944

945945

946946
NUMERALS = " ⅠⅡⅢⅣⅤⅥ"

tests/snapshot_tests/__snapshots__/test_snapshots/test_markdown_component_classes_reloading.svg

Lines changed: 1 addition & 2 deletions
Loading

tests/snapshot_tests/__snapshots__/test_snapshots/test_markdown_dark_theme_override.svg

Lines changed: 3 additions & 4 deletions
Loading

0 commit comments

Comments
 (0)