gpui: Press enter, space to trigger click to focused element (#35075)

Release Notes:

- N/A

> Any user interaction that is equivalent to a click, such as pressing
the Space key or Enter key while the element is focused. Note that this
only applies to elements with a default key event handler, and
therefore, excludes other elements that have been made focusable by
setting the
[tabindex](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/tabindex)
attribute.

https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event

---------

Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Umesh Yadav <23421535+imumesh18@users.noreply.github.com>
This commit is contained in:
Jason Lee 2025-08-06 06:15:30 +08:00 committed by GitHub
parent b7469f5bc3
commit 0025019db4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 231 additions and 63 deletions

View file

@ -8183,7 +8183,7 @@ impl Editor {
editor.set_breakpoint_context_menu(
row,
Some(position),
event.down.position,
event.position(),
window,
cx,
);
@ -8350,7 +8350,11 @@ impl Editor {
.icon_color(color)
.toggle_state(is_active)
.on_click(cx.listener(move |editor, e: &ClickEvent, window, cx| {
let quick_launch = e.down.button == MouseButton::Left;
let quick_launch = match e {
ClickEvent::Keyboard(_) => true,
ClickEvent::Mouse(e) => e.down.button == MouseButton::Left,
};
window.focus(&editor.focus_handle(cx));
editor.toggle_code_actions(
&ToggleCodeActions {
@ -8362,7 +8366,7 @@ impl Editor {
);
}))
.on_right_click(cx.listener(move |editor, event: &ClickEvent, window, cx| {
editor.set_breakpoint_context_menu(row, position, event.down.position, window, cx);
editor.set_breakpoint_context_menu(row, position, event.position(), window, cx);
}))
}

View file

@ -43,11 +43,11 @@ use gpui::{
Bounds, ClickEvent, ContentMask, Context, Corner, Corners, CursorStyle, DispatchPhase, Edges,
Element, ElementInputHandler, Entity, Focusable as _, FontId, GlobalElementId, Hitbox,
HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero, Keystroke, Length,
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PaintQuad,
ParentElement, Pixels, ScrollDelta, ScrollHandle, ScrollWheelEvent, ShapedLine, SharedString,
Size, StatefulInteractiveElement, Style, Styled, TextRun, TextStyleRefinement, WeakEntity,
Window, anchored, deferred, div, fill, linear_color_stop, linear_gradient, outline, point, px,
quad, relative, size, solid_background, transparent_black,
ModifiersChangedEvent, MouseButton, MouseClickEvent, MouseDownEvent, MouseMoveEvent,
MouseUpEvent, PaintQuad, ParentElement, Pixels, ScrollDelta, ScrollHandle, ScrollWheelEvent,
ShapedLine, SharedString, Size, StatefulInteractiveElement, Style, Styled, TextRun,
TextStyleRefinement, WeakEntity, Window, anchored, deferred, div, fill, linear_color_stop,
linear_gradient, outline, point, px, quad, relative, size, solid_background, transparent_black,
};
use itertools::Itertools;
use language::language_settings::{
@ -949,8 +949,12 @@ impl EditorElement {
let hovered_link_modifier = Editor::multi_cursor_modifier(false, &event.modifiers(), cx);
if !pending_nonempty_selections && hovered_link_modifier && text_hitbox.is_hovered(window) {
let point = position_map.point_for_position(event.up.position);
if let Some(mouse_position) = event.mouse_position()
&& !pending_nonempty_selections
&& hovered_link_modifier
&& text_hitbox.is_hovered(window)
{
let point = position_map.point_for_position(mouse_position);
editor.handle_click_hovered_link(point, event.modifiers(), window, cx);
editor.selection_drag_state = SelectionDragState::None;
@ -3735,7 +3739,7 @@ impl EditorElement {
move |editor, e: &ClickEvent, window, cx| {
editor.open_excerpts_common(
Some(jump_data.clone()),
e.down.modifiers.secondary(),
e.modifiers().secondary(),
window,
cx,
);
@ -6882,10 +6886,10 @@ impl EditorElement {
// Fire click handlers during the bubble phase.
DispatchPhase::Bubble => editor.update(cx, |editor, cx| {
if let Some(mouse_down) = captured_mouse_down.take() {
let event = ClickEvent {
let event = ClickEvent::Mouse(MouseClickEvent {
down: mouse_down,
up: event.clone(),
};
});
Self::click(editor, &event, &position_map, window, cx);
}
}),