Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 10, 2025
1 parent 2852b12 commit 7657a9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/textual/_compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def get_widget_and_offset_at(
offset_x2 = 0

for segment in lines[0]:
end += segment.cell_length
end += len(segment.text)
style = segment.style
if style is not None and style._meta is not None:
meta = style.meta
Expand All @@ -921,10 +921,11 @@ def get_widget_and_offset_at(
offset_x2 = offset_x + len(segment.text)

if x <= end and x >= start:
first, _ = segment.split_cells(x - start)
return widget, (
None
if offset_y is None
else Offset(offset_x + (x - start), offset_y)
else Offset(offset_x + len(first.text), offset_y)
)
start = end

Expand Down
18 changes: 18 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3330,3 +3330,21 @@ def compose(self) -> ComposeResult:
yield Label("This does not allow [bold]markup[/bold]", markup=False)

snap_compare(LabelApp())


def test_arbitrary_selection_double_cell(snap_compare):
"""Check that selection understands double width cells.
You should see a smiley face followed by 'Hello World!', where Hello is highlighted."""

class LApp(App):
def compose(self) -> ComposeResult:
yield Label("😃Hello World!")

async def run_before(pilot: Pilot) -> None:
await pilot.pause()
await pilot.mouse_down(Label, offset=(2, 0))
await pilot.mouse_up(Label, offset=(7, 0))
await pilot.pause()

assert snap_compare(LApp(), run_before=run_before)

0 comments on commit 7657a9e

Please sign in to comment.