[BUG] Segment.split_cells doesn't handle zero width charachters correctly
まだ誰も着手していません。
評価
調査の方向性
Start with Segment.split_cells and the cell-width helpers in rich/segment.py, then read split_text in rich/cells.py to see how it cuts text by cell position. Write a test like the one in the issue, using repr checks on the two halves of a Hebrew string with combining marks, and run it to see the current split. Done means the marks stay attached to their base characters and the existing cell-splitting tests still pass; the proposed split_text swap needs checking against them.
索引モデルが issue の本文から書いたものです。
説明
- I've checked docs and closed issues for possible solutions.
- I can't find my issue in the FAQ.
Describe the bug
Segment.split_cells() mishandles zero-width characters (such as Hebrew diacritical marks) when splitting text across cell boundaries, resulting in malformed segments where zero-width combining marks are incorrectly detached or split from their base characters.
Minimal reproduction / Unit Test
def test_split_cells_zero_width():
hebrew_segment = Segment("שָׁלוֹם")
left, right = hebrew_segment.split_cells(3)
assert repr(left) == "Segment('שָׁלוֹ')"
assert repr(right) == "Segment('ם')"
Proposed Fix
cells.py already has a function called split_text that can be used to solve the problem as such:
def _split_cells(cls, segment: "Segment", cut: int) -> tuple["Segment", "Segment"]:
"""Split a segment in to two at a given cell position.
Note that splitting a double-width character, may result in that character turning
into two spaces.
Args:
segment (Segment): A segment to split.
cut (int): A cell position to cut on.
Returns:
A tuple of two segments.
"""
text, style, control = segment
_Segment = Segment
cell_length = segment.cell_length
if cut >= cell_length:
return segment, _Segment("", style, control)
before, after = split_text(text, cut)
return (
_Segment(before, style, control),
_Segment(after, style, control),
)
I tried to publish it but wasn't able to since the repository limints pull requests t collaborators only.
- 主要言語
- Python
- スター
- 57.8k
- フォーク
- 2.6k
- 平均マージ
- 20分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Textualize/rich のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
Textualize/rich#4269 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Textualize/rich#4268 ·
-
Needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Textualize/rich#4267 ·
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Textualize/rich#4265 ·
Textualize/rich の issue をすべて見る
似ている issue
-
integration: media_player
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
home-assistant/core#193344 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
daniel-ospina/tortoise#13607 ·
メンテナーはふだん 1 日以内に返信
-
documentation priority: medium
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信