Action release handlers (#8782)
This PR adds support for handling action releases — events that are fired when the user releases all the modifier keys that were part of an action-triggering shortcut. If the user holds modifiers and invokes several actions sequentially via shortcuts (same or different), only the last action is "released" when its modifier keys released. ~The following methods were added to `Div`:~ - ~`capture_action_release()`~ - ~`on_action_release()`~ - ~`on_boxed_action_release()`~ ~They work similarly to `capture_action()`, `on_action()` and `on_boxed_action()`.~ See the implementation details in [this comment](https://github.com/zed-industries/zed/pull/8782#issuecomment-2009154646). Release Notes: - Added a fast-switch mode to the file finder: hit `p` or `shift-p` while holding down `cmd` to select a file immediately. (#8258). Related Issues: - Implements #8757 - Implements #8258 - Part of #7653 Co-authored-by: @ConradIrwin
This commit is contained in:
parent
91ab95ec82
commit
5602c48136
9 changed files with 260 additions and 31 deletions
|
@ -33,10 +33,11 @@ use crate::{
|
|||
ContentMask, Corners, CursorStyle, DevicePixels, DispatchNodeId, DispatchPhase, DispatchTree,
|
||||
DrawPhase, ElementId, ElementStateBox, EntityId, FocusHandle, FocusId, FontId, GlobalElementId,
|
||||
GlyphId, Hsla, ImageData, InputHandler, IsZero, KeyContext, KeyEvent, LayoutId,
|
||||
LineLayoutIndex, MonochromeSprite, MouseEvent, PaintQuad, Path, Pixels, PlatformInputHandler,
|
||||
Point, PolychromeSprite, Quad, RenderGlyphParams, RenderImageParams, RenderSvgParams, Scene,
|
||||
Shadow, SharedString, Size, StrikethroughStyle, Style, TextStyleRefinement,
|
||||
TransformationMatrix, Underline, UnderlineStyle, Window, WindowContext, SUBPIXEL_VARIANTS,
|
||||
LineLayoutIndex, ModifiersChangedEvent, MonochromeSprite, MouseEvent, PaintQuad, Path, Pixels,
|
||||
PlatformInputHandler, Point, PolychromeSprite, Quad, RenderGlyphParams, RenderImageParams,
|
||||
RenderSvgParams, Scene, Shadow, SharedString, Size, StrikethroughStyle, Style,
|
||||
TextStyleRefinement, TransformationMatrix, Underline, UnderlineStyle, Window, WindowContext,
|
||||
SUBPIXEL_VARIANTS,
|
||||
};
|
||||
|
||||
pub(crate) type AnyMouseListener =
|
||||
|
@ -1324,4 +1325,22 @@ impl<'a> ElementContext<'a> {
|
|||
},
|
||||
));
|
||||
}
|
||||
|
||||
/// Register a modifiers changed event listener on the window for the next frame.
|
||||
///
|
||||
/// This is a fairly low-level method, so prefer using event handlers on elements unless you have
|
||||
/// a specific need to register a global listener.
|
||||
pub fn on_modifiers_changed(
|
||||
&mut self,
|
||||
listener: impl Fn(&ModifiersChangedEvent, &mut ElementContext) + 'static,
|
||||
) {
|
||||
self.window
|
||||
.next_frame
|
||||
.dispatch_tree
|
||||
.on_modifiers_changed(Rc::new(
|
||||
move |event: &ModifiersChangedEvent, cx: &mut ElementContext<'_>| {
|
||||
listener(event, cx)
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue