Add spawning of tasks without saving them in the task stack (#9951)
These tasks are not considered for reruns with `task::Rerun`. This PR tears a bunch of stuff up around tasks: - `menu::SecondaryConfirm` for tasks is gonna spawn a task without storing it in history instead of being occupied by oneshot tasks. This is done so that cmd-clicking on the menu item actually does something meaningful. - `menu::UseSelectedQuery` got moved into picker, as tasks are it's only user (and it doesn't really make sense as a menu action). TODO: - [x] add release note - [x] Actually implement the core of this feature, which is spawning a task without saving it in history, lol. Fixes #9804 Release Notes: - Added "fire-and-forget" task spawning; `menu::SecondaryConfirm` in tasks modal now spawns a task without registering it as the last spawned task for the purposes of `task::Rerun`. By default you can spawn a task in this fashion with cmd+enter or by holding cmd and clicking on a task entry in a list. Spawning oneshots has been rebound to `option-enter` (under a `picker::ConfirmInput` name). Fixes #9804 (breaking change) - Moved `menu::UseSelectedQuery` action to `picker` namespace (breaking change).
This commit is contained in:
parent
e7bd91c6c7
commit
cff9ad19f8
7 changed files with 104 additions and 38 deletions
|
@ -17,6 +17,7 @@ anyhow.workspace = true
|
|||
editor.workspace = true
|
||||
gpui.workspace = true
|
||||
menu.workspace = true
|
||||
serde.workspace = true
|
||||
ui.workspace = true
|
||||
workspace.workspace = true
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use anyhow::Result;
|
||||
use editor::{scroll::Autoscroll, Editor};
|
||||
use gpui::{
|
||||
div, list, prelude::*, uniform_list, AnyElement, AppContext, ClickEvent, DismissEvent,
|
||||
EventEmitter, FocusHandle, FocusableView, Length, ListState, MouseButton, MouseUpEvent, Render,
|
||||
Task, UniformListScrollHandle, View, ViewContext, WindowContext,
|
||||
actions, div, impl_actions, list, prelude::*, uniform_list, AnyElement, AppContext, ClickEvent,
|
||||
DismissEvent, EventEmitter, FocusHandle, FocusableView, Length, ListState, MouseButton,
|
||||
MouseUpEvent, Render, Task, UniformListScrollHandle, View, ViewContext, WindowContext,
|
||||
};
|
||||
use head::Head;
|
||||
use serde::Deserialize;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use ui::{prelude::*, v_flex, Color, Divider, Label, ListItem, ListItemSpacing};
|
||||
use workspace::ModalView;
|
||||
|
@ -18,6 +19,17 @@ enum ElementContainer {
|
|||
UniformList(UniformListScrollHandle),
|
||||
}
|
||||
|
||||
actions!(picker, [UseSelectedQuery]);
|
||||
|
||||
/// ConfirmInput is an alternative editor action which - instead of selecting active picker entry - treats pickers editor input literally,
|
||||
/// performing some kind of action on it.
|
||||
#[derive(PartialEq, Clone, Deserialize, Default)]
|
||||
pub struct ConfirmInput {
|
||||
pub secondary: bool,
|
||||
}
|
||||
|
||||
impl_actions!(picker, [ConfirmInput]);
|
||||
|
||||
struct PendingUpdateMatches {
|
||||
delegate_update_matches: Option<Task<()>>,
|
||||
_task: Task<Result<()>>,
|
||||
|
@ -65,6 +77,9 @@ pub trait PickerDelegate: Sized + 'static {
|
|||
}
|
||||
|
||||
fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<Picker<Self>>);
|
||||
/// Instead of interacting with currently selected entry, treats editor input literally,
|
||||
/// performing some kind of action on it.
|
||||
fn confirm_input(&mut self, _secondary: bool, _: &mut ViewContext<Picker<Self>>) {}
|
||||
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>);
|
||||
fn selected_as_query(&self) -> Option<String> {
|
||||
None
|
||||
|
@ -278,7 +293,11 @@ impl<D: PickerDelegate> Picker<D> {
|
|||
}
|
||||
}
|
||||
|
||||
fn use_selected_query(&mut self, _: &menu::UseSelectedQuery, cx: &mut ViewContext<Self>) {
|
||||
fn confirm_input(&mut self, input: &ConfirmInput, cx: &mut ViewContext<Self>) {
|
||||
self.delegate.confirm_input(input.secondary, cx);
|
||||
}
|
||||
|
||||
fn use_selected_query(&mut self, _: &UseSelectedQuery, cx: &mut ViewContext<Self>) {
|
||||
if let Some(new_query) = self.delegate.selected_as_query() {
|
||||
self.set_query(new_query, cx);
|
||||
cx.stop_propagation();
|
||||
|
@ -472,6 +491,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
|
|||
.on_action(cx.listener(Self::confirm))
|
||||
.on_action(cx.listener(Self::secondary_confirm))
|
||||
.on_action(cx.listener(Self::use_selected_query))
|
||||
.on_action(cx.listener(Self::confirm_input))
|
||||
.child(match &self.head {
|
||||
Head::Editor(editor) => v_flex()
|
||||
.child(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue