forge
Explore
Log in

Don't you dare go Hollow

The actions card has a door and a search box

Browse files at this commit

d4255d945e3de39cdea566cc4cd419c8c518accaAhmet Kaan GümüşParent: 680220d
  • feat
    • the actions card has a door and a search box
Show full message
✨ feat(keys): the actions card has a door and a search box

Forty actions do not fit a 360 px window, and the only way in was a button
in the panel. Both halves of that:

- F1 opens it (ActionId::ShowActions, Category::File, beside the save and
  the export it stands next to on screen). The panel button is still its
  pointer door and now says the key in its tooltip.
- Typing filters: label and stroke, case-insensitive substring, headings
  with nothing left under them gone with their rows. Escape clears the
  search first and closes the card second -- a capture waiting for a
  stroke still wins over both.
- Up and down scroll the row list from the keyboard, so the rows past the
  fold are reachable without a wheel; the search resets it to the top,
  since a filtered list is shorter than the offset a scrolled one left.

A stroke another action holds is refused by that action's name, as it
always was (keymap::rebind_action) -- nothing here steals a chord.
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
@@ -461,6 +461,65 @@ fn keys_rows() -> Vec<KeyRow> {
461 rows461 rows
462 }462 }
463 463
464+/// [`keys_rows`] with a search applied: the rows whose label or whose stroke
465+/// carries `needle`, and the heading each one lives under. A heading with
466+/// nothing left beneath it goes with them -- an empty "Playback" over a gap
467+/// reads as a list that lost its rows rather than as a search that found none.
468+///
469+/// Each row keeps the index it has in the unfiltered list, so an element id is
470+/// the same one before and after a keystroke: filtering is a look at the list,
471+/// and gpui's per-element state is keyed on that id.
472+///
473+/// Case-insensitive substring, on both columns: people look for an action by
474+/// what it does ("vol") and for a stroke by what they pressed ("ctrl").
475+fn keys_filter(needle: &str, keymap: &Keymap) -> Vec<(usize, KeyRow)> {
476+ let needle = needle.trim().to_lowercase();
477+ let rows = keys_rows().into_iter().enumerate();
478+ if needle.is_empty() {
479+ return rows.collect();
480+ }
481+ let hit = |label: &str, chord: &str| {
482+ label.to_lowercase().contains(&needle) || chord.to_lowercase().contains(&needle)
483+ };
484+ let mut out: Vec<(usize, KeyRow)> = Vec::new();
485+ // The heading above the row being looked at, until a row under it earns it
486+ // a place -- then it goes in once, ahead of that row.
487+ let mut pending: Option<(usize, KeyRow)> = None;
488+ for (i, row) in rows {
489+ match &row {
490+ KeyRow::Head(_) => pending = Some((i, row)),
491+ KeyRow::Act(action) => {
492+ if hit(action.label(), &keymap.display(*action)) {
493+ out.extend(pending.take());
494+ out.push((i, row));
495+ }
496+ }
497+ KeyRow::Fixed(f) => {
498+ let fixed = &keymap::FIXED[*f];
499+ if hit(fixed.label, fixed.chord) {
500+ out.extend(pending.take());
501+ out.push((i, row));
502+ }
503+ }
504+ }
505+ }
506+ out
507+}
508+
509+/// The character a stroke types into the actions card's search box, if it types
510+/// one. gpui reports a printable key as itself and the space bar by name
511+/// (platform.rs:866), and everything else -- the arrows, the function keys --
512+/// is a word this must not spell into the box letter by letter.
513+fn typed(key: &str) -> Option<char> {
514+ match key {
515+ "space" => Some(' '),
516+ _ => key
517+ .chars()
518+ .next()
519+ .filter(|c| c.is_ascii_graphic() && key.chars().count() == 1),
520+ }
521+}
522+
464 /// The project resolutions [`Player::cycle_resolution`] offers, largest first.523 /// The project resolutions [`Player::cycle_resolution`] offers, largest first.
465 /// A short list of the sizes people name; the media's own is cycled in beside524 /// A short list of the sizes people name; the media's own is cycled in beside
466 /// them, which is what makes the trip round come back to where it started.525 /// them, which is what makes the trip round come back to where it started.
@@ -883,6 +942,16 @@ struct Player {
883 /// pointer: a stroke or a click meant for a row must not also cut the942 /// pointer: a stroke or a click meant for a row must not also cut the
884 /// timeline.943 /// timeline.
885 keys_open: bool,944 keys_open: bool,
945+ /// What has been typed into the card's search box, which is the card's own
946+ /// input exactly as the export card's digits are (nothing in it takes
947+ /// focus, so the root's key handler is the field). Emptied every time the
948+ /// card opens: a search is a look at the list, not a setting.
949+ keys_search: String,
950+ /// Where that list is scrolled to. Held here rather than left to the
951+ /// wheel alone: forty actions are four times what a 360 px window shows,
952+ /// and the rows past the fold have to be reachable from the keyboard that
953+ /// is already typing in the search box.
954+ keys_scroll: ScrollHandle,
886 /// The export options card is up: what the export action opens now, so955 /// The export options card is up: what the export action opens now, so
887 /// nothing is written until the card's own button says so. One card at a956 /// nothing is written until the card's own button says so. One card at a
888 /// time -- opening either closes the other, since both are the whole window957 /// time -- opening either closes the other, since both are the whole window
@@ -1196,6 +1265,7 @@ impl Player {
1196 // Nothing to cancel while nothing is exporting; the export guard in1265 // Nothing to cancel while nothing is exporting; the export guard in
1197 // the key handler is what answers this one while there is.1266 // the key handler is what answers this one while there is.
1198 ActionId::CancelExport => {}1267 ActionId::CancelExport => {}
1268+ ActionId::ShowActions => self.show_actions(cx),
1199 }1269 }
1200 }1270 }
1201 1271
@@ -1212,6 +1282,37 @@ impl Player {
1212 cx.notify();1282 cx.notify();
1213 }1283 }
1214 1284
1285+ /// The actions card, from its key, from the panel button, or from its own
1286+ /// row: open, with an empty search box -- a card that opens showing the
1287+ /// last search would hide most of the list for a reason nobody remembers.
1288+ fn show_actions(&mut self, cx: &mut Context<Self>) {
1289+ self.keys_open = true;
1290+ self.keys_search.clear();
1291+ self.scroll_keys(None);
1292+ self.rebinding = None;
1293+ // One card at a time, the rule the other cards follow.
1294+ self.export_open = false;
1295+ cx.notify();
1296+ }
1297+
1298+ /// Moves the actions card's row list by `by` pixels, or puts it back at the
1299+ /// top (`None`). Back to the top after every keystroke that changes the
1300+ /// search: a filtered list is shorter than the offset a scrolled one left
1301+ /// behind, and a card showing the empty space past its last row reads as a
1302+ /// search that found nothing.
1303+ ///
1304+ /// Clamped to what there is to scroll, so the list cannot be pushed off
1305+ /// either end -- `max_offset` is what the last paint measured, which is the
1306+ /// only place that number exists.
1307+ fn scroll_keys(&self, by: Option<f32>) {
1308+ let at = match by {
1309+ Some(by) => (f32::from(self.keys_scroll.offset().y) + by)
1310+ .clamp(-f32::from(self.keys_scroll.max_offset().height), 0.),
1311+ None => 0.,
1312+ };
1313+ self.keys_scroll.set_offset(point(px(0.), px(at)));
1314+ }
1315+
1215 /// Whether the editor can be asked for `action` right now, and why not when1316 /// Whether the editor can be asked for `action` right now, and why not when
1216 /// it cannot. `on` is the clip the question is about -- the one a clip menu1317 /// it cannot. `on` is the clip the question is about -- the one a clip menu
1217 /// was opened on -- and `None` asks about the marked clip instead, which is1318 /// was opened on -- and `None` asks about the marked clip instead, which is
@@ -3797,14 +3898,37 @@ impl Render for Player {
3797 cx.notify();3898 cx.notify();
3798 return;3899 return;
3799 }3900 }
3800- // The overlay owns the keyboard while it is up: a stroke aimed3901+ // The overlay owns the keyboard while it is up -- but it types
3801- // at a row must not also cut the timeline, and the way out of it3902+ // now: a printable stroke is the search box's, which is why
3802- // is the same key that gets out of a capture.3903+ // nothing here reaches the keymap. A waiting row is answered
3904+ // above and still wins, so a rebind onto "v" binds the key
3905+ // rather than typing it.
3803 if this.keys_open {3906 if this.keys_open {
3804 if key == ESCAPE {3907 if key == ESCAPE {
3805- this.keys_open = false;3908+ // Two steps out, the way a search box anywhere gets
3806- cx.notify();3909+ // out: the filter first -- the whole list back --
3910+ // and the card only once there is no search to clear.
3911+ if this.keys_search.is_empty() {
3912+ this.keys_open = false;
3913+ } else {
3914+ this.keys_search.clear();
3915+ this.scroll_keys(None);
3916+ }
3917+ // The rows past the fold, without a wheel: forty actions
3918+ // are four times what the viewport shows, and the hand
3919+ // typing in the search box is already on the keyboard.
3920+ } else if key == "up" {
3921+ this.scroll_keys(Some(KEYS_ROW_H));
3922+ } else if key == "down" {
3923+ this.scroll_keys(Some(-KEYS_ROW_H));
3924+ } else if key == "backspace" {
3925+ this.keys_search.pop();
3926+ this.scroll_keys(None);
3927+ } else if let Some(c) = typed(key) {
3928+ this.keys_search.push(c);
3929+ this.scroll_keys(None);
3807 }3930 }
3931+ cx.notify();
3808 return;3932 return;
3809 }3933 }
3810 // The export card owns it the same way, and for the same3934 // The export card owns it the same way, and for the same
@@ -4898,23 +5022,27 @@ impl Player {
4898 live,5022 live,
4899 cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)),5023 cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)),
4900 ))5024 ))
4901- // No shortcut of its own -- and closed while an export runs,5025+ // Closed while an export runs, which is what keeps a waiting
4902- // which is what keeps a waiting row from swallowing the5026+ // row from swallowing the escape the progress line promises
4903- // escape the progress line promises cancels the export.5027+ // cancels the export.
4904 .child(control(5028 .child(control(
4905 "keys",5029 "keys",
4906 None,5030 None,
4907 "Actions",5031 "Actions",
4908 // The pointer's way to every action there is, including5032 // The pointer's way to every action there is, including
4909 // the ones no button here has room for.5033 // the ones no button here has room for.
4910- "do any action, or change the key that does it".to_string(),5034+ format!(
5035+ "{} — do any action, or change the key that does it",
5036+ key(ActionId::ShowActions)
5037+ ),
4911 !exporting,5038 !exporting,
4912- cx.listener(|this, _: &ClickEvent, _, cx| {5039+ cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open {
4913- this.keys_open = !this.keys_open;5040+ true => {
4914- this.rebinding = None;5041+ this.keys_open = false;
4915- // One card at a time, both ways round.5042+ this.rebinding = None;
4916- this.export_open = false;5043+ cx.notify();
4917- cx.notify();5044+ }
5045+ false => this.show_actions(cx),
4918 }),5046 }),
4919 )),5047 )),
4920 )5048 )
@@ -5148,7 +5276,26 @@ impl Player {
5148 .px(px(6.))5276 .px(px(6.))
5149 .rounded(px(3.))5277 .rounded(px(3.))
5150 };5278 };
5151- for (i, key_row) in keys_rows().into_iter().enumerate() {5279+ let found = keys_filter(&self.keys_search, &self.keymap);
5280+ // What the search box says: the typed text, and how much of the list is
5281+ // left under it -- a filter that found nothing has to say so, or the
5282+ // card reads as a list that lost its rows.
5283+ let search = if self.keys_search.is_empty() {
5284+ "search: type to filter · ↑ ↓ scroll the list".to_string()
5285+ } else {
5286+ let rows = found
5287+ .iter()
5288+ .filter(|(_, r)| !matches!(r, KeyRow::Head(_)))
5289+ .count();
5290+ match rows {
5291+ 0 => format!(
5292+ "search: {} — nothing matches · {out} clears",
5293+ self.keys_search
5294+ ),
5295+ n => format!("search: {} — {n} shown · {out} clears", self.keys_search),
5296+ }
5297+ };
5298+ for (i, key_row) in found {
5152 rows.push(match key_row {5299 rows.push(match key_row {
5153 KeyRow::Head(category) => div()5300 KeyRow::Head(category) => div()
5154 .flex_none()5301 .flex_none()
@@ -5286,6 +5433,19 @@ impl Player {
5286 }),5433 }),
5287 ),5434 ),
5288 )5435 )
5436+ // The search box: no focus and no text field -- the
5437+ // card's key handler is the field, exactly as the
5438+ // export card's digits are typed into it. Its own line
5439+ // above the list, so the rows below it are always the
5440+ // answer to what it says.
5441+ .child(
5442+ div()
5443+ .flex_none()
5444+ .px(px(6.))
5445+ .text_size(px(11.))
5446+ .text_color(rgb(INK_DIM))
5447+ .child(search),
5448+ )
5289 // Capped and scrolling rather than as tall as the action5449 // Capped and scrolling rather than as tall as the action
5290 // list happens to be: the list grows with the editor,5450 // list happens to be: the list grows with the editor,
5291 // the smallest window does not.5451 // the smallest window does not.
@@ -5297,6 +5457,10 @@ impl Player {
5297 .gap(px(2.))5457 .gap(px(2.))
5298 .max_h(px(KEYS_ROWS_H))5458 .max_h(px(KEYS_ROWS_H))
5299 .overflow_y_scroll()5459 .overflow_y_scroll()
5460+ // The wheel's offset and the arrow keys' are
5461+ // the same one, so the two cannot disagree
5462+ // about where the list is.
5463+ .track_scroll(&self.keys_scroll)
5300 .children(rows),5464 .children(rows),
5301 ),5465 ),
5302 ),5466 ),
@@ -8009,6 +8173,17 @@ struct Ctx {
8009 /// disagree about what an action needs -- exactly the reason [`Player::act`] is8173 /// disagree about what an action needs -- exactly the reason [`Player::act`] is
8010 /// one table too.8174 /// one table too.
8011 fn enable(action: ActionId, ctx: Ctx) -> Enable {8175 fn enable(action: ActionId, ctx: Ctx) -> Enable {
8176+ // The one action that is about the editor rather than about the timeline:
8177+ // the list of what everything does, and where a key is changed. An empty
8178+ // window has no clips and still has keys -- so this answers ahead of the
8179+ // timeline question, and only an export shuts it (a waiting row would
8180+ // swallow the escape the progress line promises cancels the export).
8181+ if action == ActionId::ShowActions {
8182+ return match ctx.exporting {
8183+ true => Enable::No("an export is running"),
8184+ false => Enable::Yes,
8185+ };
8186+ }
8012 if !ctx.timeline {8187 if !ctx.timeline {
8013 return Enable::No("no timeline open");8188 return Enable::No("no timeline open");
8014 }8189 }
@@ -9968,11 +10143,11 @@ mod tests {
9968 enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y,10143 enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y,
9969 estimated_mb, export_path, export_settings, format_key,10144 estimated_mb, export_path, export_settings, format_key,
9970 format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram,10145 format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram,
9971- inserted_band, is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at,10146+ inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h,
9972- next_container,10147+ marked, menu_at, next_container, normalise, nothing_to_play, panel_h, project_path,
9973- normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due,10148+ push_digit, retarget, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped,
9974- show_label, silence_rate, snap_cue, snap_marks, snapped, source_tint, span_partner,10149+ source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport,
9975- speed_at, summary_head, summary_tail, timecode, transport, unseen_paths, unseen_sources,10150+ typed, unseen_paths, unseen_sources,
9976 whole_take, window_title,10151 whole_take, window_title,
9977 };10152 };
9978 use super::{10153 use super::{
@@ -11787,19 +11962,106 @@ mod tests {
11787 assert!(KEYS_ROW_H >= HIT_MIN);11962 assert!(KEYS_ROW_H >= HIT_MIN);
11788 }11963 }
11789 11964
11965+ /// The search box: what a typed word leaves standing. Forty actions is more
11966+ /// than a 360 px window shows at once, so this is the card's answer to
11967+ /// "where is the one I want" -- and a heading with nothing under it would
11968+ /// be worse than no filter at all.
11969+ #[test]
11970+ fn a_search_leaves_the_rows_it_names_under_their_own_headings() {
11971+ use keymap::{ActionId, Category, Keymap};
11972+ let keymap = Keymap::defaults();
11973+ let acts = |found: &[(usize, KeyRow)]| -> Vec<ActionId> {
11974+ found
11975+ .iter()
11976+ .filter_map(|(_, r)| match r {
11977+ KeyRow::Act(a) => Some(*a),
11978+ _ => None,
11979+ })
11980+ .collect()
11981+ };
11982+ let heads = |found: &[(usize, KeyRow)]| -> Vec<Category> {
11983+ found
11984+ .iter()
11985+ .filter_map(|(_, r)| match r {
11986+ KeyRow::Head(c) => Some(*c),
11987+ _ => None,
11988+ })
11989+ .collect()
11990+ };
11991+ // Nothing typed hides nothing, and every row keeps its place in the
11992+ // unfiltered list: an element id must not move under a keystroke.
11993+ let all = keys_filter("", &keymap);
11994+ assert_eq!(all.len(), keys_rows().len());
11995+ assert!(all.iter().enumerate().all(|(n, (i, _))| n == *i));
11996+ // The word the user types is the word on the row. The mix card names
11997+ // the track volumes, so it is an honest hit; the fixed row about the
11998+ // volume keys is another, and each comes with its own heading only.
11999+ let vol = keys_filter("vol", &keymap);
12000+ assert_eq!(
12001+ acts(&vol),
12002+ vec![ActionId::VolumeUp, ActionId::VolumeDown, ActionId::Mix]
12003+ );
12004+ assert_eq!(heads(&vol), vec![Category::Audio, Category::View]);
12005+ // Case is not part of the question, in either direction.
12006+ assert_eq!(keys_filter("VoL", &keymap).len(), vol.len());
12007+ // The stroke column is searched too -- "what did ctrl do again" -- and
12008+ // an unbound-looking word finds nothing rather than everything.
12009+ let ctrl = keys_filter("ctrl+", &keymap);
12010+ assert!(acts(&ctrl).contains(&ActionId::Save));
12011+ assert!(!acts(&ctrl).contains(&ActionId::Play));
12012+ assert!(
12013+ keys_filter("qzx", &keymap).is_empty(),
12014+ "headings left behind"
12015+ );
12016+ // The card's own door is on the card, by name and by stroke.
12017+ assert_eq!(
12018+ acts(&keys_filter("f1", &keymap)),
12019+ vec![ActionId::ShowActions]
12020+ );
12021+ assert_eq!(
12022+ acts(&keys_filter("all actions", &keymap)),
12023+ vec![ActionId::ShowActions]
12024+ );
12025+ }
12026+
12027+ /// What a keystroke means to that box: a letter is a letter, and a word
12028+ /// gpui reports for a key that prints nothing is not typed letter by
12029+ /// letter into the search.
12030+ #[test]
12031+ fn only_a_printable_stroke_types_into_the_search() {
12032+ assert_eq!(typed("a"), Some('a'));
12033+ assert_eq!(typed("-"), Some('-'));
12034+ assert_eq!(typed("1"), Some('1'));
12035+ // The one printable key gpui reports by name.
12036+ assert_eq!(typed("space"), Some(' '));
12037+ for word in ["left", "escape", "f1", "backspace", "tab", "delete", "home"] {
12038+ assert_eq!(typed(word), None, "{word}");
12039+ }
12040+ }
12041+
11790 #[test]12042 #[test]
11791 fn the_keybindings_card_fits_the_smallest_window() {12043 fn the_keybindings_card_fits_the_smallest_window() {
11792 // The row list is capped and scrolls, so the card's height no longer12044 // The row list is capped and scrolls, so the card's height no longer
11793- // depends on how many actions there are: a title, a status line and the12045+ // depends on how many actions there are: a title, a status line, the
11794- // viewport, inside the 640x360 the rest of the layout is sized for.12046+ // search box and the viewport, inside the 640x360 the rest of the
12047+ // layout is sized for.
11795 let title = 17.; // 13 px text on its own line12048 let title = 17.; // 13 px text on its own line
11796 let status = 28.; // 11 px text, two lines: a refusal wraps12049 let status = 28.; // 11 px text, two lines: a refusal wraps
11797- let gaps = 3. * 2.;12050+ let search = 15.; // 11 px text, one line: it never wraps
12051+ let gaps = 4. * 2.;
11798 let padding = 24.;12052 let padding = 24.;
11799 assert!(12053 assert!(
11800- title + status + KEYS_ROWS_H + gaps + padding <= 360.,12054+ title + status + search + KEYS_ROWS_H + gaps + padding <= 360.,
11801 "card too tall"12055 "card too tall"
11802 );12056 );
12057+ // ...and the list is the only part that grows with the editor, so the
12058+ // rows past the fold are reached by scrolling that viewport (and, with
12059+ // forty of them, by the search box above it) rather than by a card
12060+ // taller than the window.
12061+ assert!(
12062+ keys_rows().len() as f32 * KEYS_ROW_H > KEYS_ROWS_H,
12063+ "the list outgrew the viewport long ago; the cap must still scroll"
12064+ );
11803 // The cap is only honest if it is the taller list that scrolls, not the12065 // The cap is only honest if it is the taller list that scrolls, not the
11804 // card that grows: every action must be reachable by scrolling, and12066 // card that grows: every action must be reachable by scrolling, and
11805 // enough of them visible that the list reads as a list.12067 // enough of them visible that the list reads as a list.
@@ -13515,6 +13777,8 @@ fn main() {
13515 project_path: project.clone(),13777 project_path: project.clone(),
13516 keymap: keymap.clone(),13778 keymap: keymap.clone(),
13517 keys_open: false,13779 keys_open: false,
13780+ keys_search: String::new(),
13781+ keys_scroll: ScrollHandle::new(),
13518 export_open: false,13782 export_open: false,
13519 export_grouped: true,13783 export_grouped: true,
13520 export_refusals_inline: false,13784 export_refusals_inline: false,