Add an action for that runs a sequence of actions (#39261)
Thanks to @Zertsov for #37932 which caused me to consider this implementation approach. One known issue with this is that it will not wait for actions that do async work to complete. Supporting this would require quite a lot of code change. It also doesn't affect the main usecase of sequencing editor actions, since few are async. Another caveat is that this is implemented as an action handler on workspace and so won't work in other types of windows. This seems fine for now, since action sequences don't seem useful in other window types. The command palette isn't accessible in non-workspace windows. Alternatives considered: * Add `cx: &App` to `Action::build`. This would allow removal of the special case in keymap parsing. Decided not to do this, since ideally `build` is a pure function of the input json. * Build it more directly into GPUI. The main advantage of this would be the potential to handle non-workspace windows. Since it's possible to do outside of GPUI, seems better to do so. While some aspects of the GPUI action system are pretty directly informed by the specifics of Zed's keymap files, it seems to avoid this as much as possible. * Bake it more directly into keymap syntax like in #37932. While I think it would be good for this to be a primitive in the JSON syntax, it seems like it would better fit in a more comprehensive change to provide better JSON structure. So in the meantime it seems better to keep the structure the same and just add a new action. - Another reason to not bake it in yet is that this provides a place to document the caveat about async actions. Closes #17710 Release Notes: - Added support for action sequences in keymaps. Example: `["action::Sequence", [ ["editor::SelectLargerSyntaxNode", "editor::Copy", "editor::UndoSelection"]` --------- Co-authored-by: Mitchel Vostrez <mitch@voz.dev>
This commit is contained in:
co-authored by
Mitchel Vostrez
parent
b9d9602074
commit
b5d57598b6
@@ -5553,6 +5553,13 @@ impl Workspace {
|
||||
|
||||
fn actions(&self, div: Div, window: &mut Window, cx: &mut Context<Self>) -> Div {
|
||||
self.add_workspace_actions_listeners(div, window, cx)
|
||||
.on_action(cx.listener(
|
||||
|_workspace, action_sequence: &settings::ActionSequence, window, cx| {
|
||||
for action in &action_sequence.0 {
|
||||
window.dispatch_action(action.boxed_clone(), cx);
|
||||
}
|
||||
},
|
||||
))
|
||||
.on_action(cx.listener(Self::close_inactive_items_and_panes))
|
||||
.on_action(cx.listener(Self::close_all_items_and_panes))
|
||||
.on_action(cx.listener(Self::save_all))
|
||||
|
||||
Reference in New Issue
Block a user