From aa0929298bf85b9357edf8af239d715a18ab5ce8 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 6 Jan 2023 14:14:48 +0000 Subject: [PATCH] fix issue splitting segments --- CHANGELOG.md | 6 ++++++ rich/segment.py | 2 +- tests/test_segment.py | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3af54fd..ab3c436e 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](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [13.0.1] - 2022-01-06 + +### Fixed + +- Fixed issue with Segment.split_cells for mixed single and double cell widths + ## [13.0.0] - 2022-12-30 ### Fixed diff --git a/rich/segment.py b/rich/segment.py index 6c87a791..d489d137 100644 --- a/rich/segment.py +++ b/rich/segment.py @@ -119,7 +119,7 @@ class Segment(NamedTuple): cell_size = get_character_cell_size - pos = int((cut / cell_length) * len(text)) + pos = int((cut / cell_length) * (len(text) - 1)) before = text[:pos] cell_pos = cell_len(before) diff --git a/tests/test_segment.py b/tests/test_segment.py index 5c3bbc39..3db60b90 100644 --- a/tests/test_segment.py +++ b/tests/test_segment.py @@ -273,6 +273,11 @@ def test_divide_edge_2(): ("💩X💩Y💩Z💩A💩", 4, (Segment("💩X "), Segment(" Y💩Z💩A💩"))), ("XYZABC", 4, (Segment("XYZA"), Segment("BC"))), ("XYZABC", 5, (Segment("XYZAB"), Segment("C"))), + ( + "a1あ11bcdaef", + 9, + (Segment("a1あ11b"), Segment("cdaef")), + ), ], ) def test_split_cells_emoji(text, split, result):