keymap: format, and keep the dispatcher's Default clear of clippy's derive lint

This commit is contained in:
aiongg committed 2026-10-20 15:46:00 +00:00
1 parent 6d96b4f684
commit 9aaf9dfd38
3 files changed
+19 -15

No files matched your search

+10 -9
View File
@@ -238,9 +238,12 @@ pub struct Dispatcher {
text_first: bool,
}
/// eframe's web build sends a press's Text event first when no text field has focus.
const TEXT_FIRST: bool = cfg!(target_arch = "wasm32");
impl Default for Dispatcher {
fn default() -> Dispatcher {
Dispatcher { last: None, repeat: false, clipboard: false, text_first: cfg!(target_arch = "wasm32") }
Dispatcher { last: None, repeat: false, clipboard: false, text_first: TEXT_FIRST }
}
}
@@ -300,11 +303,8 @@ impl Dispatcher {
let held = Mods::from_egui(modifiers, platform);
if let Some(key) = Key::from_egui(*key) {
let plain_clip = is_plain_clipboard(key, held);
let keep = if active.typing {
text_of[i].is_some() || plain_clip
} else {
!self.clipboard && plain_clip && causes[i].is_some()
};
let keep =
if active.typing { text_of[i].is_some() || plain_clip } else { !self.clipboard && plain_clip && causes[i].is_some() };
if keep {
if let Some((j, _)) = causes[i] {
caused_taken[j] = Some(false);
@@ -374,9 +374,10 @@ impl Dispatcher {
if repeat {
return find(false);
}
let again = self.last.as_ref().is_some_and(|l| {
l.chord == first && !l.ran_double && l.panel.as_deref() == active.panel && now >= l.at && now - l.at < DOUBLE_PRESS
});
let again = self
.last
.as_ref()
.is_some_and(|l| l.chord == first && !l.ran_double && l.panel.as_deref() == active.panel && now >= l.at && now - l.at < DOUBLE_PRESS);
let double = if again { find(true) } else { None };
self.last = Some(LastPress { chord: first, at: now, ran_double: double.is_some(), panel: active.panel.map(str::to_owned) });
double.or_else(|| find(false))
+1 -4
View File
@@ -20,10 +20,7 @@ impl Scope {
/// character, or one with whitespace at either end, which binding text would lose.
pub fn new(name: impl Into<String>) -> Option<Scope> {
let name = name.into();
let ok = !name.is_empty()
&& name.len() <= MAX_SCOPE_NAME
&& name.trim() == name
&& !name.chars().any(|c| c == ':' || c.is_control());
let ok = !name.is_empty() && name.len() <= MAX_SCOPE_NAME && name.trim() == name && !name.chars().any(|c| c == ':' || c.is_control());
ok.then_some(Scope(name))
}
+8 -2
View File
@@ -341,7 +341,9 @@ fn changes_that_find_the_overrides_full_are_reported() {
let rows = |failed: &[Failed]| -> Vec<(String, String, FailedChange, Vec<String>)> {
failed.iter().map(|f| (f.command.id.clone(), f.label.clone(), f.change, f.shortcuts.clone())).collect()
};
let row = |id: &str, label: &str, change, shortcuts: &[&str]| (id.to_string(), label.to_string(), change, shortcuts.iter().map(|s| s.to_string()).collect::<Vec<_>>());
let row = |id: &str, label: &str, change, shortcuts: &[&str]| {
(id.to_string(), label.to_string(), change, shortcuts.iter().map(|s| s.to_string()).collect::<Vec<_>>())
};
assert_eq!(
rows(&r.failed),
[
@@ -395,7 +397,11 @@ fn keys_in_unknown_scopes_are_skipped_and_the_rest_apply() {
let mut km = keymap(Platform::Windows);
let r = plan(&set, &km, &options).apply(&mut km);
has(&km, "file.close", &["Cmd+Q", "Text: Cmd+L"]);
let skipped: Vec<_> = r.skipped.iter().map(|s: &Skipped| (s.command.id.as_str(), s.item.as_str(), s.line, s.shortcut.as_str(), s.kept_by.clone(), s.reason)).collect();
let skipped: Vec<_> = r
.skipped
.iter()
.map(|s: &Skipped| (s.command.id.as_str(), s.item.as_str(), s.line, s.shortcut.as_str(), s.kept_by.clone(), s.reason))
.collect();
assert_eq!(skipped, [("file.close", "File > Close", None, "Story: Cmd+K", None, SkipReason::UnknownScope)]);
assert_eq!(serde_json::to_value(r.skipped[0].reason).unwrap(), "unknownScope");
}