Skip to content

Conversation

@wingding12
Copy link

Summary

Fixes #3948

When soft_wrap=True, the console sets overflow='ignore'. The previous fix for #3937 (trailing whitespace) caused the wrap() method to skip justification entirely when overflow='ignore', resulting in table titles being left-aligned instead of centered.

Root Cause

PR #3937 added this early return:

if overflow == "ignore":
    lines.append(line)
    continue

This bypassed all processing including new_lines.justify(), causing titles to not be centered.

Fix

Restructured the wrap() method to:

  1. Always create new_lines and apply justification
  2. Only skip truncation when overflow='ignore' (not justification)

Test Plan

Added two tests:

  • test_wrap_justify_with_overflow_ignore in test_text.py - verifies text centering works with overflow=ignore
  • test_title_justify_with_soft_wrap in test_table.py - verifies table title is centered when soft_wrap=True

Before/After

Before (title left-aligned):

The Title                  
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Column 1 ┃ Column 2 ┃
┗━━━━━━━━━━┻━━━━━━━━━━┛

After (title centered):

        The Title         
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Column 1 ┃ Column 2 ┃
┗━━━━━━━━━━┻━━━━━━━━━━┛
When soft_wrap=True, the console sets overflow='ignore'. The previous
fix for Textualize#3937 (trailing whitespace) caused the wrap() method to skip
justification entirely when overflow='ignore', resulting in table
titles being left-aligned instead of centered.

The fix restructures the wrap() method to:
1. Always create new_lines and apply justification
2. Only skip truncation when overflow='ignore' (not justification)

Fixes Textualize#3948
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant