Avoid creating occlusions for editor blocks, since these block mouse wheel events (#20649)

Just block mouse down events, and in the case of the inline assist
prompt, set the default cursor.

Release Notes:

- N/A

Co-authored-by: Richard <richard@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-11-13 21:02:54 -08:00 committed by GitHub
parent 6b3c909155
commit 093c9cc87b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 20 additions and 13 deletions

View file

@ -24,9 +24,9 @@ use futures::{
join, SinkExt, Stream, StreamExt, join, SinkExt, Stream, StreamExt,
}; };
use gpui::{ use gpui::{
anchored, deferred, point, AnyElement, AppContext, ClickEvent, EventEmitter, FocusHandle, anchored, deferred, point, AnyElement, AppContext, ClickEvent, CursorStyle, EventEmitter,
FocusableView, FontWeight, Global, HighlightStyle, Model, ModelContext, Subscription, Task, FocusHandle, FocusableView, FontWeight, Global, HighlightStyle, Model, ModelContext,
TextStyle, UpdateGlobal, View, ViewContext, WeakView, WindowContext, Subscription, Task, TextStyle, UpdateGlobal, View, ViewContext, WeakView, WindowContext,
}; };
use language::{Buffer, IndentKind, Point, Selection, TransactionId}; use language::{Buffer, IndentKind, Point, Selection, TransactionId};
use language_model::{ use language_model::{
@ -1199,7 +1199,7 @@ impl InlineAssistant {
style: BlockStyle::Flex, style: BlockStyle::Flex,
render: Arc::new(move |cx| { render: Arc::new(move |cx| {
div() div()
.occlude() .block_mouse_down()
.bg(cx.theme().status().deleted_background) .bg(cx.theme().status().deleted_background)
.size_full() .size_full()
.h(height as f32 * cx.line_height()) .h(height as f32 * cx.line_height())
@ -1481,7 +1481,8 @@ impl Render for PromptEditor {
h_flex() h_flex()
.key_context("PromptEditor") .key_context("PromptEditor")
.bg(cx.theme().colors().editor_background) .bg(cx.theme().colors().editor_background)
.occlude() .block_mouse_down()
.cursor(CursorStyle::Arrow)
.border_y_1() .border_y_1()
.border_color(cx.theme().status().info_border) .border_color(cx.theme().status().info_border)
.size_full() .size_full()

View file

@ -795,7 +795,7 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
let highlight_style: HighlightStyle = cx.theme().colors().text_accent.into(); let highlight_style: HighlightStyle = cx.theme().colors().text_accent.into();
h_flex() h_flex()
.id(DIAGNOSTIC_HEADER) .id(DIAGNOSTIC_HEADER)
.occlude() .block_mouse_down()
.h(2. * cx.line_height()) .h(2. * cx.line_height())
.pl_10() .pl_10()
.pr_5() .pr_5()

View file

@ -10431,7 +10431,7 @@ impl Editor {
text_style = text_style.highlight(highlight_style); text_style = text_style.highlight(highlight_style);
} }
div() div()
.occlude() .block_mouse_down()
.pl(cx.anchor_x) .pl(cx.anchor_x)
.child(EditorElement::new( .child(EditorElement::new(
&rename_editor, &rename_editor,
@ -14681,7 +14681,7 @@ pub fn diagnostic_block_renderer(
.group(group_id.clone()) .group(group_id.clone())
.relative() .relative()
.size_full() .size_full()
.occlude() .block_mouse_down()
.pl(cx.gutter_dimensions.width) .pl(cx.gutter_dimensions.width)
.w(cx.max_width - cx.gutter_dimensions.full_width()) .w(cx.max_width - cx.gutter_dimensions.full_width())
.child( .child(

View file

@ -435,7 +435,7 @@ impl Editor {
h_flex() h_flex()
.id(cx.block_id) .id(cx.block_id)
.occlude() .block_mouse_down()
.h(cx.line_height()) .h(cx.line_height())
.w_full() .w_full()
.border_t_1() .border_t_1()
@ -714,7 +714,7 @@ impl Editor {
h_flex() h_flex()
.id(cx.block_id) .id(cx.block_id)
.occlude() .block_mouse_down()
.bg(deleted_hunk_color) .bg(deleted_hunk_color)
.h(height as f32 * cx.line_height()) .h(height as f32 * cx.line_height())
.w_full() .w_full()

View file

@ -511,7 +511,7 @@ impl Interactivity {
} }
/// Block the mouse from interacting with this element or any of its children /// Block the mouse from interacting with this element or any of its children
/// The imperative API equivalent to [`InteractiveElement::block_mouse`] /// The imperative API equivalent to [`InteractiveElement::occlude`]
pub fn occlude_mouse(&mut self) { pub fn occlude_mouse(&mut self) {
self.occlude_mouse = true; self.occlude_mouse = true;
} }
@ -874,11 +874,17 @@ pub trait InteractiveElement: Sized {
} }
/// Block the mouse from interacting with this element or any of its children /// Block the mouse from interacting with this element or any of its children
/// The fluent API equivalent to [`Interactivity::block_mouse`] /// The fluent API equivalent to [`Interactivity::occlude_mouse`]
fn occlude(mut self) -> Self { fn occlude(mut self) -> Self {
self.interactivity().occlude_mouse(); self.interactivity().occlude_mouse();
self self
} }
/// Block the mouse from interacting with this element or any of its children
/// The fluent API equivalent to [`Interactivity::occlude_mouse`]
fn block_mouse_down(mut self) -> Self {
self.on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
}
} }
/// A trait for elements that want to use the standard GPUI interactivity features /// A trait for elements that want to use the standard GPUI interactivity features

View file

@ -163,7 +163,7 @@ impl EditorBlock {
div() div()
.id(cx.block_id) .id(cx.block_id)
.occlude() .block_mouse_down()
.flex() .flex()
.items_start() .items_start()
.min_h(text_line_height) .min_h(text_line_height)