Skip to content

Rendering issue with soft hyphens (~~long/wrapped text in OptionList~~) #4073

@davep

Description

@davep

At the suggestion of @willmcgugan I'm recording this without an MRE (although I have tried to make one; see below). In an application I'm currently toying with, over the weekend, I ran into this curious rendering bug:

Screenshot 2024-01-28 at 12 42 56

Note the effect seen to the right of question 9.

The widget is an OptionList, the Options within are made up of Rich renderables which in turn are made up of a Group that contains two Table.grids.

I've attempted to isolate the issue from the wider application, adding all the relevant styles (also doing it as a ModalScreen as this was part of such):

from rich.table import Table
from rich.console import Group

from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.screen import ModalScreen
from textual.widgets import OptionList

NAMES = [
    "Cardiff",
    "Swansea",
    "Aberdare",
    "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
    "Mountain Ash",
    "Hirwaun"
]

class Names(ModalScreen[None]):

    CSS = """
    Names {
        align: center middle;

        Vertical {
            width: auto;
            max-width: 60%;
            height: auto;
            max-height: 80%;
            padding: 1 2 0 2;
            background: $surface;
            border: panel $primary;
            border-title-color: $accent;

            OptionList {
                height: 1fr;
                margin: 1 0 1 0;
                &> .option-list--option {
                    padding: 0 5 1 0;
                }
            }
        }
    }
    """

    def gridify(self, n: int, name: str) -> Group:
        question = Table.grid()
        question.add_column(width=3, justify="right")
        question.add_column(width=1)
        question.add_column(ratio=1)
        question.add_row(str(n), "", f"{name} is the name of a place in Wales." )
        answer = Table.grid()
        answer.add_column(width=4)
        answer.add_column(ratio=1)
        answer.add_row("", "[red]Here is the[/] [green]second line[/]")
        return Group(question, answer)

    def compose(self) -> ComposeResult:
        with Vertical():
            yield OptionList(*[self.gridify(n, name) for n, name in enumerate(NAMES)])

class TruncatedTextOptionApp(App[None]):

    CSS = """
    Screen#_default {
        background: red;
    }
    """

    def on_mount(self) -> None:
        self.push_screen(Names())

if __name__ == "__main__":
    TruncatedTextOptionApp().run()

the result however seems fine:

Screenshot 2024-01-29 at 10 20 24

Metadata

Metadata

Labels

TaskbugSomething isn't workingquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions