Confirm code action on mouse down

This commit is contained in:
Antonio Scandurra 2023-11-10 15:57:02 +01:00
parent fb450e35f7
commit c44db3b7ec
2 changed files with 16 additions and 5 deletions

View file

@ -44,7 +44,7 @@ snippet = { path = "../snippet" }
sum_tree = { path = "../sum_tree" } sum_tree = { path = "../sum_tree" }
text = { package="text2", path = "../text2" } text = { package="text2", path = "../text2" }
theme = { package="theme2", path = "../theme2" } theme = { package="theme2", path = "../theme2" }
ui2 = { package = "ui2", path = "../ui2" } ui = { package = "ui2", path = "../ui2" }
util = { path = "../util" } util = { path = "../util" }
sqlez = { path = "../sqlez" } sqlez = { path = "../sqlez" }
workspace = { package = "workspace2", path = "../workspace2" } workspace = { package = "workspace2", path = "../workspace2" }

View file

@ -42,9 +42,9 @@ use gpui::{
action, actions, div, point, px, relative, rems, size, uniform_list, AnyElement, AppContext, action, actions, div, point, px, relative, rems, size, uniform_list, AnyElement, AppContext,
AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context,
DispatchContext, EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight, DispatchContext, EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight,
HighlightStyle, Hsla, InputHandler, Model, ParentElement, Pixels, Render, StatelessInteractive, HighlightStyle, Hsla, InputHandler, Model, MouseButton, ParentElement, Pixels, Render,
Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, StatelessInteractive, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View,
VisualContext, WeakView, WindowContext, ViewContext, VisualContext, WeakView, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState}; use hover_popover::{hide_hover, HoverState};
@ -1586,6 +1586,17 @@ impl CodeActionsMenu {
.bg(colors.element_hover) .bg(colors.element_hover)
.text_color(colors.text_accent) .text_color(colors.text_accent)
}) })
.on_mouse_down(MouseButton::Left, move |editor: &mut Editor, _, cx| {
cx.stop_propagation();
editor
.confirm_code_action(
&ConfirmCodeAction {
item_ix: Some(item_ix),
},
cx,
)
.map(|task| task.detach_and_log_err(cx));
})
.child(action.lsp_action.title.clone()) .child(action.lsp_action.title.clone())
}) })
.collect() .collect()
@ -4429,7 +4440,7 @@ impl Editor {
) -> Option<AnyElement<Self>> { ) -> Option<AnyElement<Self>> {
if self.available_code_actions.is_some() { if self.available_code_actions.is_some() {
Some( Some(
IconButton::new("code_actions_indicator", ui2::Icon::Bolt) IconButton::new("code_actions_indicator", ui::Icon::Bolt)
.on_click(|editor: &mut Editor, cx| { .on_click(|editor: &mut Editor, cx| {
editor.toggle_code_actions( editor.toggle_code_actions(
&ToggleCodeActions { &ToggleCodeActions {