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

Background queries on App when command palette is shown causes an exception #3633

Closed
davep opened this issue Nov 2, 2023 · 1 comment · Fixed by #3641
Closed

Background queries on App when command palette is shown causes an exception #3633

davep opened this issue Nov 2, 2023 · 1 comment · Fixed by #3641
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@davep
Copy link
Contributor

davep commented Nov 2, 2023

Technically this isn't an issue with the command palette, it would be an issue with any screen with a background process that causes a query to be handled by the app, but via the command palette is the way that a dev would most likely encounter it and it's where they'd find it most surprising.

Consider this code:

from textual.app import App, ComposeResult
from textual.widgets import Log

class CommandPaletteIsolation(App[None]):

    def compose(self) -> ComposeResult:
        yield Log()

    def tick(self) -> None:
        self.query_one(Log).write_line("Tick")

    def on_mount(self) -> None:
        self.set_interval(1, self.tick)

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

Let it run for a moment, then summon the command palette and keep it up. The next time tick runs a NoMatches will result.

This version, where the default screen isn't being used, isn't a problem:

from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Log

class MyScreen(Screen):

    def compose(self) -> ComposeResult:
        yield Log()

    def tick(self) -> None:
        self.query_one(Log).write_line("Tick")

    def on_mount(self) -> None:
        self.set_interval(1, self.tick)

class CommandPaletteIsolation(App[None]):

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

if __name__ == "__main__":
    CommandPaletteIsolation().run()
@davep davep added bug Something isn't working enhancement New feature or request labels Nov 2, 2023
davep added a commit to davep/textual-sandbox that referenced this issue Nov 3, 2023
@davep davep self-assigned this Nov 6, 2023
davep added a commit to davep/textual that referenced this issue Nov 6, 2023
This fixes Textualize#3633 by ensuring that if a query is made against the app while
the command palette is active, the query trickles down to the
previously-active screen rather than into the command palette modal screen.

This also updates the command palette unit tests to take this change into
account.
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant