Add Caps Lock support (#30470)

Closes #21700

Release Notes:

- Added caps lock support and show a warning if the user is entering an
SSH password with Caps Lock enabled

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: 张小白 <364772080@qq.com>
This commit is contained in:
Maxim Zaks 2025-06-18 02:43:33 +02:00 committed by GitHub
parent e47c48fd3b
commit 90aa99bb14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 146 additions and 31 deletions

View file

@ -2,15 +2,15 @@
use crate::Inspector;
use crate::{
Action, AnyDrag, AnyElement, AnyImageCache, AnyTooltip, AnyView, App, AppContext, Arena, Asset,
AsyncWindowContext, AvailableSpace, Background, BorderStyle, Bounds, BoxShadow, Context,
Corners, CursorStyle, Decorations, DevicePixels, DispatchActionListener, DispatchNodeId,
DispatchTree, DisplayId, Edges, Effect, Entity, EntityId, EventEmitter, FileDropEvent, FontId,
Global, GlobalElementId, GlyphId, GpuSpecs, Hsla, InputHandler, IsZero, KeyBinding, KeyContext,
KeyDownEvent, KeyEvent, Keystroke, KeystrokeEvent, LayoutId, LineLayoutIndex, Modifiers,
ModifiersChangedEvent, MonochromeSprite, MouseButton, MouseEvent, MouseMoveEvent, MouseUpEvent,
Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler,
PlatformWindow, Point, PolychromeSprite, PromptButton, PromptLevel, Quad, Render,
RenderGlyphParams, RenderImage, RenderImageParams, RenderSvgParams, Replay, ResizeEdge,
AsyncWindowContext, AvailableSpace, Background, BorderStyle, Bounds, BoxShadow, Capslock,
Context, Corners, CursorStyle, Decorations, DevicePixels, DispatchActionListener,
DispatchNodeId, DispatchTree, DisplayId, Edges, Effect, Entity, EntityId, EventEmitter,
FileDropEvent, FontId, Global, GlobalElementId, GlyphId, GpuSpecs, Hsla, InputHandler, IsZero,
KeyBinding, KeyContext, KeyDownEvent, KeyEvent, Keystroke, KeystrokeEvent, LayoutId,
LineLayoutIndex, Modifiers, ModifiersChangedEvent, MonochromeSprite, MouseButton, MouseEvent,
MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,
PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptButton, PromptLevel, Quad,
Render, RenderGlyphParams, RenderImage, RenderImageParams, RenderSvgParams, Replay, ResizeEdge,
SMOOTH_SVG_SCALE_FACTOR, SUBPIXEL_VARIANTS, ScaledPixels, Scene, Shadow, SharedString, Size,
StrikethroughStyle, Style, SubscriberSet, Subscription, TaffyLayoutEngine, Task, TextStyle,
TextStyleRefinement, TransformationMatrix, Underline, UnderlineStyle, WindowAppearance,
@ -796,6 +796,7 @@ pub struct Window {
mouse_position: Point<Pixels>,
mouse_hit_test: HitTest,
modifiers: Modifiers,
capslock: Capslock,
scale_factor: f32,
pub(crate) bounds_observers: SubscriberSet<(), AnyObserver>,
appearance: WindowAppearance,
@ -907,6 +908,7 @@ impl Window {
let sprite_atlas = platform_window.sprite_atlas();
let mouse_position = platform_window.mouse_position();
let modifiers = platform_window.modifiers();
let capslock = platform_window.capslock();
let content_size = platform_window.content_size();
let scale_factor = platform_window.scale_factor();
let appearance = platform_window.appearance();
@ -1015,6 +1017,7 @@ impl Window {
.update(&mut cx, |_, window, cx| {
window.active.set(active);
window.modifiers = window.platform_window.modifiers();
window.capslock = window.platform_window.capslock();
window
.activation_observers
.clone()
@ -1100,6 +1103,7 @@ impl Window {
mouse_position,
mouse_hit_test: HitTest::default(),
modifiers,
capslock,
scale_factor,
bounds_observers: SubscriberSet::new(),
appearance,
@ -1728,6 +1732,11 @@ impl Window {
self.modifiers
}
/// The current state of the keyboard's capslock
pub fn capslock(&self) -> Capslock {
self.capslock
}
fn complete_frame(&self) {
self.platform_window.completed_frame();
}
@ -3352,6 +3361,7 @@ impl Window {
}
PlatformInput::ModifiersChanged(modifiers_changed) => {
self.modifiers = modifiers_changed.modifiers;
self.capslock = modifiers_changed.capslock;
PlatformInput::ModifiersChanged(modifiers_changed)
}
PlatformInput::ScrollWheel(scroll_wheel) => {