Skip to content

Commit

Permalink
command palette tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jun 22, 2024
1 parent b118074 commit 9d67e45
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
Screen,
ScreenResultCallbackType,
ScreenResultType,
_SystemModalScreen,
SystemModalScreen,
)
from .signal import Signal
from .timer import Timer
Expand Down Expand Up @@ -696,7 +696,7 @@ def children(self) -> Sequence["Widget"]:
next(
screen
for screen in reversed(self._screen_stack)
if not isinstance(screen, _SystemModalScreen)
if not isinstance(screen, SystemModalScreen)
),
)
except StopIteration:
Expand Down
25 changes: 14 additions & 11 deletions src/textual/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from .fuzzy import Matcher
from .message import Message
from .reactive import var
from .screen import Screen, _SystemModalScreen
from .screen import Screen, SystemModalScreen
from .timer import Timer
from .types import CallbackType, IgnoreReturnCallbackType
from .widget import Widget
Expand Down Expand Up @@ -349,12 +349,13 @@ class CommandList(OptionList, can_focus=False):
CommandList {
visibility: hidden;
border-top: blank;
border-bottom: hkey $primary;
border-bottom: hkey $background;
border-left: none;
border-right: none;
height: auto;
max-height: 70vh;
background: $panel;
padding: 0;
}
CommandList:focus {
Expand All @@ -374,7 +375,7 @@ class CommandList(OptionList, can_focus=False):
}
CommandList > .option-list--option {
padding-left: 1;
padding-left: 2;
}
"""

Expand Down Expand Up @@ -416,7 +417,7 @@ class CommandInput(Input):
"""


class CommandPalette(_SystemModalScreen[CallbackType]):
class CommandPalette(SystemModalScreen[CallbackType]):
"""The Textual command palette."""

COMPONENT_CLASSES: ClassVar[set[str]] = {
Expand All @@ -431,17 +432,19 @@ class CommandPalette(_SystemModalScreen[CallbackType]):
"""

DEFAULT_CSS = """
CommandPalette:inline {
/* If the command palette is invoked in inline mode, we may need additional lines. */
min-height: 20;
}
CommandPalette {
background: $background 30%;
align-horizontal: center;
background: $background 50%;
align-horizontal: center;
}
CommandPalette > .command-palette--help-text {
text-style: dim;
text-style: dim not bold;
}
CommandPalette:dark > .command-palette--highlight {
Expand All @@ -455,15 +458,15 @@ class CommandPalette(_SystemModalScreen[CallbackType]):
CommandPalette > Vertical {
margin-top: 3;
width: 90%;
# width: 90%;
height: 100%;
visibility: hidden;
visibility: hidden;
}
CommandPalette #--input {
height: auto;
visibility: visible;
border: hkey $primary;
border: hkey $background;
background: $panel;
}
Expand Down Expand Up @@ -623,7 +626,7 @@ def compose(self) -> ComposeResult:
with Vertical():
with Horizontal(id="--input"):
yield SearchIcon()
yield CommandInput(placeholder="Command Palette Search...")
yield CommandInput(placeholder="Search for commands…")
if not self.run_on_select:
yield Button("\u25b6")
with Vertical(id="--results"):
Expand Down
2 changes: 1 addition & 1 deletion src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ def __init__(
self._modal = True


class _SystemModalScreen(ModalScreen[ScreenResultType], inherit_css=False):
class SystemModalScreen(ModalScreen[ScreenResultType], inherit_css=False):
"""A variant of `ModalScreen` for internal use.
This version of `ModalScreen` allows us to build system-level screens;
Expand Down
5 changes: 4 additions & 1 deletion src/textual/widgets/_option_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,10 @@ def render_line(self, y: int) -> Strip:
style,
self.scrollable_content_region.width - self._left_gutter_width(),
)
strip = strips[y_offset]
try:
strip = strips[y_offset]
except IndexError:
return Strip([])
return strip

def scroll_to_highlight(self, top: bool = False) -> None:
Expand Down

0 comments on commit 9d67e45

Please sign in to comment.