Skip to content

Commit 449d3a6

Browse files
Ensure that the command palette only cancels its own workers
See #3615. Co-authored-by: Rodrigo Girão Serrão <[email protected]>
1 parent 7cbba66 commit 449d3a6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/textual/command.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def _on_click(self, event: Click) -> None:
515515
method of dismissing the palette.
516516
"""
517517
if self.get_widget_at(event.screen_x, event.screen_y)[0] is self:
518-
self.workers.cancel_all()
518+
self._cancel_gather_commands()
519519
self.dismiss()
520520

521521
def on_mount(self, _: Mount) -> None:
@@ -774,7 +774,10 @@ def _refresh_command_list(
774774
_NO_MATCHES: Final[str] = "--no-matches"
775775
"""The ID to give the disabled option that shows there were no matches."""
776776

777-
@work(exclusive=True)
777+
_GATHER_COMMANDS_GROUP: Final[str] = "--textual-command-palette-gather-commands"
778+
"""The group name of the command gathering worker."""
779+
780+
@work(exclusive=True, group=_GATHER_COMMANDS_GROUP)
778781
async def _gather_commands(self, search_value: str) -> None:
779782
"""Gather up all of the commands that match the search value.
780783
@@ -895,6 +898,10 @@ async def _gather_commands(self, search_value: str) -> None:
895898
if command_list.option_count == 0 and not worker.is_cancelled:
896899
self._start_no_matches_countdown()
897900

901+
def _cancel_gather_commands(self) -> None:
902+
"""Cancel any operation that is gather commands."""
903+
self.workers.cancel_group(self, self._GATHER_COMMANDS_GROUP)
904+
898905
@on(Input.Changed)
899906
def _input(self, event: Input.Changed) -> None:
900907
"""React to input in the command palette.
@@ -903,7 +910,7 @@ def _input(self, event: Input.Changed) -> None:
903910
event: The input event.
904911
"""
905912
event.stop()
906-
self.workers.cancel_all()
913+
self._cancel_gather_commands()
907914
self._stop_no_matches_countdown()
908915

909916
search_value = event.value.strip()
@@ -921,7 +928,7 @@ def _select_command(self, event: OptionList.OptionSelected) -> None:
921928
event: The option selection event.
922929
"""
923930
event.stop()
924-
self.workers.cancel_all()
931+
self._cancel_gather_commands()
925932
input = self.query_one(CommandInput)
926933
with self.prevent(Input.Changed):
927934
assert isinstance(event.option, Command)
@@ -958,7 +965,7 @@ def _select_or_command(
958965
if self._selected_command is not None:
959966
# ...we should return it to the parent screen and let it
960967
# decide what to do with it (hopefully it'll run it).
961-
self.workers.cancel_all()
968+
self._cancel_gather_commands()
962969
self.dismiss(self._selected_command.command)
963970

964971
@on(OptionList.OptionHighlighted)
@@ -971,7 +978,7 @@ def _action_escape(self) -> None:
971978
if self._list_visible:
972979
self._list_visible = False
973980
else:
974-
self.workers.cancel_all()
981+
self._cancel_gather_commands()
975982
self.dismiss()
976983

977984
def _action_command_list(self, action: str) -> None:

0 commit comments

Comments
 (0)