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

Several command palette issues on 0.71.0 #4705

Open
darrenburns opened this issue Jul 4, 2024 · 2 comments
Open

Several command palette issues on 0.71.0 #4705

darrenburns opened this issue Jul 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@darrenburns
Copy link
Member

darrenburns commented Jul 4, 2024

I found 3 issues with the command palette in the latest release.

  1. The help text doesn't appear for the initial "discovery" hits. When you start to search, the help text starts to appear.
  2. There's something wrong with scrolling when you use the keyboard to move the cursor through the option list. In the example below, scrolling seems to break after you've started searching.
  3. The initial commands listed (DiscoveryHits) are sorted alphabetically, which seems wrong (I want control over the order - it's easy enough for me to sort my commands if that's what I require). Normal hits from searches are not sorted (as expected).
from typing import Any
from textual.app import App, ComposeResult
from textual.command import DiscoveryHit, Hit, Hits, Provider
from textual.widgets import Label


class MyProvider(Provider):
    @property
    def commands(self) -> list[tuple[str, Any, str]]:
        return [(f"option-{i}", lambda: 1, f"This is option {i}") for i in range(30)]

    async def discover(self) -> Hits:
        for name, runnable, help_text in self.commands:
            yield DiscoveryHit(
                name,
                runnable,
                help_text,
            )

    async def search(self, query: str) -> Hits:
        matcher = self.matcher(query)
        for name, runnable, help_text in self.commands:
            if (match := matcher.match(name)) > 0:
                yield Hit(
                    match,
                    matcher.highlight(name),
                    runnable,
                    help=help_text,
                )


class OptionListScrolling(App[None]):
    COMMANDS = {MyProvider}

    def compose(self) -> ComposeResult:
        yield Label("hey!")


if __name__ == "__main__":
    app = OptionListScrolling()
    app.run()
@darrenburns darrenburns added the bug Something isn't working label Jul 4, 2024
@TomJGooding
Copy link
Contributor

The help text doesn't appear for the initial "discovery" hits. When you start to search, the help text starts to appear.

It looks like you just need a small tweak to your DiscoveryHit:

    async def discover(self) -> Hits:
        for name, runnable, help_text in self.commands:
            yield DiscoveryHit(
                name,
                runnable,
                help=help_text,
            )

@TomJGooding
Copy link
Contributor

TomJGooding commented Jul 6, 2024

There's something wrong with scrolling when you use the keyboard to move the cursor through the option list.

From a quick look at the recent changes to the OptionList, I'm not sure the "line position for the start of the option" is correctly tracked here?

self._spans.append(OptionLineSpan(option_index, height))
option_index += 1

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

No branches or pull requests

2 participants