keymap, kbd: use PressKind; restore DragRest; phosphor arrow-up/down as fill paths

This commit is contained in:
bflatastic committed 2026-11-21 21:31:14 +07:00
1 parent 53da45bbe4
commit ee19084e8f
8 files changed
+26 -17

No files matched your search

+3 -3
View File
@@ -823,9 +823,9 @@ impl Trigger {
/// `one`, the chord's text, as this kind of press writes it.
fn written(&self, one: String) -> String {
match self.press {
Press::Single => one,
Press::Double => format!("{one} {one}"),
Press::Hold => format!("Hold {one}"),
PressKind::Single => one,
PressKind::Double => format!("{one} {one}"),
PressKind::Hold => format!("Hold {one}"),
}
}
}
+2 -2
View File
@@ -14,7 +14,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use serde::{Deserialize, Serialize};
use crate::chord::{Chord, Press, Trigger};
use crate::chord::{Chord, PressKind, Trigger};
use crate::chord::foreign::{Flavor, ForeignError, ReadNote, read_foreign};
use crate::command::CommandRef;
use crate::keymap::{Binding, CommandDef, CommandKind, Keymap, MAX_BINDINGS, Policy};
@@ -968,7 +968,7 @@ fn key_codes(k: &ForeignKey) -> Vec<(String, bool)> {
/// The first unscoped single-press default of command `i` as (modifiers text, key text), the forms codes decode to.
fn default_parts(keymap: &Keymap, i: usize) -> Option<(String, String)> {
let command = &keymap.catalog().get(i)?.command;
let chord = keymap.default_bindings(command).into_iter().find(|b| b.scope.is_none() && b.trigger.press == Press::Single)?.trigger.chord;
let chord = keymap.default_bindings(command).into_iter().find(|b| b.scope.is_none() && b.trigger.press == PressKind::Single)?.trigger.chord;
let (key, full) = (chord.key.name(), chord.to_string());
let mods = full.strip_suffix(key).unwrap_or_default().trim_end_matches('+');
Some((mods.to_string(), key.to_string()))
+2 -2
View File
@@ -177,7 +177,7 @@ pub fn read(text: &str) -> Result<ForeignSet, KysError> {
let mut key = ForeignKey::read(None, key, flavor);
// Photoshop's tool shortcuts are single keys: one with modifiers is reported as
// unreadable and binds nothing, and the tool keeps the key it has.
if row.tool && key.trigger.as_ref().is_ok_and(|t| !t.chord.mods.is_none() || t.press != crate::chord::Press::Single) {
if row.tool && key.trigger.as_ref().is_ok_and(|t| !t.chord.mods.is_none() || t.press != crate::chord::PressKind::Single) {
key.trigger = Err(ForeignError::UnsupportedModifier(key.text.clone()));
}
entry = entry.with_key(key);
@@ -226,7 +226,7 @@ pub fn write(name: &str, keymap: &Keymap) -> String {
for tools in [false, true] {
for b in keymap.catalog().iter().filter(|b| matches!(b.kind, CommandKind::Tool { .. }) == tools) {
let keys: Vec<String> =
keymap.bindings(&b.command).iter().filter(|k| k.scope.is_none() && k.trigger.press == crate::chord::Press::Single).map(|k| photoshop_key(&k.trigger)).collect();
keymap.bindings(&b.command).iter().filter(|k| k.scope.is_none() && k.trigger.press == crate::chord::PressKind::Single).map(|k| photoshop_key(&k.trigger)).collect();
let Some(first) = keys.first() else { continue };
let label = escape(&b.label.replace('…', "..."));
let id = escape(&b.command.key());
+4 -4
View File
@@ -422,7 +422,7 @@ impl Keymap {
/// The command a hold of `chord` runs where it applies, ranked as the other lookups rank.
pub fn hold_of(&self, chord: &Chord, active: &Active<'_>) -> Option<CommandRef> {
match self.winners(Trigger { chord: chord.effective(self.platform), press: Press::Hold }, active, &[]) {
match self.winners(Trigger { chord: chord.effective(self.platform), press: PressKind::Hold }, active, &[]) {
Winners::None => None,
Winners::Run(i) => Some(self.catalog[i].command.clone()),
Winners::Cycle(cycle) => cycle.first().map(|&i| self.catalog[i].command.clone()),
@@ -499,7 +499,7 @@ impl Keymap {
/// [`shown_chord`](Self::shown_chord) of the command at catalog position `i`, from the bindings.
fn shown_of(&self, i: usize) -> Option<Chord> {
let home = &self.catalog[i].scope;
let single = || self.current[i].iter().filter(|(trigger, _)| trigger.press == Press::Single);
let single = || self.current[i].iter().filter(|(trigger, _)| trigger.press == PressKind::Single);
let runs = |(trigger, scope): &&Bound| {
let name = [scope.as_str()];
let active = match self.scopes.kind(scope) {
@@ -507,7 +507,7 @@ impl Keymap {
ScopeKind::Panel => Active::panel(name[0]),
ScopeKind::Context => Active { panel: None, contexts: &name, typing: false },
};
match self.winners(Trigger { chord: trigger.chord.effective(self.platform), press: Press::Single }, &active, &[]) {
match self.winners(Trigger { chord: trigger.chord.effective(self.platform), press: PressKind::Single }, &active, &[]) {
Winners::None => false,
Winners::Run(j) => j == i,
Winners::Cycle(cycle) => cycle.contains(&i),
@@ -531,7 +531,7 @@ impl Keymap {
Lookup::Cycle(cycle) => return cycle.into_iter().next(),
Lookup::None => {}
}
let want = Trigger { chord: chord.effective(self.platform), press: Press::Single };
let want = Trigger { chord: chord.effective(self.platform), press: PressKind::Single };
self.by_trigger.get(&want)?.iter().find(|&&(i, k)| self.at(i, k).is_some()).map(|&(i, _)| self.catalog[i].command.clone())
}
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="128" y1="40" x2="128" y2="216" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><polyline points="56 144 128 216 200 144" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M205.66,149.66l-72,72a8,8,0,0,1-11.32,0l-72-72a8,8,0,0,1,11.32-11.32L120,196.69V40a8,8,0,0,1,16,0V196.69l58.34-58.35a8,8,0,0,1,11.32,11.32Z"/></svg>

Before

Width:  |  Height:  |  Size: 396 B

After

Width:  |  Height:  |  Size: 239 B

@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="128" y1="216" x2="128" y2="40" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><polyline points="56 112 128 40 200 112" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M205.66,117.66a8,8,0,0,1-11.32,0L136,59.31V216a8,8,0,0,1-16,0V59.31L61.66,117.66a8,8,0,0,1-11.32-11.32l72-72a8,8,0,0,1,11.32,0l72,72A8,8,0,0,1,205.66,117.66Z"/></svg>

Before

Width:  |  Height:  |  Size: 395 B

After

Width:  |  Height:  |  Size: 257 B

+10 -1
View File
@@ -3,9 +3,11 @@
use super::{ItemsHooks, Placement, members};
use crate::contract::collection::{CollectionEvent, LeadOnOpen, LeadSource, ListDrag, SelectMode};
use crate::contract::{Collection, Cx};
use crate::runtime::memory::sub;
use crate::runtime::{drag, pointer};
use craft_behavior::{Flow, ItemLayout, PointerEvent, SelectionChange, SelectionModel};
use craft_keymap::Mods;
use egui::{Pos2, Rect, Vec2};
use egui::{Context, Id, Pos2, Rect, Vec2};
use std::any::TypeId;
/// What made a selection change, reported with it (`CollectionEvent::Selection`): a key, or a pointer pick with the
@@ -16,6 +18,13 @@ pub(super) enum PickBy {
Pointer(Mods),
}
/// What the rest timer of `drag_select` last saw: the drag's pointer and the row it is timing.
#[derive(Clone, Copy, Default)]
struct DragRest {
pointer: Option<Pos2>,
row: Option<usize>,
}
impl<'s, 'r, C: Collection> ItemsHooks<'s, 'r, C> {
pub(super) fn select_mode(comp: &C) -> SelectMode {
comp.items().select
+3 -3
View File
@@ -129,9 +129,9 @@ impl Kbd {
None => one,
};
match trigger.press {
craft_keymap::chord::Press::Single => one,
craft_keymap::chord::Press::Double => format!("{one} {one}"),
craft_keymap::chord::Press::Hold => words.kbd_hold.fill(&[("chord", one.as_str())]),
craft_keymap::chord::PressKind::Single => one,
craft_keymap::chord::PressKind::Double => format!("{one} {one}"),
craft_keymap::chord::PressKind::Hold => words.kbd_hold.fill(&[("chord", one.as_str())]),
}
}