From c44db3b7ecf1a4ead6190a62964911c80334a263 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 10 Nov 2023 15:57:02 +0100 Subject: [PATCH] Confirm code action on mouse down --- crates/editor2/Cargo.toml | 2 +- crates/editor2/src/editor.rs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/editor2/Cargo.toml b/crates/editor2/Cargo.toml index 493f10006f734f5c0fd907935981d2cb9a17b9e1..e45c33d91759f2e7d21283e45d1011cdd26abcb8 100644 --- a/crates/editor2/Cargo.toml +++ b/crates/editor2/Cargo.toml @@ -44,7 +44,7 @@ snippet = { path = "../snippet" } sum_tree = { path = "../sum_tree" } text = { package="text2", path = "../text2" } theme = { package="theme2", path = "../theme2" } -ui2 = { package = "ui2", path = "../ui2" } +ui = { package = "ui2", path = "../ui2" } util = { path = "../util" } sqlez = { path = "../sqlez" } workspace = { package = "workspace2", path = "../workspace2" } diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 4fafedbfcce2c27c0dbde0e12dad5da921d2d406..5e00faf3d20d8e0afcbdb3cfc9a679dab2fed8e6 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -42,9 +42,9 @@ use gpui::{ action, actions, div, point, px, relative, rems, size, uniform_list, AnyElement, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context, DispatchContext, EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight, - HighlightStyle, Hsla, InputHandler, Model, ParentElement, Pixels, Render, StatelessInteractive, - Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, - VisualContext, WeakView, WindowContext, + HighlightStyle, Hsla, InputHandler, Model, MouseButton, ParentElement, Pixels, Render, + StatelessInteractive, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, + ViewContext, VisualContext, WeakView, WindowContext, }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; @@ -1586,6 +1586,17 @@ impl CodeActionsMenu { .bg(colors.element_hover) .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()) }) .collect() @@ -4429,7 +4440,7 @@ impl Editor { ) -> Option> { if self.available_code_actions.is_some() { Some( - IconButton::new("code_actions_indicator", ui2::Icon::Bolt) + IconButton::new("code_actions_indicator", ui::Icon::Bolt) .on_click(|editor: &mut Editor, cx| { editor.toggle_code_actions( &ToggleCodeActions {