From 0be7cf8ea81e7631113ff7a91396f1bdb3292e90 Mon Sep 17 00:00:00 2001 From: Wes Higbee Date: Fri, 13 Dec 2024 22:31:54 -0600 Subject: [PATCH] Show `restart` transformation button after successful inline assist (#20439) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using inline assist, after successfully generating a transformation it's not possible to generate a new transformation. Currently, you have to modify the prompt (i.e. add a `` and hit ``) to regenerate. So, I changed the restart button to be visible after a successful transformation. And in that case I map it to a different keyboard shortcut because `menu::Confirm` is mapped to accept the current suggestion. Now, I can invoke a series of transforms back to back until I get what I want! It might also be desired to keep the accept button visible after modifying the prompt (before submitting it). In that case we'll need to remap accept to an alternate key (perhaps the same alt-shift-enter I am using for restart. That wouldn't be too insane to remember. But maybe someone has a better idea. I don't care what the shortcut is, I just want the ability to regenerate without adding/deleting spaces. ## Before **Two choices** after a suggestions is presented. Also, a great example of why I would want to regenerate the suggestion, it left some tokens ``! ![CleanShot 2024-12-13 at 00 34 09](https://github.com/user-attachments/assets/3c1786ca-8ec5-48e2-b3dd-64de36e61f6a) ## After **Three choices** after a suggestion is presented, the circular icon is for regenerate, just like you see if you modify the prompt text. ![CleanShot 2024-12-13 at 00 37 58](https://github.com/user-attachments/assets/ceda300f-0851-48bf-ad3a-be44308c734e) ## Release Notes: - Added Restart Button to Inline Assistant When PromptĀ Is Unchanged --------- Co-authored-by: Danilo Leal --- assets/icons/rotate_cw.svg | 5 ++- assets/keymaps/default-linux.json | 1 + assets/keymaps/default-macos.json | 1 + crates/assistant/src/inline_assistant.rs | 49 ++++++++++++++++-------- crates/menu/src/menu.rs | 1 + 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/assets/icons/rotate_cw.svg b/assets/icons/rotate_cw.svg index 019367745fa9baca4be2d0a72b096d9f9cdb15a4..2098de38c235edcb9779858f62137b4269b432c5 100644 --- a/assets/icons/rotate_cw.svg +++ b/assets/icons/rotate_cw.svg @@ -1 +1,4 @@ - + + + + diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index f52ddfcc26000060dd10b2c54ef35a48cd9d64a2..f93c459ec6985e884856dff6ce924a1559f81eb0 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -17,6 +17,7 @@ "escape": "menu::Cancel", "ctrl-escape": "menu::Cancel", "ctrl-c": "menu::Cancel", + "alt-shift-enter": "menu::Restart", "alt-enter": ["picker::ConfirmInput", { "secondary": false }], "ctrl-alt-enter": ["picker::ConfirmInput", { "secondary": true }], "ctrl-shift-w": "workspace::CloseWindow", diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index 1ec898a84b81d6035bcc0d5a6b5360e025e2874b..f821bc982d3ac04df1f78c9b907f5f6d0d972179 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -24,6 +24,7 @@ "cmd-escape": "menu::Cancel", "ctrl-escape": "menu::Cancel", "ctrl-c": "menu::Cancel", + "alt-shift-enter": "menu::Restart", "cmd-shift-w": "workspace::CloseWindow", "shift-escape": "workspace::ToggleZoom", "cmd-o": "workspace::Open", diff --git a/crates/assistant/src/inline_assistant.rs b/crates/assistant/src/inline_assistant.rs index acca7ae1afac2c2fad0b6cc90b291339af83224c..9c95b09854a90a39b9cabad9f451475bdd24bf6e 100644 --- a/crates/assistant/src/inline_assistant.rs +++ b/crates/assistant/src/inline_assistant.rs @@ -1441,6 +1441,15 @@ impl Render for PromptEditor { ] } CodegenStatus::Error(_) | CodegenStatus::Done => { + let must_rerun = + self.edited_since_done || matches!(status, CodegenStatus::Error(_)); + // when accept button isn't visible, then restart maps to confirm + // when accept button is visible, then restart must be mapped to an alternate keyboard shortcut + let restart_key: &dyn gpui::Action = if must_rerun { + &menu::Confirm + } else { + &menu::Restart + }; vec![ IconButton::new("cancel", IconName::Close) .icon_color(Color::Muted) @@ -1450,23 +1459,22 @@ impl Render for PromptEditor { cx.listener(|_, _, cx| cx.emit(PromptEditorEvent::CancelRequested)), ) .into_any_element(), - if self.edited_since_done || matches!(status, CodegenStatus::Error(_)) { - IconButton::new("restart", IconName::RotateCw) - .icon_color(Color::Info) - .shape(IconButtonShape::Square) - .tooltip(|cx| { - Tooltip::with_meta( - "Restart Transformation", - Some(&menu::Confirm), - "Changes will be discarded", - cx, - ) - }) - .on_click(cx.listener(|_, _, cx| { - cx.emit(PromptEditorEvent::StartRequested); - })) - .into_any_element() - } else { + IconButton::new("restart", IconName::RotateCw) + .icon_color(Color::Muted) + .shape(IconButtonShape::Square) + .tooltip(|cx| { + Tooltip::with_meta( + "Regenerate Transformation", + Some(restart_key), + "Current change will be discarded", + cx, + ) + }) + .on_click(cx.listener(|_, _, cx| { + cx.emit(PromptEditorEvent::StartRequested); + })) + .into_any_element(), + if !must_rerun { IconButton::new("confirm", IconName::Check) .icon_color(Color::Info) .shape(IconButtonShape::Square) @@ -1475,6 +1483,8 @@ impl Render for PromptEditor { cx.emit(PromptEditorEvent::ConfirmRequested); })) .into_any_element() + } else { + div().into_any_element() }, ] } @@ -1491,6 +1501,7 @@ impl Render for PromptEditor { .py(cx.line_height() / 2.5) .on_action(cx.listener(Self::confirm)) .on_action(cx.listener(Self::cancel)) + .on_action(cx.listener(Self::restart)) .on_action(cx.listener(Self::move_up)) .on_action(cx.listener(Self::move_down)) .capture_action(cx.listener(Self::cycle_prev)) @@ -1837,6 +1848,10 @@ impl PromptEditor { } } + fn restart(&mut self, _: &menu::Restart, cx: &mut ViewContext) { + cx.emit(PromptEditorEvent::StartRequested); + } + fn cancel(&mut self, _: &editor::actions::Cancel, cx: &mut ViewContext) { match self.codegen.read(cx).status(cx) { CodegenStatus::Idle | CodegenStatus::Done | CodegenStatus::Error(_) => { diff --git a/crates/menu/src/menu.rs b/crates/menu/src/menu.rs index 0818a6e6ffabb5e3afb329e54af1f145313b3a53..3c5dc2521f7275f163ec42b4b55b2f472a5f5480 100644 --- a/crates/menu/src/menu.rs +++ b/crates/menu/src/menu.rs @@ -19,5 +19,6 @@ actions!( SelectNext, SelectFirst, SelectLast, + Restart ] );