| 1 | use gpui_kit::*; |
| 2 | |
| 3 | use super::actions::{ |
| 4 | COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, InsertTableLine, NewChat, OpenSwitcher, |
| 5 | PastePlainText, RemoveTableLine, ReplyToHovered, ScheduleSend, ToggleBold, ToggleCallMute, |
| 6 | ToggleCode, ToggleFormatBar, ToggleItalic, ToggleStrike, ToggleSubscript, ToggleSuperscript, |
| 7 | ToggleUnderline, |
| 8 | }; |
| 9 | |
| 10 | const TEXT_FIELD_CONTEXT: &str = "Input"; |
| 11 | const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer"; |
| 12 | const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input"; |
| 13 | const ALTERNATE_KEYS: &[(&str, &str)] = &[ |
| 14 | ("Zoom in on shared content", "alt-shift-+"), |
| 15 | ("Insert column or row", "ctrl-alt-+"), |
| 16 | ("Zoom in", "ctrl-+"), |
| 17 | ("Zoom in", "ctrl-shift-="), |
| 18 | ("Zoom in", "ctrl-shift-+"), |
| 19 | ("Zoom out", "ctrl-_"), |
| 20 | ("Zoom out", "ctrl-shift--"), |
| 21 | ]; |
| 22 | |
| 23 | actions!( |
| 24 | teams, |
| 25 | [ |
| 26 | OpenActivity, |
| 27 | OpenChatsTab, |
| 28 | OpenChannelsTab, |
| 29 | OpenSaved, |
| 30 | OpenCallsTab, |
| 31 | OpenAgents, |
| 32 | OpenChatFilter, |
| 33 | FindInChat, |
| 34 | FilterUnreadChats, |
| 35 | FilterNonMeetingChats, |
| 36 | FilterMeetingChats, |
| 37 | FilterMutedChats, |
| 38 | ClearChatFilters, |
| 39 | PreviousConversation, |
| 40 | NextConversation, |
| 41 | JumpToLastReadOrNewest, |
| 42 | AcceptCall, |
| 43 | DeclineCall, |
| 44 | JoinMeetingFromToast, |
| 45 | HangUpCall, |
| 46 | ToggleCallCamera, |
| 47 | ToggleCallShare, |
| 48 | ToggleCallHand, |
| 49 | OpenLobbyList, |
| 50 | StartAudioCall, |
| 51 | StartVideoCall, |
| 52 | ToggleCallFullscreen, |
| 53 | PushToTalk, |
| 54 | ZoomShareIn, |
| 55 | ZoomShareOut, |
| 56 | ZoomShareReset, |
| 57 | ShowShortcuts, |
| 58 | OpenSettings, |
| 59 | ZoomIn, |
| 60 | ZoomOut, |
| 61 | ZoomReset |
| 62 | ] |
| 63 | ); |
| 64 | |
| 65 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 66 | pub enum Group { |
| 67 | General, |
| 68 | Navigation, |
| 69 | Composer, |
| 70 | Calls, |
| 71 | } |
| 72 | |
| 73 | impl Group { |
| 74 | pub const ALL: [Group; 4] = [ |
| 75 | Group::General, |
| 76 | Group::Navigation, |
| 77 | Group::Composer, |
| 78 | Group::Calls, |
| 79 | ]; |
| 80 | |
| 81 | pub fn title(self) -> &'static str { |
| 82 | match self { |
| 83 | Group::General => "General", |
| 84 | Group::Navigation => "Navigation", |
| 85 | Group::Composer => "Messages and composer", |
| 86 | Group::Calls => "Calls", |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 92 | pub enum Scope { |
| 93 | Global, |
| 94 | OutsideComposer, |
| 95 | GlobalOverTextFields, |
| 96 | OutsideTextFields, |
| 97 | Composer, |
| 98 | } |
| 99 | |
| 100 | pub struct Shortcut { |
| 101 | pub group: Group, |
| 102 | pub label: &'static str, |
| 103 | pub keys: &'static str, |
| 104 | pub mac_keys: Option<&'static str>, |
| 105 | pub scope: Scope, |
| 106 | bind: fn(&str, Option<&str>) -> KeyBinding, |
| 107 | } |
| 108 | |
| 109 | macro_rules! shortcut { |
| 110 | ($group:ident, $scope:ident, $label:expr, $keys:expr, $mac_keys:expr, $action:expr) => { |
| 111 | Shortcut { |
| 112 | group: Group::$group, |
| 113 | label: $label, |
| 114 | keys: $keys, |
| 115 | mac_keys: $mac_keys, |
| 116 | scope: Scope::$scope, |
| 117 | bind: |keys, context| KeyBinding::new(keys, $action, context), |
| 118 | } |
| 119 | }; |
| 120 | } |
| 121 | |
| 122 | #[rustfmt::skip] |
| 123 | pub const SHORTCUTS: &[Shortcut] = &[ |
| 124 | shortcut!(General, OutsideComposer, "Search and switch chats", "ctrl-k", Some("cmd-k"), OpenSwitcher), |
| 125 | shortcut!(General, Global, "New chat", "ctrl-n", Some("cmd-n"), NewChat), |
| 126 | shortcut!(General, GlobalOverTextFields, "Keyboard shortcuts", "ctrl-.", Some("cmd-."), ShowShortcuts), |
| 127 | shortcut!(General, GlobalOverTextFields, "Settings", "ctrl-,", Some("cmd-,"), OpenSettings), |
| 128 | shortcut!(General, OutsideComposer, "Zoom in", "ctrl-=", Some("cmd-="), ZoomIn), |
| 129 | shortcut!(General, GlobalOverTextFields, "Zoom out", "ctrl--", Some("cmd--"), ZoomOut), |
| 130 | shortcut!(General, GlobalOverTextFields, "Reset zoom level", "ctrl-0", Some("cmd-0"), ZoomReset), |
| 131 | shortcut!(Navigation, GlobalOverTextFields, "Open Activity", "ctrl-1", Some("cmd-1"), OpenActivity), |
| 132 | shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab), |
| 133 | shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab), |
| 134 | shortcut!(Navigation, GlobalOverTextFields, "Open Saved", "ctrl-4", Some("cmd-4"), OpenSaved), |
| 135 | shortcut!(Navigation, GlobalOverTextFields, "Show Calls", "ctrl-5", Some("cmd-5"), OpenCallsTab), |
| 136 | shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents), |
| 137 | shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation), |
| 138 | shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation), |
| 139 | shortcut!(Navigation, GlobalOverTextFields, "Open filter", "ctrl-shift-f", Some("cmd-shift-f"), OpenChatFilter), |
| 140 | shortcut!(Navigation, OutsideTextFields, "Filter chat list by unread chats only", "ctrl-alt-u", None, FilterUnreadChats), |
| 141 | shortcut!(Navigation, OutsideTextFields, "Filter chat list by chats only", "ctrl-alt-c", None, FilterNonMeetingChats), |
| 142 | shortcut!(Navigation, OutsideTextFields, "Filter chat list by meeting chats only", "ctrl-alt-b", None, FilterMeetingChats), |
| 143 | shortcut!(Navigation, OutsideTextFields, "Filter chat list by muted chats only", "ctrl-alt-q", None, FilterMutedChats), |
| 144 | shortcut!(Navigation, OutsideTextFields, "Remove all filters in the chat list", "ctrl-alt-z", None, ClearChatFilters), |
| 145 | shortcut!(Composer, GlobalOverTextFields, "Find in chat", "ctrl-f", Some("cmd-f"), FindInChat), |
| 146 | shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered), |
| 147 | shortcut!(Composer, Global, "Jump to last read or newest message", "ctrl-j", Some("cmd-j"), JumpToLastReadOrNewest), |
| 148 | shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold), |
| 149 | shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic), |
| 150 | shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline), |
| 151 | shortcut!(Composer, Composer, "Format", "ctrl-shift-x", Some("cmd-shift-x"), ToggleFormatBar), |
| 152 | shortcut!(Composer, Composer, "Strikethrough", "ctrl-alt-x", None, ToggleStrike), |
| 153 | shortcut!(Composer, Composer, "Superscript", "ctrl-shift-=", None, ToggleSuperscript), |
| 154 | shortcut!(Composer, Composer, "Subscript", "ctrl-=", None, ToggleSubscript), |
| 155 | shortcut!(Composer, Composer, "Code", "ctrl-shift-c", None, ToggleCode), |
| 156 | shortcut!(Composer, Composer, "Insert link", "ctrl-k", Some("cmd-k"), EditLink), |
| 157 | shortcut!(Composer, Composer, "Paste as plain text", "ctrl-shift-v", Some("cmd-shift-v"), PastePlainText), |
| 158 | shortcut!(Composer, Composer, "Schedule send", "ctrl-shift-enter", None, ScheduleSend), |
| 159 | shortcut!(Composer, Composer, "Insert column or row", "ctrl-alt-=", None, InsertTableLine), |
| 160 | shortcut!(Composer, Composer, "Delete column, row, or table", "ctrl-alt--", None, RemoveTableLine), |
| 161 | shortcut!(Calls, GlobalOverTextFields, "Accept incoming call", "ctrl-shift-a", Some("cmd-shift-a"), AcceptCall), |
| 162 | shortcut!(Calls, GlobalOverTextFields, "Decline incoming call", "ctrl-shift-d", Some("cmd-shift-d"), DeclineCall), |
| 163 | shortcut!(Calls, GlobalOverTextFields, "Join the meeting from its reminder", "ctrl-shift-j", Some("cmd-shift-j"), JoinMeetingFromToast), |
| 164 | shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall), |
| 165 | shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute), |
| 166 | shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera), |
| 167 | shortcut!(Calls, GlobalOverTextFields, "Open the share menu or stop sharing", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare), |
| 168 | shortcut!(Calls, GlobalOverTextFields, "Raise or lower hand", "ctrl-shift-k", Some("cmd-shift-k"), ToggleCallHand), |
| 169 | shortcut!(Calls, GlobalOverTextFields, "Open the lobby list", "ctrl-shift-y", Some("cmd-shift-y"), OpenLobbyList), |
| 170 | shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall), |
| 171 | shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall), |
| 172 | shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen), |
| 173 | shortcut!(Calls, GlobalOverTextFields, "Zoom in on shared content", "alt-shift-=", None, ZoomShareIn), |
| 174 | shortcut!(Calls, GlobalOverTextFields, "Zoom out on shared content", "alt-shift--", None, ZoomShareOut), |
| 175 | shortcut!(Calls, GlobalOverTextFields, "Reset zoom on shared content", "alt-shift-0", None, ZoomShareReset), |
| 176 | shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk), |
| 177 | ]; |
| 178 | |
| 179 | impl Shortcut { |
| 180 | pub fn keys_for_platform(&self) -> &'static str { |
| 181 | match self.mac_keys { |
| 182 | Some(mac_keys) if cfg!(target_os = "macos") => mac_keys, |
| 183 | _ => self.keys, |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | pub fn display_keys(&self) -> String { |
| 188 | display_keys(self.keys_for_platform()) |
| 189 | } |
| 190 | |
| 191 | fn bindings(&self) -> Vec<KeyBinding> { |
| 192 | let contexts: &[Option<&str>] = match self.scope { |
| 193 | Scope::Global => &[None], |
| 194 | Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)], |
| 195 | Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)], |
| 196 | Scope::OutsideTextFields => &[Some(OUTSIDE_TEXT_FIELD_CONTEXT)], |
| 197 | Scope::Composer => &[Some(COMPOSER_CONTEXT)], |
| 198 | }; |
| 199 | let mut keys = vec![self.keys]; |
| 200 | keys.extend( |
| 201 | ALTERNATE_KEYS |
| 202 | .iter() |
| 203 | .filter(|(label, _)| *label == self.label) |
| 204 | .map(|(_, alternate)| *alternate), |
| 205 | ); |
| 206 | keys.extend(self.mac_keys.filter(|_| cfg!(target_os = "macos"))); |
| 207 | keys.iter() |
| 208 | .flat_map(|keys| contexts.iter().map(|context| (self.bind)(keys, *context))) |
| 209 | .collect() |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | pub fn keys_for_label(label: &str) -> Option<String> { |
| 214 | SHORTCUTS |
| 215 | .iter() |
| 216 | .find(|shortcut| shortcut.label == label) |
| 217 | .map(Shortcut::display_keys) |
| 218 | } |
| 219 | |
| 220 | pub fn display_keys(keys: &str) -> String { |
| 221 | let (modifiers, key) = match keys.strip_suffix("--") { |
| 222 | Some(modifiers) => (modifiers, "-"), |
| 223 | None => keys.rsplit_once('-').unwrap_or(("", keys)), |
| 224 | }; |
| 225 | modifiers |
| 226 | .split('-') |
| 227 | .filter(|part| !part.is_empty()) |
| 228 | .chain([key]) |
| 229 | .map(|part| match part { |
| 230 | "ctrl" => "Ctrl".to_owned(), |
| 231 | "cmd" => "Cmd".to_owned(), |
| 232 | "alt" => "Alt".to_owned(), |
| 233 | "shift" => "Shift".to_owned(), |
| 234 | "up" => "Up".to_owned(), |
| 235 | "down" => "Down".to_owned(), |
| 236 | "enter" => "Enter".to_owned(), |
| 237 | "space" => "Space".to_owned(), |
| 238 | "=" => "Plus".to_owned(), |
| 239 | "-" => "Minus".to_owned(), |
| 240 | other => other.to_uppercase(), |
| 241 | }) |
| 242 | .collect::<Vec<_>>() |
| 243 | .join("+") |
| 244 | } |
| 245 | |
| 246 | pub fn bind_scopes(cx: &mut App, scopes: &[Scope]) { |
| 247 | cx.bind_keys( |
| 248 | SHORTCUTS |
| 249 | .iter() |
| 250 | .filter(|shortcut| scopes.contains(&shortcut.scope)) |
| 251 | .flat_map(Shortcut::bindings), |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | pub fn shortcuts_in(group: Group) -> impl Iterator<Item = &'static Shortcut> { |
| 256 | SHORTCUTS |
| 257 | .iter() |
| 258 | .filter(move |shortcut| shortcut.group == group) |
| 259 | } |
| 260 | |
| 261 | #[cfg(test)] |
| 262 | mod tests { |
| 263 | use std::collections::HashSet; |
| 264 | |
| 265 | use gpui_kit::{KeyContext, Keystroke, TestAppContext}; |
| 266 | |
| 267 | use super::{Group, SHORTCUTS, Scope, Shortcut, display_keys, shortcuts_in}; |
| 268 | use crate::views::shell::bind_keys; |
| 269 | |
| 270 | fn bound_action(cx: &mut TestAppContext, keys: &str, contexts: &[&str]) -> Option<String> { |
| 271 | let stack: Vec<KeyContext> = contexts |
| 272 | .iter() |
| 273 | .map(|context| KeyContext::parse(context).unwrap()) |
| 274 | .collect(); |
| 275 | let keystroke = Keystroke::parse(keys).unwrap(); |
| 276 | cx.update(|cx| { |
| 277 | let keymap = cx.key_bindings(); |
| 278 | let (bindings, _) = keymap.borrow().bindings_for_input(&[keystroke], &stack); |
| 279 | bindings |
| 280 | .first() |
| 281 | .map(|binding| binding.action().name().to_owned()) |
| 282 | }) |
| 283 | } |
| 284 | |
| 285 | fn registered(cx: &mut TestAppContext) { |
| 286 | cx.update(gpui_kit::init); |
| 287 | cx.update(bind_keys); |
| 288 | } |
| 289 | |
| 290 | fn action_name(shortcut: &Shortcut) -> String { |
| 291 | shortcut.bindings()[0].action().name().to_owned() |
| 292 | } |
| 293 | |
| 294 | #[gpui_kit::test] |
| 295 | fn every_listed_shortcut_resolves_to_its_action(cx: &mut TestAppContext) { |
| 296 | registered(cx); |
| 297 | for shortcut in SHORTCUTS { |
| 298 | let contexts: &[&str] = match shortcut.scope { |
| 299 | Scope::Global | Scope::OutsideComposer => &["AppShell"], |
| 300 | Scope::GlobalOverTextFields | Scope::OutsideTextFields => &["AppShell"], |
| 301 | Scope::Composer => &["AppShell", "Composer"], |
| 302 | }; |
| 303 | assert_eq!( |
| 304 | bound_action(cx, shortcut.keys, contexts), |
| 305 | Some(action_name(shortcut)), |
| 306 | "{} ({})", |
| 307 | shortcut.label, |
| 308 | shortcut.keys |
| 309 | ); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | #[gpui_kit::test] |
| 314 | fn global_shortcuts_survive_typing_in_the_composer(cx: &mut TestAppContext) { |
| 315 | registered(cx); |
| 316 | for shortcut in SHORTCUTS |
| 317 | .iter() |
| 318 | .filter(|shortcut| shortcut.scope == Scope::GlobalOverTextFields) |
| 319 | { |
| 320 | assert_eq!( |
| 321 | bound_action(cx, shortcut.keys, &["AppShell", "Composer", "Input"]), |
| 322 | Some(action_name(shortcut)), |
| 323 | "{} ({})", |
| 324 | shortcut.label, |
| 325 | shortcut.keys |
| 326 | ); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | #[gpui_kit::test] |
| 331 | fn push_to_talk_is_not_bound_while_typing_in_a_text_field(cx: &mut TestAppContext) { |
| 332 | registered(cx); |
| 333 | assert!(bound_action(cx, "ctrl-space", &["AppShell"]).is_some()); |
| 334 | assert_eq!( |
| 335 | bound_action(cx, "ctrl-space", &["AppShell", "Composer", "Input"]), |
| 336 | None |
| 337 | ); |
| 338 | } |
| 339 | |
| 340 | #[gpui_kit::test] |
| 341 | fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) { |
| 342 | registered(cx); |
| 343 | let typing = ["AppShell", "Composer", "Input"]; |
| 344 | assert_eq!( |
| 345 | bound_action(cx, "ctrl-k", &typing), |
| 346 | Some(action_name( |
| 347 | SHORTCUTS |
| 348 | .iter() |
| 349 | .find(|shortcut| shortcut.label == "Insert link") |
| 350 | .unwrap() |
| 351 | )) |
| 352 | ); |
| 353 | assert_eq!( |
| 354 | bound_action(cx, "ctrl-k", &["AppShell"]), |
| 355 | Some(action_name( |
| 356 | SHORTCUTS |
| 357 | .iter() |
| 358 | .find(|shortcut| shortcut.label == "Search and switch chats") |
| 359 | .unwrap() |
| 360 | )) |
| 361 | ); |
| 362 | } |
| 363 | |
| 364 | #[test] |
| 365 | fn no_two_shortcuts_share_keys_in_the_same_scope() { |
| 366 | let mut seen = HashSet::new(); |
| 367 | for shortcut in SHORTCUTS { |
| 368 | let scope = matches!(shortcut.scope, Scope::Composer); |
| 369 | assert!(seen.insert((shortcut.keys, scope)), "{}", shortcut.keys); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | #[test] |
| 374 | fn every_group_lists_shortcuts_and_keys_read_like_teams() { |
| 375 | for group in Group::ALL { |
| 376 | assert!(shortcuts_in(group).next().is_some(), "{group:?}"); |
| 377 | } |
| 378 | assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A"); |
| 379 | assert_eq!(display_keys("alt-up"), "Alt+Up"); |
| 380 | assert_eq!(display_keys("ctrl-."), "Ctrl+."); |
| 381 | assert_eq!(display_keys("ctrl-space"), "Ctrl+Space"); |
| 382 | assert_eq!(display_keys("alt-shift-="), "Alt+Shift+Plus"); |
| 383 | assert_eq!(display_keys("alt-shift--"), "Alt+Shift+Minus"); |
| 384 | assert_eq!(display_keys("alt-shift-0"), "Alt+Shift+0"); |
| 385 | assert_eq!(display_keys("ctrl-alt--"), "Ctrl+Alt+Minus"); |
| 386 | } |
| 387 | |
| 388 | #[gpui_kit::test] |
| 389 | fn zoom_keys_match_teams_and_leave_the_composer_subscript_alone(cx: &mut TestAppContext) { |
| 390 | registered(cx); |
| 391 | let action_of = |label: &str| { |
| 392 | action_name( |
| 393 | SHORTCUTS |
| 394 | .iter() |
| 395 | .find(|shortcut| shortcut.label == label) |
| 396 | .unwrap(), |
| 397 | ) |
| 398 | }; |
| 399 | for (keys, label) in [ |
| 400 | ("ctrl-=", "Zoom in"), |
| 401 | ("ctrl-+", "Zoom in"), |
| 402 | ("ctrl-shift-=", "Zoom in"), |
| 403 | ("ctrl--", "Zoom out"), |
| 404 | ("ctrl-_", "Zoom out"), |
| 405 | ("ctrl-0", "Reset zoom level"), |
| 406 | ] { |
| 407 | assert_eq!( |
| 408 | bound_action(cx, keys, &["AppShell"]), |
| 409 | Some(action_of(label)), |
| 410 | "{keys}" |
| 411 | ); |
| 412 | } |
| 413 | let typing = ["AppShell", "Composer", "Input"]; |
| 414 | assert_eq!( |
| 415 | bound_action(cx, "ctrl-=", &typing), |
| 416 | Some(action_of("Subscript")) |
| 417 | ); |
| 418 | assert_eq!( |
| 419 | bound_action(cx, "ctrl--", &typing), |
| 420 | Some(action_of("Zoom out")) |
| 421 | ); |
| 422 | assert_eq!(display_keys("ctrl-="), "Ctrl+Plus"); |
| 423 | } |
| 424 | |
| 425 | #[gpui_kit::test] |
| 426 | fn composer_format_and_table_keys_match_teams(cx: &mut TestAppContext) { |
| 427 | registered(cx); |
| 428 | let typing = ["AppShell", "Composer", "Input"]; |
| 429 | let action_of = |label: &str| { |
| 430 | action_name( |
| 431 | SHORTCUTS |
| 432 | .iter() |
| 433 | .find(|shortcut| shortcut.label == label) |
| 434 | .unwrap(), |
| 435 | ) |
| 436 | }; |
| 437 | for (keys, label) in [ |
| 438 | ("ctrl-shift-x", "Format"), |
| 439 | ("ctrl-alt-x", "Strikethrough"), |
| 440 | ("ctrl-alt-=", "Insert column or row"), |
| 441 | ("ctrl-alt-+", "Insert column or row"), |
| 442 | ("ctrl-alt--", "Delete column, row, or table"), |
| 443 | ] { |
| 444 | assert_eq!( |
| 445 | bound_action(cx, keys, &typing), |
| 446 | Some(action_of(label)), |
| 447 | "{keys}" |
| 448 | ); |
| 449 | } |
| 450 | } |
| 451 | } |