Skip to content

Passing focus to a different widget and hiding causes screen regions not to be redrawn. #6200

@lyovushka

Description

@lyovushka

Here is an example to reproduce the issue. Press "ctrl+f", type some letters (it makes the program scroll randomly), then press "escape". Quite often the screen is not redrawn properly.

Textual version: 6.4.0
Terminal's tried: kitty, foot
Operating system: linux

from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.widgets import Checkbox, Input
from textual.geometry import Region
from textual.binding import Binding
import random


class ExampleFind(HorizontalGroup):
    BINDINGS = [("escape", "dismiss")]

    DEFAULT_CSS = """
    ExampleFind {
        border-top: tall $accent;
        padding: 0 1 1 1;
        Input { width: 1fr; }

        &.hidden {
            display: none;
        }
    }
    """

    def on_input_changed(self, message: Input.Changed) -> None:
        scroll: VerticalScroll = self.parent.query_one(VerticalScroll)
        region = Region(random.randint(5, 100), random.randint(5, 100), width=3, height=1)
        scroll.scroll_to_region(region, immediate=True, animate=False)

    def compose(self) -> ComposeResult:
        yield Input(placeholder="Find")
        yield Checkbox("Match case")
        yield Checkbox("Whole word")

    def action_dismiss(self) -> None:
        scroll: VerticalScroll = self.parent.query_one(VerticalScroll)
        scroll.children[3].focus(False)
        self.add_class("hidden")


class ExampleApp(App):
    BINDINGS = [Binding("ctrl+f", "find", priority=True)]

    def compose(self) -> ComposeResult:
        with VerticalScroll():
            for i in range(100):
                yield Input(placeholder=str(i))

        yield ExampleFind(classes="hidden")

    def action_find(self) -> None:
        find = self.query_one(ExampleFind)
        find.remove_class("hidden")
        find_input = find.query_one(Input)
        find_input.focus()


if __name__ == "__main__":
    app = ExampleApp()
    app.run()

Originally posted by @lyovushka in #6176

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions