|
20 | 20 | from dataclasses import dataclass
|
21 | 21 | from functools import total_ordering
|
22 | 22 | from inspect import isclass
|
| 23 | +from operator import attrgetter |
23 | 24 | from time import monotonic
|
24 | 25 | from typing import (
|
25 | 26 | TYPE_CHECKING,
|
@@ -455,9 +456,9 @@ class CommandList(OptionList, can_focus=False):
|
455 | 456 | }
|
456 | 457 |
|
457 | 458 | CommandList > .option-list--option-highlighted {
|
458 |
| - color: $block-cursor-foreground; |
459 |
| - background: $block-cursor-background; |
460 |
| - text-style: $block-cursor-text-style; |
| 459 | + color: $block-cursor-blurred-foreground; |
| 460 | + background: $block-cursor-blurred-background; |
| 461 | + text-style: $block-cursor-blurred-text-style; |
461 | 462 | }
|
462 | 463 |
|
463 | 464 | CommandList:nocolor > .option-list--option-highlighted {
|
@@ -1014,26 +1015,12 @@ def _refresh_command_list(
|
1014 | 1015 | commands: The commands to show in the widget.
|
1015 | 1016 | clear_current: Should the current content of the list be cleared first?
|
1016 | 1017 | """
|
1017 |
| - # For the moment, this is a fairly naive approach to populating the |
1018 |
| - # command list with a list of commands. Every time we add a |
1019 |
| - # new one we're nuking the list of options and populating them |
1020 |
| - # again. If this turns out to not be a great approach, we may try |
1021 |
| - # and get a lot smarter with this (ideally OptionList will grow a |
1022 |
| - # method to sort its content in an efficient way; but for now we'll |
1023 |
| - # go with "worse is better" wisdom). |
1024 |
| - highlighted = ( |
1025 |
| - command_list.get_option_at_index(command_list.highlighted) |
1026 |
| - if command_list.highlighted is not None and not clear_current |
1027 |
| - else None |
1028 |
| - ) |
1029 |
| - |
1030 |
| - def sort_key(command: Command) -> float: |
1031 |
| - return -command.hit.score |
1032 | 1018 |
|
1033 |
| - sorted_commands = sorted(commands, key=sort_key) |
| 1019 | + sorted_commands = sorted(commands, key=attrgetter("hit.score"), reverse=True) |
1034 | 1020 | command_list.clear_options().add_options(sorted_commands)
|
1035 |
| - if highlighted is not None and highlighted.id: |
1036 |
| - command_list.highlighted = command_list.get_option_index(highlighted.id) |
| 1021 | + |
| 1022 | + if sorted_commands: |
| 1023 | + command_list.highlighted = 0 |
1037 | 1024 |
|
1038 | 1025 | self._list_visible = bool(command_list.option_count)
|
1039 | 1026 | self._hit_count = command_list.option_count
|
|
0 commit comments