Skip to content

Commit

Permalink
Merge pull request #2296 from Textualize/text-wrapping-edgecase
Browse files Browse the repository at this point in the history
Text wrapping edgecase
  • Loading branch information
willmcgugan committed May 27, 2022
2 parents c187270 + e3bd037 commit 2be0fc9
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 174 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix text wrapping edge case https://github.com/Textualize/rich/pull/2296
- Allow exceptions that are raised while a Live is rendered to be displayed and/or processed https://github.com/Textualize/rich/pull/2305
- Fix crashes that can happen with `inspect` when docstrings contain some special control codes https://github.com/Textualize/rich/pull/2294

Expand Down
11 changes: 6 additions & 5 deletions rich/_wrap.py
@@ -1,8 +1,8 @@
import re
from typing import Iterable, List, Tuple

from .cells import cell_len, chop_cells
from ._loop import loop_last
from .cells import cell_len, chop_cells

re_word = re.compile(r"\s*\S+\s*")

Expand All @@ -27,14 +27,15 @@ def divide_line(text: str, width: int, fold: bool = True) -> List[int]:
if line_position + word_length > width:
if word_length > width:
if fold:
for last, line in loop_last(
chop_cells(word, width, position=line_position)
):
chopped_words = chop_cells(word, max_size=width, position=0)
for last, line in loop_last(chopped_words):
if start:
append(start)

if last:
line_position = _cell_len(line)
else:
start += len(line)
append(start)
else:
if start:
append(start)
Expand Down
3 changes: 2 additions & 1 deletion rich/cells.py
Expand Up @@ -109,7 +109,8 @@ def set_cell_size(text: str, total: int) -> str:
# TODO: This is inefficient
# TODO: This might not work with CWJ type characters
def chop_cells(text: str, max_size: int, position: int = 0) -> List[str]:
"""Break text in to equal (cell) length strings."""
"""Break text in to equal (cell) length strings, returning the characters in reverse
order"""
_get_character_cell_size = get_character_cell_size
characters = [
(character, _get_character_cell_size(character)) for character in text
Expand Down

0 comments on commit 2be0fc9

Please sign in to comment.