Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the size of the tab not being fixed after being justified on "fully" #3425

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Progress track thread is now a daemon thread https://github.com/Textualize/rich/pull/3402
- Fixed cached hash preservation upon clearing meta and links https://github.com/Textualize/rich/issues/2942
- Fixed overriding the `background_color` of `Syntax` not including padding https://github.com/Textualize/rich/issues/3295
- The size of the tab (\t) was not fixed when justifying text "fully" https://github.com/Textualize/rich/issues/3424

### Changed

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ The following people have contributed to the development of Rich:
- [Pierro](https://github.com/xpierroz)
- [Bernhard Wagner](https://github.com/bwagner)
- [Aaron Beaudoin](https://github.com/AaronBeaudoin)
- [oppZ](https://github.com/oppZ)
8 changes: 7 additions & 1 deletion rich/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,15 @@ def justify(
index = 0
if spaces:
while words_size + num_spaces < width:
spaces[len(spaces) - index - 1] += 1
word_index = len(spaces) - index - 1
while cell_len(words[word_index].plain) == 0 and not words_size == 0:
index = (index + 1) % len(spaces)
word_index = len(spaces) - index - 1

spaces[word_index] += 1
num_spaces += 1
index = (index + 1) % len(spaces)

tokens: List[Text] = []
for index, (word, next_word) in enumerate(
zip_longest(words, words[1:])
Expand Down
3 changes: 2 additions & 1 deletion rich/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,8 @@ def wrap(
lines = Lines()
for line in self.split(allow_blank=True):
if "\t" in line:
line.expand_tabs(tab_size)
line.plain = line.plain.replace("\t", " " * tab_size)
line._length = len(line.plain)
if no_wrap:
new_lines = Lines([line])
else:
Expand Down