This commit is contained in:
Junkui Zhang
2025-07-09 19:37:46 +08:00
parent 1610d05526
commit 0c96bcd572
2 changed files with 28 additions and 23 deletions

View File

@@ -42,12 +42,12 @@ use gpui::{
Action, Along, AnyElement, App, AppContext, AvailableSpace, Axis as ScrollbarAxis, BorderStyle,
Bounds, ClickEvent, ContentMask, Context, Corner, Corners, CursorStyle, DispatchPhase, Edges,
Element, ElementInputHandler, Entity, Focusable as _, FontId, GlobalElementId, Hitbox,
HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero, KeybindingKeystroke, 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,
HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero, KeybindingKeystroke, 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,
};
use itertools::Itertools;
use language::language_settings::{

View File

@@ -1202,7 +1202,7 @@ async fn save_keybinding_update(
}
struct KeystrokeInput {
keystrokes: Vec<Keystroke>,
keystrokes: Vec<KeybindingKeystroke>,
focus_handle: FocusHandle,
}
@@ -1230,10 +1230,14 @@ impl KeystrokeInput {
last.modifiers = event.modifiers;
}
} else {
self.keystrokes.push(Keystroke {
self.keystrokes.push(KeybindingKeystroke {
inner: Keystroke {
modifiers: event.modifiers,
key: "".to_string(),
key_char: None,
},
modifiers: event.modifiers,
key: "".to_string(),
key_char: None,
});
}
cx.stop_propagation();
@@ -1249,12 +1253,13 @@ impl KeystrokeInput {
if event.is_held {
return;
}
let keystroke = event.keystroke.clone().into_keybinding_keystroke();
if let Some(last) = self.keystrokes.last_mut()
&& last.key.is_empty()
{
*last = event.keystroke.clone();
*last = keystroke;
} else {
self.keystrokes.push(event.keystroke.clone());
self.keystrokes.push(keystroke);
}
cx.stop_propagation();
cx.notify();
@@ -1266,22 +1271,27 @@ impl KeystrokeInput {
_window: &mut Window,
cx: &mut Context<Self>,
) {
let keystroke = event.keystroke.clone().into_keybinding_keystroke();
if let Some(last) = self.keystrokes.last_mut()
&& !last.key.is_empty()
&& last.modifiers == event.keystroke.modifiers
&& last.modifiers == keystroke.modifiers
{
self.keystrokes.push(Keystroke {
modifiers: event.keystroke.modifiers,
self.keystrokes.push(KeybindingKeystroke {
inner: Keystroke {
modifiers: event.keystroke.modifiers,
key: "".to_string(),
key_char: None,
},
modifiers: keystroke.modifiers,
key: "".to_string(),
key_char: None,
});
}
cx.stop_propagation();
cx.notify();
}
fn keystrokes(&self) -> Vec<KeybindingKeystroke> {
let keystrokes = if self
fn keystrokes(&self) -> &[KeybindingKeystroke] {
if self
.keystrokes
.last()
.map_or(false, |last| last.key.is_empty())
@@ -1289,12 +1299,7 @@ impl KeystrokeInput {
&self.keystrokes[..self.keystrokes.len() - 1]
} else {
&self.keystrokes
};
keystrokes
.to_vec()
.into_iter()
.map(|keystroke| keystroke.into_keybinding_keystroke())
.collect()
}
}
}