diff --git a/CHANGELOG.md b/CHANGELOG.md index 05e95619ce..1bdc55f5a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Changed + +- "Discover" hits in the command palette are no longer sorted alphabetically https://github.com/Textualize/textual/pull/4720 + ### Fixed - Fixed scroll_visible with margin https://github.com/Textualize/textual/pull/4719 diff --git a/docs/guide/command_palette.md b/docs/guide/command_palette.md index 5fa1bebc08..484ccbe49c 100644 --- a/docs/guide/command_palette.md +++ b/docs/guide/command_palette.md @@ -113,7 +113,6 @@ this is to aid in command discoverability. - `discover` accepts no parameters (instead of the search value) - `discover` yields instances of [`DiscoveryHit`][textual.command.DiscoveryHit] (instead of instances of [`Hit`][textual.command.Hit]) -- discovery hits are sorted in ascending alphabetical order because there is no matching and no match score is generated Instances of [`DiscoveryHit`][textual.command.DiscoveryHit] contain information about how the hit should be displayed, an optional help string, and a callback which will be run if the user selects that command. diff --git a/src/textual/command.py b/src/textual/command.py index 2b1d713462..2cd523767a 100644 --- a/src/textual/command.py +++ b/src/textual/command.py @@ -865,7 +865,7 @@ def _refresh_command_list( clear_current: Should the current content of the list be cleared first? """ # For the moment, this is a fairly naive approach to populating the - # command list with a sorted list of commands. Every time we add a + # command list with a list of commands. Every time we add a # new one we're nuking the list of options and populating them # again. If this turns out to not be a great approach, we may try # and get a lot smarter with this (ideally OptionList will grow a @@ -876,7 +876,7 @@ def _refresh_command_list( if command_list.highlighted is not None and not clear_current else None ) - command_list.clear_options().add_options(sorted(commands, reverse=True)) + command_list.clear_options().add_options(commands) if highlighted is not None and highlighted.id: command_list.highlighted = command_list.get_option_index(highlighted.id) self._list_visible = bool(command_list.option_count) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 6510f97bd2..693e150753 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -4305,138 +4305,138 @@ font-weight: 700; } - .terminal-2176540917-matrix { + .terminal-1919115509-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-2176540917-title { + .terminal-1919115509-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-2176540917-r1 { fill: #646464 } - .terminal-2176540917-r2 { fill: #c5c8c6 } - .terminal-2176540917-r3 { fill: #004578 } - .terminal-2176540917-r4 { fill: #dfe1e2 } - .terminal-2176540917-r5 { fill: #00ff00 } - .terminal-2176540917-r6 { fill: #000000 } - .terminal-2176540917-r7 { fill: #1e1e1e } - .terminal-2176540917-r8 { fill: #dfe1e2;font-weight: bold } - .terminal-2176540917-r9 { fill: #fea62b;font-weight: bold } + .terminal-1919115509-r1 { fill: #646464 } + .terminal-1919115509-r2 { fill: #c5c8c6 } + .terminal-1919115509-r3 { fill: #004578 } + .terminal-1919115509-r4 { fill: #dfe1e2 } + .terminal-1919115509-r5 { fill: #00ff00 } + .terminal-1919115509-r6 { fill: #000000 } + .terminal-1919115509-r7 { fill: #1e1e1e } + .terminal-1919115509-r8 { fill: #dfe1e2;font-weight: bold } + .terminal-1919115509-r9 { fill: #fea62b;font-weight: bold } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - CommandPaletteApp + CommandPaletteApp - + - - - - - ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ - - 🔎A - - -   This is a test of this code 9                                                  -   This is a test of this code 8                                                  -   This is a test of this code 7                                                  -   This is a test of this code 6                                                  -   This is a test of this code 5                                                  -   This is a test of this code 4                                                  -   This is a test of this code 3                                                  -   This is a test of this code 2                                                  -   This is a test of this code 1                                                  -   This is a test of this code 0                                                  - ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ - - - - + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + + 🔎A + + +   This is a test of this code 0                                                  +   This is a test of this code 1                                                  +   This is a test of this code 2                                                  +   This is a test of this code 3                                                  +   This is a test of this code 4                                                  +   This is a test of this code 5                                                  +   This is a test of this code 6                                                  +   This is a test of this code 7                                                  +   This is a test of this code 8                                                  +   This is a test of this code 9                                                  + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + @@ -19883,133 +19883,133 @@ font-weight: 700; } - .terminal-593761732-matrix { + .terminal-112858016-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-593761732-title { + .terminal-112858016-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-593761732-r1 { fill: #c5c8c6 } - .terminal-593761732-r2 { fill: #e3e3e3 } - .terminal-593761732-r3 { fill: #e1e1e1 } - .terminal-593761732-r4 { fill: #ffdddd } + .terminal-112858016-r1 { fill: #c5c8c6 } + .terminal-112858016-r2 { fill: #e3e3e3 } + .terminal-112858016-r3 { fill: #e1e1e1 } + .terminal-112858016-r4 { fill: #eedddd } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - Press ctrl + \ and type a color + Press ctrl + \ and type a color - - - - Press ctrl + \ and type a color - - - - - red - - - - - - - - - - - - - - - - - + + + + Press ctrl + \ and type a color + + + + + ansi_red + + + + + + + + + + + + + + + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index bbe242f0ba..74a4a7b607 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1188,7 +1188,7 @@ def test_example_color_command(snap_compare): """Test the color_command example.""" assert snap_compare( EXAMPLES_DIR / "color_command.py", - press=["ctrl+backslash", "r", "e", "d", "down", "down", "enter"], + press=["ctrl+backslash", "r", "e", "d", "down", "enter"], )