forge
Explore
Log in

Don't you dare go Hollow

🔀 merge(C3): the actions card answers to F1 and to a search box — every action findable by name

Browse files at this commit

4cb3df0079e7d7a339a4f5c1bf7f7b486c667abaAhmet Kaan GümüşParent: edf0cd9d4255d9
crates/app/src/keymap.rsmodified+27 -4
@@ -80,12 +80,16 @@ pub enum ActionId {
80 Mix,80 Mix,
81 ToggleSnap,81 ToggleSnap,
82 CancelExport,82 CancelExport,
83+ /// Opens the actions card -- the list every other action is on. A door of
84+ /// its own, because a card reachable only by a button in the panel is one a
85+ /// hand on the keyboard has to leave the keyboard for.
86+ ShowActions,
83 }87 }
84 88
85 impl ActionId {89 impl ActionId {
86 /// Display order everywhere -- the editor lists them in it and90 /// Display order everywhere -- the editor lists them in it and
87 /// [`Keymap::defaults`] binds them in it.91 /// [`Keymap::defaults`] binds them in it.
88- pub const ALL: [ActionId; 40] = [92+ pub const ALL: [ActionId; 41] = [
89 ActionId::Play,93 ActionId::Play,
90 ActionId::StepBack,94 ActionId::StepBack,
91 ActionId::StepForward,95 ActionId::StepForward,
@@ -126,6 +130,7 @@ impl ActionId {
126 ActionId::Mix,130 ActionId::Mix,
127 ActionId::ToggleSnap,131 ActionId::ToggleSnap,
128 ActionId::CancelExport,132 ActionId::CancelExport,
133+ ActionId::ShowActions,
129 ];134 ];
130 135
131 /// What a person calls it.136 /// What a person calls it.
@@ -171,6 +176,7 @@ impl ActionId {
171 ActionId::Mix => "Mix: track volumes and the limiter…",176 ActionId::Mix => "Mix: track volumes and the limiter…",
172 ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)",177 ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)",
173 ActionId::CancelExport => "Cancel export",178 ActionId::CancelExport => "Cancel export",
179+ ActionId::ShowActions => "All actions and their keys…",
174 }180 }
175 }181 }
176 182
@@ -218,6 +224,7 @@ impl ActionId {
218 ActionId::Mix => "mix",224 ActionId::Mix => "mix",
219 ActionId::ToggleSnap => "toggle-snap",225 ActionId::ToggleSnap => "toggle-snap",
220 ActionId::CancelExport => "cancel-export",226 ActionId::CancelExport => "cancel-export",
227+ ActionId::ShowActions => "show-actions",
221 }228 }
222 }229 }
223 230
@@ -282,7 +289,12 @@ impl ActionId {
282 // are this machine's monitoring. Both are audio, and the card says289 // are this machine's monitoring. Both are audio, and the card says
283 // which is which.290 // which is which.
284 | ActionId::Mix => Category::Audio,291 | ActionId::Mix => Category::Audio,
285- ActionId::Save | ActionId::Export | ActionId::CancelExport => Category::File,292+ // Under the heading the panel button sits in, beside the save and
293+ // the export it stands next to on screen.
294+ ActionId::Save
295+ | ActionId::Export
296+ | ActionId::CancelExport
297+ | ActionId::ShowActions => Category::File,
286 }298 }
287 }299 }
288 }300 }
@@ -681,6 +693,11 @@ impl Keymap {
681 // it with: free here, and nowhere near the two keys that delete.693 // it with: free here, and nowhere near the two keys that delete.
682 b(ActionId::ToggleSnap, "n", false),694 b(ActionId::ToggleSnap, "n", false),
683 b(ActionId::CancelExport, "escape", false),695 b(ActionId::CancelExport, "escape", false),
696+ // The help key, where every program's list of what it can do
697+ // has always been. Free -- gpui names it "f1"
698+ // (platform.rs:880, the keysym's own name lowercased) -- and
699+ // not a letter, so it takes nothing away from the clip keys.
700+ b(ActionId::ShowActions, "f1", false),
684 ],701 ],
685 }702 }
686 }703 }
@@ -942,7 +959,8 @@ mod tests {
942 #[test]959 #[test]
943 fn every_default_stroke_reaches_its_action() {960 fn every_default_stroke_reaches_its_action() {
944 let k = Keymap::defaults();961 let k = Keymap::defaults();
945- assert_eq!(k.entries().len(), 42);962+ assert_eq!(k.entries().len(), 43);
963+ assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));
946 assert_eq!(k.lookup("space", false), Some(ActionId::Play));964 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
947 // The seek keys: bare arrows a frame, ctrl arrows a second, and the two965 // The seek keys: bare arrows a frame, ctrl arrows a second, and the two
948 // ends of the timeline.966 // ends of the timeline.
@@ -1133,6 +1151,10 @@ mod tests {
1133 // Refused means unchanged, on both sides of the conflict.1151 // Refused means unchanged, on both sides of the conflict.
1134 assert_eq!(k.lookup("e", false), Some(ActionId::Export));1152 assert_eq!(k.lookup("e", false), Some(ActionId::Export));
1135 assert_eq!(k.lookup("space", false), Some(ActionId::Play));1153 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
1154+ // And the refusal is a name, not a shrug: it is the holder's own label
1155+ // the card prints back at the waiting row (`Player::capture`, "ALREADY
1156+ // BOUND — space is Play / Pause").
1157+ assert_eq!(ActionId::Play.label(), "Play / Pause");
1136 // A free stroke takes, and the old one stops meaning anything.1158 // A free stroke takes, and the old one stops meaning anything.
1137 assert_eq!(k.rebind_action(ActionId::Export, chord("w", true)), Ok(()));1159 assert_eq!(k.rebind_action(ActionId::Export, chord("w", true)), Ok(()));
1138 assert_eq!(k.lookup("w", true), Some(ActionId::Export));1160 assert_eq!(k.lookup("w", true), Some(ActionId::Export));
@@ -1176,8 +1198,9 @@ mod tests {
1176 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");1198 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");
1177 // The label is the editor's column, and never the file's word for it.1199 // The label is the editor's column, and never the file's word for it.
1178 assert_eq!(ActionId::CancelExport.label(), "Cancel export");1200 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
1179- assert_eq!(ActionId::ALL.len(), 40);1201+ assert_eq!(ActionId::ALL.len(), 41);
1180 assert_eq!(k.display(ActionId::ToggleSnap), "n");1202 assert_eq!(k.display(ActionId::ToggleSnap), "n");
1203+ assert_eq!(k.display(ActionId::ShowActions), "f1");
1181 assert_eq!(k.display(ActionId::ZoomIn), "ctrl+=");1204 assert_eq!(k.display(ActionId::ZoomIn), "ctrl+=");
1182 }1205 }
1183 1206
crates/app/src/main.rsmodified+292 -28
@@ -21,9 +21,9 @@ use engine::{Clip, Codec, ExportHandle, Frame, PlaybackSession};
21 use gpui::{21 use gpui::{
22 AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent,22 AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent,
23 FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,23 FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
24- PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollWheelEvent, SharedString, Size,24+ PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollHandle, ScrollWheelEvent,
25- Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div, img,25+ SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions,
26- point, prelude::*, px, relative, rgb, rgba, size,26+ canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size,
27 };27 };
28 28
29 /// Editor chrome: three grays and one accent, all darker than the picture so the29 /// Editor chrome: three grays and one accent, all darker than the picture so the
@@ -493,6 +493,65 @@ fn keys_rows() -> Vec<KeyRow> {
493 rows493 rows
494 }494 }
495 495
496+/// [`keys_rows`] with a search applied: the rows whose label or whose stroke
497+/// carries `needle`, and the heading each one lives under. A heading with
498+/// nothing left beneath it goes with them -- an empty "Playback" over a gap
499+/// reads as a list that lost its rows rather than as a search that found none.
500+///
501+/// Each row keeps the index it has in the unfiltered list, so an element id is
502+/// the same one before and after a keystroke: filtering is a look at the list,
503+/// and gpui's per-element state is keyed on that id.
504+///
505+/// Case-insensitive substring, on both columns: people look for an action by
506+/// what it does ("vol") and for a stroke by what they pressed ("ctrl").
507+fn keys_filter(needle: &str, keymap: &Keymap) -> Vec<(usize, KeyRow)> {
508+ let needle = needle.trim().to_lowercase();
509+ let rows = keys_rows().into_iter().enumerate();
510+ if needle.is_empty() {
511+ return rows.collect();
512+ }
513+ let hit = |label: &str, chord: &str| {
514+ label.to_lowercase().contains(&needle) || chord.to_lowercase().contains(&needle)
515+ };
516+ let mut out: Vec<(usize, KeyRow)> = Vec::new();
517+ // The heading above the row being looked at, until a row under it earns it
518+ // a place -- then it goes in once, ahead of that row.
519+ let mut pending: Option<(usize, KeyRow)> = None;
520+ for (i, row) in rows {
521+ match &row {
522+ KeyRow::Head(_) => pending = Some((i, row)),
523+ KeyRow::Act(action) => {
524+ if hit(action.label(), &keymap.display(*action)) {
525+ out.extend(pending.take());
526+ out.push((i, row));
527+ }
528+ }
529+ KeyRow::Fixed(f) => {
530+ let fixed = &keymap::FIXED[*f];
531+ if hit(fixed.label, fixed.chord) {
532+ out.extend(pending.take());
533+ out.push((i, row));
534+ }
535+ }
536+ }
537+ }
538+ out
539+}
540+
541+/// The character a stroke types into the actions card's search box, if it types
542+/// one. gpui reports a printable key as itself and the space bar by name
543+/// (platform.rs:866), and everything else -- the arrows, the function keys --
544+/// is a word this must not spell into the box letter by letter.
545+fn typed(key: &str) -> Option<char> {
546+ match key {
547+ "space" => Some(' '),
548+ _ => key
549+ .chars()
550+ .next()
551+ .filter(|c| c.is_ascii_graphic() && key.chars().count() == 1),
552+ }
553+}
554+
496 /// The project resolutions [`Player::cycle_resolution`] offers, largest first.555 /// The project resolutions [`Player::cycle_resolution`] offers, largest first.
497 /// A short list of the sizes people name; the media's own is cycled in beside556 /// A short list of the sizes people name; the media's own is cycled in beside
498 /// them, which is what makes the trip round come back to where it started.557 /// them, which is what makes the trip round come back to where it started.
@@ -919,6 +978,16 @@ struct Player {
919 /// pointer: a stroke or a click meant for a row must not also cut the978 /// pointer: a stroke or a click meant for a row must not also cut the
920 /// timeline.979 /// timeline.
921 keys_open: bool,980 keys_open: bool,
981+ /// What has been typed into the card's search box, which is the card's own
982+ /// input exactly as the export card's digits are (nothing in it takes
983+ /// focus, so the root's key handler is the field). Emptied every time the
984+ /// card opens: a search is a look at the list, not a setting.
985+ keys_search: String,
986+ /// Where that list is scrolled to. Held here rather than left to the
987+ /// wheel alone: forty actions are four times what a 360 px window shows,
988+ /// and the rows past the fold have to be reachable from the keyboard that
989+ /// is already typing in the search box.
990+ keys_scroll: ScrollHandle,
922 /// The export options card is up: what the export action opens now, so991 /// The export options card is up: what the export action opens now, so
923 /// nothing is written until the card's own button says so. One card at a992 /// nothing is written until the card's own button says so. One card at a
924 /// time -- opening either closes the other, since both are the whole window993 /// time -- opening either closes the other, since both are the whole window
@@ -1232,6 +1301,7 @@ impl Player {
1232 // Nothing to cancel while nothing is exporting; the export guard in1301 // Nothing to cancel while nothing is exporting; the export guard in
1233 // the key handler is what answers this one while there is.1302 // the key handler is what answers this one while there is.
1234 ActionId::CancelExport => {}1303 ActionId::CancelExport => {}
1304+ ActionId::ShowActions => self.show_actions(cx),
1235 }1305 }
1236 }1306 }
1237 1307
@@ -1248,6 +1318,37 @@ impl Player {
1248 cx.notify();1318 cx.notify();
1249 }1319 }
1250 1320
1321+ /// The actions card, from its key, from the panel button, or from its own
1322+ /// row: open, with an empty search box -- a card that opens showing the
1323+ /// last search would hide most of the list for a reason nobody remembers.
1324+ fn show_actions(&mut self, cx: &mut Context<Self>) {
1325+ self.keys_open = true;
1326+ self.keys_search.clear();
1327+ self.scroll_keys(None);
1328+ self.rebinding = None;
1329+ // One card at a time, the rule the other cards follow.
1330+ self.export_open = false;
1331+ cx.notify();
1332+ }
1333+
1334+ /// Moves the actions card's row list by `by` pixels, or puts it back at the
1335+ /// top (`None`). Back to the top after every keystroke that changes the
1336+ /// search: a filtered list is shorter than the offset a scrolled one left
1337+ /// behind, and a card showing the empty space past its last row reads as a
1338+ /// search that found nothing.
1339+ ///
1340+ /// Clamped to what there is to scroll, so the list cannot be pushed off
1341+ /// either end -- `max_offset` is what the last paint measured, which is the
1342+ /// only place that number exists.
1343+ fn scroll_keys(&self, by: Option<f32>) {
1344+ let at = match by {
1345+ Some(by) => (f32::from(self.keys_scroll.offset().y) + by)
1346+ .clamp(-f32::from(self.keys_scroll.max_offset().height), 0.),
1347+ None => 0.,
1348+ };
1349+ self.keys_scroll.set_offset(point(px(0.), px(at)));
1350+ }
1351+
1251 /// Whether the editor can be asked for `action` right now, and why not when1352 /// Whether the editor can be asked for `action` right now, and why not when
1252 /// it cannot. `on` is the clip the question is about -- the one a clip menu1353 /// it cannot. `on` is the clip the question is about -- the one a clip menu
1253 /// was opened on -- and `None` asks about the marked clip instead, which is1354 /// was opened on -- and `None` asks about the marked clip instead, which is
@@ -3888,14 +3989,37 @@ impl Render for Player {
3888 cx.notify();3989 cx.notify();
3889 return;3990 return;
3890 }3991 }
3891- // The overlay owns the keyboard while it is up: a stroke aimed3992+ // The overlay owns the keyboard while it is up -- but it types
3892- // at a row must not also cut the timeline, and the way out of it3993+ // now: a printable stroke is the search box's, which is why
3893- // is the same key that gets out of a capture.3994+ // nothing here reaches the keymap. A waiting row is answered
3995+ // above and still wins, so a rebind onto "v" binds the key
3996+ // rather than typing it.
3894 if this.keys_open {3997 if this.keys_open {
3895 if key == ESCAPE {3998 if key == ESCAPE {
3896- this.keys_open = false;3999+ // Two steps out, the way a search box anywhere gets
3897- cx.notify();4000+ // out: the filter first -- the whole list back --
4001+ // and the card only once there is no search to clear.
4002+ if this.keys_search.is_empty() {
4003+ this.keys_open = false;
4004+ } else {
4005+ this.keys_search.clear();
4006+ this.scroll_keys(None);
4007+ }
4008+ // The rows past the fold, without a wheel: forty actions
4009+ // are four times what the viewport shows, and the hand
4010+ // typing in the search box is already on the keyboard.
4011+ } else if key == "up" {
4012+ this.scroll_keys(Some(KEYS_ROW_H));
4013+ } else if key == "down" {
4014+ this.scroll_keys(Some(-KEYS_ROW_H));
4015+ } else if key == "backspace" {
4016+ this.keys_search.pop();
4017+ this.scroll_keys(None);
4018+ } else if let Some(c) = typed(key) {
4019+ this.keys_search.push(c);
4020+ this.scroll_keys(None);
3898 }4021 }
4022+ cx.notify();
3899 return;4023 return;
3900 }4024 }
3901 // The export card owns it the same way, and for the same4025 // The export card owns it the same way, and for the same
@@ -4998,23 +5122,27 @@ impl Player {
4998 live,5122 live,
4999 cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)),5123 cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)),
5000 ))5124 ))
5001- // No shortcut of its own -- and closed while an export runs,5125+ // Closed while an export runs, which is what keeps a waiting
5002- // which is what keeps a waiting row from swallowing the5126+ // row from swallowing the escape the progress line promises
5003- // escape the progress line promises cancels the export.5127+ // cancels the export.
5004 .child(control(5128 .child(control(
5005 "keys",5129 "keys",
5006 None,5130 None,
5007 "Actions",5131 "Actions",
5008 // The pointer's way to every action there is, including5132 // The pointer's way to every action there is, including
5009 // the ones no button here has room for.5133 // the ones no button here has room for.
5010- "do any action, or change the key that does it".to_string(),5134+ format!(
5135+ "{} — do any action, or change the key that does it",
5136+ key(ActionId::ShowActions)
5137+ ),
5011 !exporting,5138 !exporting,
5012- cx.listener(|this, _: &ClickEvent, _, cx| {5139+ cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open {
5013- this.keys_open = !this.keys_open;5140+ true => {
5014- this.rebinding = None;5141+ this.keys_open = false;
5015- // One card at a time, both ways round.5142+ this.rebinding = None;
5016- this.export_open = false;5143+ cx.notify();
5017- cx.notify();5144+ }
5145+ false => this.show_actions(cx),
5018 }),5146 }),
5019 )),5147 )),
5020 )5148 )
@@ -5248,7 +5376,26 @@ impl Player {
5248 .px(px(6.))5376 .px(px(6.))
5249 .rounded(px(3.))5377 .rounded(px(3.))
5250 };5378 };
5251- for (i, key_row) in keys_rows().into_iter().enumerate() {5379+ let found = keys_filter(&self.keys_search, &self.keymap);
5380+ // What the search box says: the typed text, and how much of the list is
5381+ // left under it -- a filter that found nothing has to say so, or the
5382+ // card reads as a list that lost its rows.
5383+ let search = if self.keys_search.is_empty() {
5384+ "search: type to filter · ↑ ↓ scroll the list".to_string()
5385+ } else {
5386+ let rows = found
5387+ .iter()
5388+ .filter(|(_, r)| !matches!(r, KeyRow::Head(_)))
5389+ .count();
5390+ match rows {
5391+ 0 => format!(
5392+ "search: {} — nothing matches · {out} clears",
5393+ self.keys_search
5394+ ),
5395+ n => format!("search: {} — {n} shown · {out} clears", self.keys_search),
5396+ }
5397+ };
5398+ for (i, key_row) in found {
5252 rows.push(match key_row {5399 rows.push(match key_row {
5253 KeyRow::Head(category) => div()5400 KeyRow::Head(category) => div()
5254 .flex_none()5401 .flex_none()
@@ -5386,6 +5533,19 @@ impl Player {
5386 }),5533 }),
5387 ),5534 ),
5388 )5535 )
5536+ // The search box: no focus and no text field -- the
5537+ // card's key handler is the field, exactly as the
5538+ // export card's digits are typed into it. Its own line
5539+ // above the list, so the rows below it are always the
5540+ // answer to what it says.
5541+ .child(
5542+ div()
5543+ .flex_none()
5544+ .px(px(6.))
5545+ .text_size(px(11.))
5546+ .text_color(rgb(INK_DIM))
5547+ .child(search),
5548+ )
5389 // Capped and scrolling rather than as tall as the action5549 // Capped and scrolling rather than as tall as the action
5390 // list happens to be: the list grows with the editor,5550 // list happens to be: the list grows with the editor,
5391 // the smallest window does not.5551 // the smallest window does not.
@@ -5397,6 +5557,10 @@ impl Player {
5397 .gap(px(2.))5557 .gap(px(2.))
5398 .max_h(px(KEYS_ROWS_H))5558 .max_h(px(KEYS_ROWS_H))
5399 .overflow_y_scroll()5559 .overflow_y_scroll()
5560+ // The wheel's offset and the arrow keys' are
5561+ // the same one, so the two cannot disagree
5562+ // about where the list is.
5563+ .track_scroll(&self.keys_scroll)
5400 .children(rows),5564 .children(rows),
5401 ),5565 ),
5402 ),5566 ),
@@ -8253,6 +8417,17 @@ struct Ctx {
8253 /// disagree about what an action needs -- exactly the reason [`Player::act`] is8417 /// disagree about what an action needs -- exactly the reason [`Player::act`] is
8254 /// one table too.8418 /// one table too.
8255 fn enable(action: ActionId, ctx: Ctx) -> Enable {8419 fn enable(action: ActionId, ctx: Ctx) -> Enable {
8420+ // The one action that is about the editor rather than about the timeline:
8421+ // the list of what everything does, and where a key is changed. An empty
8422+ // window has no clips and still has keys -- so this answers ahead of the
8423+ // timeline question, and only an export shuts it (a waiting row would
8424+ // swallow the escape the progress line promises cancels the export).
8425+ if action == ActionId::ShowActions {
8426+ return match ctx.exporting {
8427+ true => Enable::No("an export is running"),
8428+ false => Enable::Yes,
8429+ };
8430+ }
8256 if !ctx.timeline {8431 if !ctx.timeline {
8257 return Enable::No("no timeline open");8432 return Enable::No("no timeline open");
8258 }8433 }
@@ -10273,11 +10448,11 @@ mod tests {
10273 enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y,10448 enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y,
10274 estimated_mb, export_path, export_settings, format_key,10449 estimated_mb, export_path, export_settings, format_key,
10275 format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram,10450 format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram,
10276- inserted_band, is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at,10451+ inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h,
10277- next_container,10452+ marked, menu_at, next_container, normalise, nothing_to_play, panel_h, project_path,
10278- normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due,10453+ push_digit, retarget, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped,
10279- show_label, silence_rate, snap_cue, snap_marks, snapped, source_tint, span_partner,10454+ source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport,
10280- speed_at, summary_head, summary_tail, timecode, transport, unseen_paths, unseen_sources,10455+ typed, unseen_paths, unseen_sources,
10281 whole_take, window_title,10456 whole_take, window_title,
10282 };10457 };
10283 use super::{10458 use super::{
@@ -12093,19 +12268,106 @@ mod tests {
12093 assert!(KEYS_ROW_H >= HIT_MIN);12268 assert!(KEYS_ROW_H >= HIT_MIN);
12094 }12269 }
12095 12270
12271+ /// The search box: what a typed word leaves standing. Forty actions is more
12272+ /// than a 360 px window shows at once, so this is the card's answer to
12273+ /// "where is the one I want" -- and a heading with nothing under it would
12274+ /// be worse than no filter at all.
12275+ #[test]
12276+ fn a_search_leaves_the_rows_it_names_under_their_own_headings() {
12277+ use keymap::{ActionId, Category, Keymap};
12278+ let keymap = Keymap::defaults();
12279+ let acts = |found: &[(usize, KeyRow)]| -> Vec<ActionId> {
12280+ found
12281+ .iter()
12282+ .filter_map(|(_, r)| match r {
12283+ KeyRow::Act(a) => Some(*a),
12284+ _ => None,
12285+ })
12286+ .collect()
12287+ };
12288+ let heads = |found: &[(usize, KeyRow)]| -> Vec<Category> {
12289+ found
12290+ .iter()
12291+ .filter_map(|(_, r)| match r {
12292+ KeyRow::Head(c) => Some(*c),
12293+ _ => None,
12294+ })
12295+ .collect()
12296+ };
12297+ // Nothing typed hides nothing, and every row keeps its place in the
12298+ // unfiltered list: an element id must not move under a keystroke.
12299+ let all = keys_filter("", &keymap);
12300+ assert_eq!(all.len(), keys_rows().len());
12301+ assert!(all.iter().enumerate().all(|(n, (i, _))| n == *i));
12302+ // The word the user types is the word on the row. The mix card names
12303+ // the track volumes, so it is an honest hit; the fixed row about the
12304+ // volume keys is another, and each comes with its own heading only.
12305+ let vol = keys_filter("vol", &keymap);
12306+ assert_eq!(
12307+ acts(&vol),
12308+ vec![ActionId::VolumeUp, ActionId::VolumeDown, ActionId::Mix]
12309+ );
12310+ assert_eq!(heads(&vol), vec![Category::Audio, Category::View]);
12311+ // Case is not part of the question, in either direction.
12312+ assert_eq!(keys_filter("VoL", &keymap).len(), vol.len());
12313+ // The stroke column is searched too -- "what did ctrl do again" -- and
12314+ // an unbound-looking word finds nothing rather than everything.
12315+ let ctrl = keys_filter("ctrl+", &keymap);
12316+ assert!(acts(&ctrl).contains(&ActionId::Save));
12317+ assert!(!acts(&ctrl).contains(&ActionId::Play));
12318+ assert!(
12319+ keys_filter("qzx", &keymap).is_empty(),
12320+ "headings left behind"
12321+ );
12322+ // The card's own door is on the card, by name and by stroke.
12323+ assert_eq!(
12324+ acts(&keys_filter("f1", &keymap)),
12325+ vec![ActionId::ShowActions]
12326+ );
12327+ assert_eq!(
12328+ acts(&keys_filter("all actions", &keymap)),
12329+ vec![ActionId::ShowActions]
12330+ );
12331+ }
12332+
12333+ /// What a keystroke means to that box: a letter is a letter, and a word
12334+ /// gpui reports for a key that prints nothing is not typed letter by
12335+ /// letter into the search.
12336+ #[test]
12337+ fn only_a_printable_stroke_types_into_the_search() {
12338+ assert_eq!(typed("a"), Some('a'));
12339+ assert_eq!(typed("-"), Some('-'));
12340+ assert_eq!(typed("1"), Some('1'));
12341+ // The one printable key gpui reports by name.
12342+ assert_eq!(typed("space"), Some(' '));
12343+ for word in ["left", "escape", "f1", "backspace", "tab", "delete", "home"] {
12344+ assert_eq!(typed(word), None, "{word}");
12345+ }
12346+ }
12347+
12096 #[test]12348 #[test]
12097 fn the_keybindings_card_fits_the_smallest_window() {12349 fn the_keybindings_card_fits_the_smallest_window() {
12098 // The row list is capped and scrolls, so the card's height no longer12350 // The row list is capped and scrolls, so the card's height no longer
12099- // depends on how many actions there are: a title, a status line and the12351+ // depends on how many actions there are: a title, a status line, the
12100- // viewport, inside the 640x360 the rest of the layout is sized for.12352+ // search box and the viewport, inside the 640x360 the rest of the
12353+ // layout is sized for.
12101 let title = 17.; // 13 px text on its own line12354 let title = 17.; // 13 px text on its own line
12102 let status = 28.; // 11 px text, two lines: a refusal wraps12355 let status = 28.; // 11 px text, two lines: a refusal wraps
12103- let gaps = 3. * 2.;12356+ let search = 15.; // 11 px text, one line: it never wraps
12357+ let gaps = 4. * 2.;
12104 let padding = 24.;12358 let padding = 24.;
12105 assert!(12359 assert!(
12106- title + status + KEYS_ROWS_H + gaps + padding <= 360.,12360+ title + status + search + KEYS_ROWS_H + gaps + padding <= 360.,
12107 "card too tall"12361 "card too tall"
12108 );12362 );
12363+ // ...and the list is the only part that grows with the editor, so the
12364+ // rows past the fold are reached by scrolling that viewport (and, with
12365+ // forty of them, by the search box above it) rather than by a card
12366+ // taller than the window.
12367+ assert!(
12368+ keys_rows().len() as f32 * KEYS_ROW_H > KEYS_ROWS_H,
12369+ "the list outgrew the viewport long ago; the cap must still scroll"
12370+ );
12109 // The cap is only honest if it is the taller list that scrolls, not the12371 // The cap is only honest if it is the taller list that scrolls, not the
12110 // card that grows: every action must be reachable by scrolling, and12372 // card that grows: every action must be reachable by scrolling, and
12111 // enough of them visible that the list reads as a list.12373 // enough of them visible that the list reads as a list.
@@ -13905,6 +14167,8 @@ fn main() {
13905 project_path: project.clone(),14167 project_path: project.clone(),
13906 keymap: keymap.clone(),14168 keymap: keymap.clone(),
13907 keys_open: false,14169 keys_open: false,
14170+ keys_search: String::new(),
14171+ keys_scroll: ScrollHandle::new(),
13908 export_open: false,14172 export_open: false,
13909 export_grouped: true,14173 export_grouped: true,
13910 export_refusals_inline: false,14174 export_refusals_inline: false,