From 1e0ded4febed33690d4d4d8f70de35961fe3a8ca Mon Sep 17 00:00:00 2001
From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
Date: Fri, 10 Jan 2025 19:00:11 -0300
Subject: [PATCH] zeta: Show keybinding in completion rating buttons in review
modal (#22985)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This PR also removes the `ThumbsUp` action that wasn't being triggered
correctly. We didn't have it's counterpart `ThumbsDown`, too, so I
mostly assumed it would be harmless to remove `ThumbsUp` as well.
Release Notes:
- N/A
---------
Co-authored-by: Marshall Bowers
---
assets/keymaps/default-macos.json | 3 +-
crates/zeta/src/rate_completion_modal.rs | 55 +++++++-----------------
2 files changed, 17 insertions(+), 41 deletions(-)
diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json
index 8e6ceb4ddcb50..ac4b27f2b02b8 100644
--- a/assets/keymaps/default-macos.json
+++ b/assets/keymaps/default-macos.json
@@ -806,7 +806,8 @@
"context": "RateCompletionModal",
"use_key_equivalents": true,
"bindings": {
- "cmd-enter": "zeta::ThumbsUp",
+ "cmd-shift-enter": "zeta::ThumbsUpActiveCompletion",
+ "cmd-shift-backspace": "zeta::ThumbsDownActiveCompletion",
"shift-down": "zeta::NextEdit",
"shift-up": "zeta::PreviousEdit",
"right": "zeta::PreviewCompletion"
diff --git a/crates/zeta/src/rate_completion_modal.rs b/crates/zeta/src/rate_completion_modal.rs
index 99e1febd9bfea..cd21a108457f8 100644
--- a/crates/zeta/src/rate_completion_modal.rs
+++ b/crates/zeta/src/rate_completion_modal.rs
@@ -15,8 +15,6 @@ actions!(
zeta,
[
RateCompletions,
- ThumbsUp,
- ThumbsDown,
ThumbsUpActiveCompletion,
ThumbsDownActiveCompletion,
NextEdit,
@@ -57,6 +55,7 @@ impl RateCompletionModal {
pub fn new(zeta: Model, cx: &mut ViewContext) -> Self {
let subscription = cx.observe(&zeta, |_, _, cx| cx.notify());
+
Self {
zeta,
selected_index: 0,
@@ -133,27 +132,6 @@ impl RateCompletionModal {
cx.notify();
}
- fn thumbs_up(&mut self, _: &ThumbsUp, cx: &mut ViewContext) {
- self.zeta.update(cx, |zeta, cx| {
- let completion = zeta
- .recent_completions()
- .skip(self.selected_index)
- .next()
- .cloned();
-
- if let Some(completion) = completion {
- zeta.rate_completion(
- &completion,
- InlineCompletionRating::Positive,
- "".to_string(),
- cx,
- );
- }
- });
- self.select_next_edit(&Default::default(), cx);
- cx.notify();
- }
-
fn thumbs_up_active(&mut self, _: &ThumbsUpActiveCompletion, cx: &mut ViewContext) {
self.zeta.update(cx, |zeta, cx| {
if let Some(active) = &self.active_completion {
@@ -289,6 +267,7 @@ impl RateCompletionModal {
fn render_active_completion(&mut self, cx: &mut ViewContext) -> Option {
let active_completion = self.active_completion.as_ref()?;
let completion_id = active_completion.completion.id;
+ let focus_handle = &self.focus_handle(cx);
let mut diff = active_completion
.completion
@@ -343,6 +322,8 @@ impl RateCompletionModal {
font_style: settings.buffer_font.style,
..Default::default()
};
+ let border_color = cx.theme().colors().border;
+ let bg_color = cx.theme().colors().editor_background;
let rated = self.zeta.read(cx).is_completion_rated(completion_id);
let was_shown = self.zeta.read(cx).was_completion_shown(completion_id);
@@ -352,9 +333,6 @@ impl RateCompletionModal {
.text(cx)
.is_empty();
- let border_color = cx.theme().colors().border;
- let bg_color = cx.theme().colors().editor_background;
-
let label_container = || h_flex().pl_1().gap_1p5();
Some(
@@ -453,12 +431,6 @@ impl RateCompletionModal {
.gap_1()
.child(
Button::new("bad", "Bad Completion")
- .key_binding(KeyBinding::for_action_in(
- &ThumbsDown,
- &self.focus_handle(cx),
- cx,
- ))
- .style(ButtonStyle::Filled)
.icon(IconName::ThumbsDown)
.icon_size(IconSize::Small)
.icon_position(IconPosition::Start)
@@ -468,6 +440,11 @@ impl RateCompletionModal {
Tooltip::text("Explain what's bad about it before reporting it", cx)
})
})
+ .key_binding(KeyBinding::for_action_in(
+ &ThumbsDownActiveCompletion,
+ focus_handle,
+ cx,
+ ))
.on_click(cx.listener(move |this, _, cx| {
this.thumbs_down_active(
&ThumbsDownActiveCompletion,
@@ -477,16 +454,15 @@ impl RateCompletionModal {
)
.child(
Button::new("good", "Good Completion")
- .key_binding(KeyBinding::for_action_in(
- &ThumbsUp,
- &self.focus_handle(cx),
- cx,
- ))
- .style(ButtonStyle::Filled)
.icon(IconName::ThumbsUp)
.icon_size(IconSize::Small)
.icon_position(IconPosition::Start)
.disabled(rated)
+ .key_binding(KeyBinding::for_action_in(
+ &ThumbsUpActiveCompletion,
+ focus_handle,
+ cx,
+ ))
.on_click(cx.listener(move |this, _, cx| {
this.thumbs_up_active(&ThumbsUpActiveCompletion, cx);
})),
@@ -512,7 +488,6 @@ impl Render for RateCompletionModal {
.on_action(cx.listener(Self::select_next_edit))
.on_action(cx.listener(Self::select_first))
.on_action(cx.listener(Self::select_last))
- .on_action(cx.listener(Self::thumbs_up))
.on_action(cx.listener(Self::thumbs_up_active))
.on_action(cx.listener(Self::thumbs_down_active))
.on_action(cx.listener(Self::focus_completions))
@@ -528,7 +503,7 @@ impl Render for RateCompletionModal {
v_flex()
.border_r_1()
.border_color(border_color)
- .w_96()
+ .w_72()
.h_full()
.flex_shrink_0()
.overflow_hidden()