BlueGit

ict rusty-teams

feat(keys): keyboard shortcuts like Teams and a shortcut overview

| Before | After |
|---|---|
| Only Ctrl+K, Ctrl+N, Alt+R, Ctrl+Shift+M | Ctrl+1 Activity, Ctrl+2 Chats, Ctrl+3 Channels, Ctrl+4 Saved; Alt+Up/Down previous/next chat in the visible list, also while typing |
| - | Calls: Ctrl+Shift+A accept, Ctrl+Shift+D decline, Ctrl+Shift+H hang up, Ctrl+Shift+O camera, Ctrl+Shift+E share screen |
| - | Ctrl+. opens a shortcut overview; one table feeds both the bindings and the overview |
| Ctrl+K in the composer opened the switcher | Ctrl+K in the composer opens the link editor (switcher when the draft is empty), elsewhere the switcher |

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-10 · 7 weeks ago

Hash
987a3babbee75abdefec68c7d0774f152980ca6b
Parent
4b75955b
12 files changed +818 −42
README.md +1 −0
@@ -56,6 +56,7 @@
56 56 - `:thumbsup:` and `:)` convert as you type, German aliases included
57 57 - Schedule send: right-click send or `Ctrl+Shift+Enter`
58 58 - Drafts and unsent messages survive a restart
59 - Keyboard like Teams: `Ctrl+1`..`4` panels and tabs, `Alt+Up` / `Alt+Down` next chat, call keys on `Ctrl+Shift+A/D/H/O/E/M`, `Ctrl+.` lists them all
59 60
60 61 **Calls**
61 62 - Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats
@@ -56,6 +56,7 @@
56- `:thumbsup:` and `:)` convert as you type, German aliases included
56- `:thumbsup:` and `:)` convert as you type, German aliases included
57- Schedule send: right-click send or `Ctrl+Shift+Enter`
57- Schedule send: right-click send or `Ctrl+Shift+Enter`
58- Drafts and unsent messages survive a restart
58- Drafts and unsent messages survive a restart
59- Keyboard like Teams: `Ctrl+1`..`4` panels and tabs, `Alt+Up` / `Alt+Down` next chat, call keys on `Ctrl+Shift+A/D/H/O/E/M`, `Ctrl+.` lists them all
59
60
60**Calls**
61**Calls**
61- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats
62- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats
ROADMAP.md +3 −4
@@ -2,7 +2,7 @@
2 2
3 3 Feature parity with the Microsoft Teams desktop client.
4 4
5 **Parity: 90 %** (77 done, 5 partial, 6 missing of 88). Partial counts half.
5 **Parity: 91 %** (78 done, 5 partial, 5 missing of 88). Partial counts half.
6 6
7 7 ## By area
8 8
@@ -15,7 +15,7 @@ Feature parity with the Microsoft Teams desktop client.
15 15 | [Message actions](#message-actions) | 100 % | 5 | 0 | 0 |
16 16 | [Channels](#channels) | 100 % | 7 | 0 | 0 |
17 17 | [Notifications](#notifications) | 88 % | 7 | 0 | 1 |
18 | [Search and navigation](#search-and-navigation) | 80 % | 4 | 0 | 1 |
18 | [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |
19 19 | [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
20 20 | [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
21 21 | [Calls and meetings](#calls-and-meetings) | 67 % | 2 | 4 | 0 |
@@ -25,7 +25,6 @@ Feature parity with the Microsoft Teams desktop client.
25 25 | # | Feature | Note |
26 26 |---|---|---|
27 27 | 1 | Sign in on Linux without Chrome on a debug port | |
28 | 2 | Keyboard: Ctrl+1..9, Alt+Up/Down | |
29 28
30 29 ## Sign-in and app
31 30
@@ -139,7 +138,7 @@ Feature parity with the Microsoft Teams desktop client.
139 138 | Full-text search over cached messages | Done | |
140 139 | Jump to a message from search | Done | |
141 140 | Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
142 | Keyboard: Ctrl+1..9, Alt+Up/Down | Missing | |
141 | Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share screen, M mute; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
143 142
144 143 ## Presence and people
145 144
@@ -2,7 +2,7 @@
2
2
3Feature parity with the Microsoft Teams desktop client.
3Feature parity with the Microsoft Teams desktop client.
4
4
5**Parity: 90 %** (77 done, 5 partial, 6 missing of 88). Partial counts half.
5**Parity: 91 %** (78 done, 5 partial, 5 missing of 88). Partial counts half.
6
6
7## By area
7## By area
8
8
@@ -15,7 +15,7 @@ Feature parity with the Microsoft Teams desktop client.
15| [Message actions](#message-actions) | 100 % | 5 | 0 | 0 |
15| [Message actions](#message-actions) | 100 % | 5 | 0 | 0 |
16| [Channels](#channels) | 100 % | 7 | 0 | 0 |
16| [Channels](#channels) | 100 % | 7 | 0 | 0 |
17| [Notifications](#notifications) | 88 % | 7 | 0 | 1 |
17| [Notifications](#notifications) | 88 % | 7 | 0 | 1 |
18| [Search and navigation](#search-and-navigation) | 80 % | 4 | 0 | 1 |
18| [Search and navigation](#search-and-navigation) | 100 % | 5 | 0 | 0 |
19| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
19| [Presence and people](#presence-and-people) | 100 % | 4 | 0 | 0 |
20| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
20| [Look and settings](#look-and-settings) | 50 % | 2 | 0 | 2 |
21| [Calls and meetings](#calls-and-meetings) | 67 % | 2 | 4 | 0 |
21| [Calls and meetings](#calls-and-meetings) | 67 % | 2 | 4 | 0 |
@@ -25,7 +25,6 @@ Feature parity with the Microsoft Teams desktop client.
25| # | Feature | Note |
25| # | Feature | Note |
26|---|---|---|
26|---|---|---|
27| 1 | Sign in on Linux without Chrome on a debug port | |
27| 1 | Sign in on Linux without Chrome on a debug port | |
28| 2 | Keyboard: Ctrl+1..9, Alt+Up/Down | |
29
28
30## Sign-in and app
29## Sign-in and app
31
30
@@ -139,7 +138,7 @@ Feature parity with the Microsoft Teams desktop client.
139| Full-text search over cached messages | Done | |
138| Full-text search over cached messages | Done | |
140| Jump to a message from search | Done | |
139| Jump to a message from search | Done | |
141| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
140| Esc closes the open conversation or editor | Done | Back to the channel keeps the feed position |
142| Keyboard: Ctrl+1..9, Alt+Up/Down | Missing | |
141| Keyboard shortcuts like Teams | Done | Ctrl+1 Activity, 2 Chats, 3 Channels, 4 Saved; Alt+Up/Down previous and next chat or channel in the visible list, also while typing; calls Ctrl+Shift+A accept, D decline, H hang up, O camera, E share screen, M mute; Ctrl+. lists all shortcuts. Ctrl+5..9 not used |
143
142
144## Presence and people
143## Presence and people
145
144
crates/app/src/call/actions.rs +43 −0
@@ -262,6 +262,22 @@ impl AppState {
262 262 self.send_call_command(CallCommand::StartShare(source));
263 263 }
264 264
265 pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
266 let Some(call) = self.call.as_ref() else {
267 return;
268 };
269 if call.model.local_share.is_some() {
270 self.stop_call_share(cx);
271 return;
272 }
273 if !call.model.can_share() {
274 return;
275 }
276 if let Some(source) = call.model.screens().first().map(|source| (*source).clone()) {
277 self.start_call_share(source, cx);
278 }
279 }
280
265 281 pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
266 282 self.send_call_command(CallCommand::StopShare);
267 283 }
@@ -390,6 +406,18 @@ impl AppState {
390 406 }
391 407 }
392 408
409 pub fn accept_ringing_call(&mut self, cx: &mut Context<Self>) {
410 if let Some(ring_id) = self.rings.first_ringing_id() {
411 self.accept_ring(ring_id, cx);
412 }
413 }
414
415 pub fn decline_ringing_call(&mut self, cx: &mut Context<Self>) {
416 if let Some(ring_id) = self.rings.first_ringing_id() {
417 self.decline_ring(ring_id, cx);
418 }
419 }
420
393 421 pub fn accept_ring(&mut self, ring_id: u64, cx: &mut Context<Self>) {
394 422 let Some(entry) = self.rings.get(ring_id).cloned() else {
395 423 return;
@@ -592,6 +620,21 @@ mod tests {
592 620 app
593 621 }
594 622
623 #[gpui_kit::test]
624 fn declining_by_shortcut_only_acts_while_a_ring_shows(cx: &mut TestAppContext) {
625 let app = app_with_chats(cx);
626 cx.update(|cx| {
627 app.update(cx, |state, cx| {
628 state.decline_ringing_call(cx);
629 assert!(!state.rings.is_ringing());
630 state.demo_incoming_ring(cx);
631 assert!(state.rings.is_ringing());
632 state.decline_ringing_call(cx);
633 assert!(!state.rings.is_ringing());
634 })
635 });
636 }
637
595 638 #[gpui_kit::test]
596 639 fn picking_another_chat_moves_the_call_to_the_mini_window(cx: &mut TestAppContext) {
597 640 let app = app_with_call(cx);
@@ -262,6 +262,22 @@ impl AppState {
262 self.send_call_command(CallCommand::StartShare(source));
262 self.send_call_command(CallCommand::StartShare(source));
263 }
263 }
264
264
265 pub fn toggle_call_share(&mut self, cx: &mut Context<Self>) {
266 let Some(call) = self.call.as_ref() else {
267 return;
268 };
269 if call.model.local_share.is_some() {
270 self.stop_call_share(cx);
271 return;
272 }
273 if !call.model.can_share() {
274 return;
275 }
276 if let Some(source) = call.model.screens().first().map(|source| (*source).clone()) {
277 self.start_call_share(source, cx);
278 }
279 }
280
265 pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
281 pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) {
266 self.send_call_command(CallCommand::StopShare);
282 self.send_call_command(CallCommand::StopShare);
267 }
283 }
@@ -390,6 +406,18 @@ impl AppState {
390 }
406 }
391 }
407 }
392
408
409 pub fn accept_ringing_call(&mut self, cx: &mut Context<Self>) {
410 if let Some(ring_id) = self.rings.first_ringing_id() {
411 self.accept_ring(ring_id, cx);
412 }
413 }
414
415 pub fn decline_ringing_call(&mut self, cx: &mut Context<Self>) {
416 if let Some(ring_id) = self.rings.first_ringing_id() {
417 self.decline_ring(ring_id, cx);
418 }
419 }
420
393 pub fn accept_ring(&mut self, ring_id: u64, cx: &mut Context<Self>) {
421 pub fn accept_ring(&mut self, ring_id: u64, cx: &mut Context<Self>) {
394 let Some(entry) = self.rings.get(ring_id).cloned() else {
422 let Some(entry) = self.rings.get(ring_id).cloned() else {
395 return;
423 return;
@@ -592,6 +620,21 @@ mod tests {
592 app
620 app
593 }
621 }
594
622
623 #[gpui_kit::test]
624 fn declining_by_shortcut_only_acts_while_a_ring_shows(cx: &mut TestAppContext) {
625 let app = app_with_chats(cx);
626 cx.update(|cx| {
627 app.update(cx, |state, cx| {
628 state.decline_ringing_call(cx);
629 assert!(!state.rings.is_ringing());
630 state.demo_incoming_ring(cx);
631 assert!(state.rings.is_ringing());
632 state.decline_ringing_call(cx);
633 assert!(!state.rings.is_ringing());
634 })
635 });
636 }
637
595 #[gpui_kit::test]
638 #[gpui_kit::test]
596 fn picking_another_chat_moves_the_call_to_the_mini_window(cx: &mut TestAppContext) {
639 fn picking_another_chat_moves_the_call_to_the_mini_window(cx: &mut TestAppContext) {
597 let app = app_with_call(cx);
640 let app = app_with_call(cx);
crates/app/src/call/ring.rs +4 −0
@@ -73,6 +73,10 @@ impl Rings {
73 73 self.entries.iter().filter(|entry| entry.state.is_ringing())
74 74 }
75 75
76 pub fn first_ringing_id(&self) -> Option<u64> {
77 self.ringing().next().map(|entry| entry.ring.ring_id)
78 }
79
76 80 pub fn is_ringing(&self) -> bool {
77 81 self.ringing().next().is_some()
78 82 }
@@ -73,6 +73,10 @@ impl Rings {
73 self.entries.iter().filter(|entry| entry.state.is_ringing())
73 self.entries.iter().filter(|entry| entry.state.is_ringing())
74 }
74 }
75
75
76 pub fn first_ringing_id(&self) -> Option<u64> {
77 self.ringing().next().map(|entry| entry.ring.ring_id)
78 }
79
76 pub fn is_ringing(&self) -> bool {
80 pub fn is_ringing(&self) -> bool {
77 self.ringing().next().is_some()
81 self.ringing().next().is_some()
78 }
82 }
crates/app/src/chat_actions.rs +16 −2
@@ -6,7 +6,9 @@ use store::{ChannelNotifications, ChatRecord};
6 6
7 7 use crate::app_state::{AppState, Selection, chat_title};
8 8 use crate::notice::{NoticeAction, short_error, truncated};
9 use crate::sidebar_model::{SectionInput, build_sections, next_chat_id};
9 use crate::sidebar_model::{
10 Section, SectionInput, Step, build_sections, next_chat_id, step_id, visible_chat_ids,
11 };
10 12
11 13 pub const TITLE_LIMIT: usize = 40;
12 14
@@ -255,6 +257,18 @@ impl AppState {
255 257 }
256 258
257 259 fn next_chat_after(&self, chat_id: &str) -> Option<String> {
260 next_chat_id(&self.chat_sections(), chat_id)
261 }
262
263 pub fn adjacent_chat_id(&self, step: Step) -> Option<String> {
264 let current = match &self.selection {
265 Some(Selection::Chat(chat_id)) => Some(chat_id.as_str()),
266 _ => None,
267 };
268 step_id(&visible_chat_ids(&self.chat_sections()), current, step)
269 }
270
271 fn chat_sections(&self) -> Vec<Section> {
258 272 let input = SectionInput {
259 273 chats: &self.sidebar.chats,
260 274 directory: &self.directory,
@@ -264,7 +278,7 @@ impl AppState {
264 278 now: Utc::now(),
265 279 offset: Local::now().offset().fix(),
266 280 };
267 next_chat_id(&build_sections(&input), chat_id)
281 build_sections(&input)
268 282 }
269 283
270 284 pub(crate) fn run_chat_action(
@@ -6,7 +6,9 @@ use store::{ChannelNotifications, ChatRecord};
6
6
7use crate::app_state::{AppState, Selection, chat_title};
7use crate::app_state::{AppState, Selection, chat_title};
8use crate::notice::{NoticeAction, short_error, truncated};
8use crate::notice::{NoticeAction, short_error, truncated};
9use crate::sidebar_model::{SectionInput, build_sections, next_chat_id};
9use crate::sidebar_model::{
10 Section, SectionInput, Step, build_sections, next_chat_id, step_id, visible_chat_ids,
11};
10
12
11pub const TITLE_LIMIT: usize = 40;
13pub const TITLE_LIMIT: usize = 40;
12
14
@@ -255,6 +257,18 @@ impl AppState {
255 }
257 }
256
258
257 fn next_chat_after(&self, chat_id: &str) -> Option<String> {
259 fn next_chat_after(&self, chat_id: &str) -> Option<String> {
260 next_chat_id(&self.chat_sections(), chat_id)
261 }
262
263 pub fn adjacent_chat_id(&self, step: Step) -> Option<String> {
264 let current = match &self.selection {
265 Some(Selection::Chat(chat_id)) => Some(chat_id.as_str()),
266 _ => None,
267 };
268 step_id(&visible_chat_ids(&self.chat_sections()), current, step)
269 }
270
271 fn chat_sections(&self) -> Vec<Section> {
258 let input = SectionInput {
272 let input = SectionInput {
259 chats: &self.sidebar.chats,
273 chats: &self.sidebar.chats,
260 directory: &self.directory,
274 directory: &self.directory,
@@ -264,7 +278,7 @@ impl AppState {
264 now: Utc::now(),
278 now: Utc::now(),
265 offset: Local::now().offset().fix(),
279 offset: Local::now().offset().fix(),
266 };
280 };
267 next_chat_id(&build_sections(&input), chat_id)
281 build_sections(&input)
268 }
282 }
269
283
270 pub(crate) fn run_chat_action(
284 pub(crate) fn run_chat_action(
crates/app/src/sidebar_model.rs +184 −4
@@ -1,7 +1,7 @@
1 1 use std::collections::{HashMap, HashSet};
2 2
3 3 use chrono::{DateTime, FixedOffset, Utc};
4 use store::{ChatRecord, Sidebar};
4 use store::{ChannelRecord, ChatRecord, Sidebar, SidebarTeam};
5 5 use teams_core::ChatSection;
6 6
7 7 use crate::app_state::chat_title;
@@ -326,12 +326,16 @@ pub fn build_sections(input: &SectionInput<'_>) -> Vec<Section> {
326 326 sections
327 327 }
328 328
329 pub fn next_chat_id(sections: &[Section], removed_id: &str) -> Option<String> {
330 let visible: Vec<&str> = sections
329 pub fn visible_chat_ids(sections: &[Section]) -> Vec<&str> {
330 sections
331 331 .iter()
332 332 .filter(|section| !section.collapsed)
333 333 .flat_map(|section| section.items.iter().map(|item| item.id.as_str()))
334 .collect();
334 .collect()
335 }
336
337 pub fn next_chat_id(sections: &[Section], removed_id: &str) -> Option<String> {
338 let visible = visible_chat_ids(sections);
335 339 let position = visible.iter().position(|id| *id == removed_id)?;
336 340 visible
337 341 .get(position + 1)
@@ -343,6 +347,89 @@ pub fn next_chat_id(sections: &[Section], removed_id: &str) -> Option<String> {
343 347 .map(|id| (*id).to_owned())
344 348 }
345 349
350 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
351 pub enum Step {
352 Previous,
353 Next,
354 }
355
356 pub fn step_id(ids: &[&str], current: Option<&str>, step: Step) -> Option<String> {
357 let position = current.and_then(|current| ids.iter().position(|id| *id == current));
358 let target = match (position, step) {
359 (Some(position), Step::Next) => position + 1,
360 (Some(position), Step::Previous) => position.checked_sub(1)?,
361 (None, Step::Next) => 0,
362 (None, Step::Previous) => ids.len().checked_sub(1)?,
363 };
364 ids.get(target).map(|id| (*id).to_owned())
365 }
366
367 pub struct ChannelOrderInput<'a> {
368 pub teams: &'a [SidebarTeam],
369 pub pinned_ids: &'a [String],
370 pub collapsed_teams: &'a HashSet<String>,
371 pub revealed_channel_teams: &'a HashSet<String>,
372 pub hidden_teams_open: bool,
373 pub selected_channel: Option<&'a str>,
374 }
375
376 pub fn visible_channel_ids<'a>(input: &ChannelOrderInput<'a>) -> Vec<&'a str> {
377 let mut ids: Vec<&str> = Vec::new();
378 let mut push = |id: &'a str| {
379 if !ids.contains(&id) {
380 ids.push(id);
381 }
382 };
383 for pinned_id in input.pinned_ids {
384 let known = input
385 .teams
386 .iter()
387 .flat_map(|entry| entry.channels.iter())
388 .find(|channel| &channel.id == pinned_id);
389 if let Some(channel) = known {
390 push(&channel.id);
391 }
392 }
393 let holds_selection = |entry: &SidebarTeam| {
394 entry
395 .channels
396 .iter()
397 .any(|channel| Some(channel.id.as_str()) == input.selected_channel)
398 };
399 let hidden_teams_shown = input.hidden_teams_open
400 || input
401 .teams
402 .iter()
403 .any(|entry| entry.hidden && holds_selection(entry));
404 let teams = input
405 .teams
406 .iter()
407 .filter(|entry| !entry.hidden)
408 .chain(
409 input
410 .teams
411 .iter()
412 .filter(|entry| entry.hidden && hidden_teams_shown),
413 );
414 for entry in teams {
415 if input.collapsed_teams.contains(&entry.team.id) {
416 continue;
417 }
418 let is_hidden = |channel: &ChannelRecord| entry.hidden_channel_ids.contains(&channel.id);
419 let is_selected = |channel: &ChannelRecord| Some(channel.id.as_str()) == input.selected_channel;
420 let revealed = input.revealed_channel_teams.contains(&entry.team.id);
421 for channel in entry.channels.iter().filter(|channel| !is_hidden(channel) || is_selected(channel)) {
422 push(&channel.id);
423 }
424 if revealed {
425 for channel in entry.channels.iter().filter(|channel| is_hidden(channel) && !is_selected(channel)) {
426 push(&channel.id);
427 }
428 }
429 }
430 ids
431 }
432
346 433 fn section(
347 434 id: String,
348 435 name: String,
@@ -517,6 +604,99 @@ mod tests {
517 604 assert_eq!(next_chat_id(&sections, "a"), None);
518 605 }
519 606
607 #[test]
608 fn stepping_follows_the_visible_order_without_wrapping() {
609 let ids = ["a", "b", "c"];
610 assert_eq!(step_id(&ids, Some("a"), Step::Next), Some("b".to_owned()));
611 assert_eq!(step_id(&ids, Some("b"), Step::Previous), Some("a".to_owned()));
612 assert_eq!(step_id(&ids, Some("c"), Step::Next), None);
613 assert_eq!(step_id(&ids, Some("a"), Step::Previous), None);
614 assert_eq!(step_id(&ids, None, Step::Next), Some("a".to_owned()));
615 assert_eq!(step_id(&ids, Some("gone"), Step::Previous), Some("c".to_owned()));
616 assert_eq!(step_id(&[], None, Step::Next), None);
617 }
618
619 #[test]
620 fn visible_chats_skip_collapsed_sections_and_see_more_rows() {
621 let mut chats = vec![chat("fav", "group", false), chat("hid", "group", false)];
622 chats.extend((0..7).map(|index| muted_chat(&format!("m{index}"))));
623 chats.push(chat("other", "group", false));
624 let directory = sectioned_directory(
625 true,
626 true,
627 vec![
628 folder("fav-folder", FolderKind::Favorites, &["fav"]),
629 folder("work", FolderKind::UserCreated, &["hid"]),
630 folder("recent", FolderKind::Recent, &[]),
631 folder("muted-folder", FolderKind::Muted, &[]),
632 ],
633 );
634 let mut collapsed = HashSet::new();
635 let sections = build_sections(&input(&chats, &directory, &collapsed));
636 assert_eq!(
637 visible_chat_ids(&sections),
638 vec!["fav", "hid", "other", "m0", "m1", "m2", "m3", "m4"]
639 );
640 collapsed.insert("work".to_owned());
641 collapsed.insert("muted-folder".to_owned());
642 let sections = build_sections(&input(&chats, &directory, &collapsed));
643 assert_eq!(visible_chat_ids(&sections), vec!["fav", "other"]);
644 }
645
646 fn team(id: &str, hidden: bool, channel_ids: &[&str], hidden_channel_ids: &[&str]) -> SidebarTeam {
647 SidebarTeam {
648 team: store::TeamRecord {
649 id: id.into(),
650 name: id.into(),
651 },
652 channels: channel_ids
653 .iter()
654 .map(|channel_id| ChannelRecord {
655 id: (*channel_id).into(),
656 team_id: id.into(),
657 name: (*channel_id).into(),
658 membership_type: None,
659 last_message_at: None,
660 unread: false,
661 })
662 .collect(),
663 hidden,
664 hidden_channel_ids: hidden_channel_ids.iter().map(|id| (*id).to_owned()).collect(),
665 notifications: HashMap::new(),
666 }
667 }
668
669 #[test]
670 fn visible_channels_list_pinned_first_then_open_teams() {
671 let teams = [
672 team("t1", false, &["a", "b", "c"], &["b"]),
673 team("t2", false, &["d", "e"], &[]),
674 team("t3", true, &["f"], &[]),
675 ];
676 let pinned = ["e".to_owned(), "missing".to_owned()];
677 let order = |selected: Option<&str>,
678 hidden_teams_open: bool,
679 collapsed: &[&str],
680 revealed: &[&str]| {
681 let to_set = |ids: &[&str]| ids.iter().map(|id| (*id).to_owned()).collect::<HashSet<_>>();
682 let (collapsed, revealed) = (to_set(collapsed), to_set(revealed));
683 let input = ChannelOrderInput {
684 teams: &teams,
685 pinned_ids: &pinned,
686 collapsed_teams: &collapsed,
687 revealed_channel_teams: &revealed,
688 hidden_teams_open,
689 selected_channel: selected,
690 };
691 visible_channel_ids(&input).into_iter().map(str::to_owned).collect::<Vec<_>>()
692 };
693 assert_eq!(order(None, false, &[], &[]), vec!["e", "a", "c", "d"]);
694 assert_eq!(order(Some("b"), false, &[], &[]), vec!["e", "a", "b", "c", "d"]);
695 assert_eq!(order(Some("f"), false, &[], &[]), vec!["e", "a", "c", "d", "f"]);
696 assert_eq!(order(None, true, &[], &[]), vec!["e", "a", "c", "d", "f"]);
697 assert_eq!(order(None, true, &["t2"], &["t1"]), vec!["e", "a", "c", "b", "f"]);
698 }
699
520 700 #[test]
521 701 fn muted_chats_stay_out_of_unread_counts() {
522 702 let mut quiet = chat("a", "group", true);
@@ -1,7 +1,7 @@
1use std::collections::{HashMap, HashSet};
1use std::collections::{HashMap, HashSet};
2
2
3use chrono::{DateTime, FixedOffset, Utc};
3use chrono::{DateTime, FixedOffset, Utc};
4use store::{ChatRecord, Sidebar};
4use store::{ChannelRecord, ChatRecord, Sidebar, SidebarTeam};
5use teams_core::ChatSection;
5use teams_core::ChatSection;
6
6
7use crate::app_state::chat_title;
7use crate::app_state::chat_title;
@@ -326,12 +326,16 @@ pub fn build_sections(input: &SectionInput<'_>) -> Vec<Section> {
326 sections
326 sections
327}
327}
328
328
329pub fn next_chat_id(sections: &[Section], removed_id: &str) -> Option<String> {
329pub fn visible_chat_ids(sections: &[Section]) -> Vec<&str> {
330 let visible: Vec<&str> = sections
330 sections
331 .iter()
331 .iter()
332 .filter(|section| !section.collapsed)
332 .filter(|section| !section.collapsed)
333 .flat_map(|section| section.items.iter().map(|item| item.id.as_str()))
333 .flat_map(|section| section.items.iter().map(|item| item.id.as_str()))
334 .collect();
334 .collect()
335}
336
337pub fn next_chat_id(sections: &[Section], removed_id: &str) -> Option<String> {
338 let visible = visible_chat_ids(sections);
335 let position = visible.iter().position(|id| *id == removed_id)?;
339 let position = visible.iter().position(|id| *id == removed_id)?;
336 visible
340 visible
337 .get(position + 1)
341 .get(position + 1)
@@ -343,6 +347,89 @@ pub fn next_chat_id(sections: &[Section], removed_id: &str) -> Option<String> {
343 .map(|id| (*id).to_owned())
347 .map(|id| (*id).to_owned())
344}
348}
345
349
350#[derive(Debug, Clone, Copy, PartialEq, Eq)]
351pub enum Step {
352 Previous,
353 Next,
354}
355
356pub fn step_id(ids: &[&str], current: Option<&str>, step: Step) -> Option<String> {
357 let position = current.and_then(|current| ids.iter().position(|id| *id == current));
358 let target = match (position, step) {
359 (Some(position), Step::Next) => position + 1,
360 (Some(position), Step::Previous) => position.checked_sub(1)?,
361 (None, Step::Next) => 0,
362 (None, Step::Previous) => ids.len().checked_sub(1)?,
363 };
364 ids.get(target).map(|id| (*id).to_owned())
365}
366
367pub struct ChannelOrderInput<'a> {
368 pub teams: &'a [SidebarTeam],
369 pub pinned_ids: &'a [String],
370 pub collapsed_teams: &'a HashSet<String>,
371 pub revealed_channel_teams: &'a HashSet<String>,
372 pub hidden_teams_open: bool,
373 pub selected_channel: Option<&'a str>,
374}
375
376pub fn visible_channel_ids<'a>(input: &ChannelOrderInput<'a>) -> Vec<&'a str> {
377 let mut ids: Vec<&str> = Vec::new();
378 let mut push = |id: &'a str| {
379 if !ids.contains(&id) {
380 ids.push(id);
381 }
382 };
383 for pinned_id in input.pinned_ids {
384 let known = input
385 .teams
386 .iter()
387 .flat_map(|entry| entry.channels.iter())
388 .find(|channel| &channel.id == pinned_id);
389 if let Some(channel) = known {
390 push(&channel.id);
391 }
392 }
393 let holds_selection = |entry: &SidebarTeam| {
394 entry
395 .channels
396 .iter()
397 .any(|channel| Some(channel.id.as_str()) == input.selected_channel)
398 };
399 let hidden_teams_shown = input.hidden_teams_open
400 || input
401 .teams
402 .iter()
403 .any(|entry| entry.hidden && holds_selection(entry));
404 let teams = input
405 .teams
406 .iter()
407 .filter(|entry| !entry.hidden)
408 .chain(
409 input
410 .teams
411 .iter()
412 .filter(|entry| entry.hidden && hidden_teams_shown),
413 );
414 for entry in teams {
415 if input.collapsed_teams.contains(&entry.team.id) {
416 continue;
417 }
418 let is_hidden = |channel: &ChannelRecord| entry.hidden_channel_ids.contains(&channel.id);
419 let is_selected = |channel: &ChannelRecord| Some(channel.id.as_str()) == input.selected_channel;
420 let revealed = input.revealed_channel_teams.contains(&entry.team.id);
421 for channel in entry.channels.iter().filter(|channel| !is_hidden(channel) || is_selected(channel)) {
422 push(&channel.id);
423 }
424 if revealed {
425 for channel in entry.channels.iter().filter(|channel| is_hidden(channel) && !is_selected(channel)) {
426 push(&channel.id);
427 }
428 }
429 }
430 ids
431}
432
346fn section(
433fn section(
347 id: String,
434 id: String,
348 name: String,
435 name: String,
@@ -517,6 +604,99 @@ mod tests {
517 assert_eq!(next_chat_id(&sections, "a"), None);
604 assert_eq!(next_chat_id(&sections, "a"), None);
518 }
605 }
519
606
607 #[test]
608 fn stepping_follows_the_visible_order_without_wrapping() {
609 let ids = ["a", "b", "c"];
610 assert_eq!(step_id(&ids, Some("a"), Step::Next), Some("b".to_owned()));
611 assert_eq!(step_id(&ids, Some("b"), Step::Previous), Some("a".to_owned()));
612 assert_eq!(step_id(&ids, Some("c"), Step::Next), None);
613 assert_eq!(step_id(&ids, Some("a"), Step::Previous), None);
614 assert_eq!(step_id(&ids, None, Step::Next), Some("a".to_owned()));
615 assert_eq!(step_id(&ids, Some("gone"), Step::Previous), Some("c".to_owned()));
616 assert_eq!(step_id(&[], None, Step::Next), None);
617 }
618
619 #[test]
620 fn visible_chats_skip_collapsed_sections_and_see_more_rows() {
621 let mut chats = vec![chat("fav", "group", false), chat("hid", "group", false)];
622 chats.extend((0..7).map(|index| muted_chat(&format!("m{index}"))));
623 chats.push(chat("other", "group", false));
624 let directory = sectioned_directory(
625 true,
626 true,
627 vec![
628 folder("fav-folder", FolderKind::Favorites, &["fav"]),
629 folder("work", FolderKind::UserCreated, &["hid"]),
630 folder("recent", FolderKind::Recent, &[]),
631 folder("muted-folder", FolderKind::Muted, &[]),
632 ],
633 );
634 let mut collapsed = HashSet::new();
635 let sections = build_sections(&input(&chats, &directory, &collapsed));
636 assert_eq!(
637 visible_chat_ids(&sections),
638 vec!["fav", "hid", "other", "m0", "m1", "m2", "m3", "m4"]
639 );
640 collapsed.insert("work".to_owned());
641 collapsed.insert("muted-folder".to_owned());
642 let sections = build_sections(&input(&chats, &directory, &collapsed));
643 assert_eq!(visible_chat_ids(&sections), vec!["fav", "other"]);
644 }
645
646 fn team(id: &str, hidden: bool, channel_ids: &[&str], hidden_channel_ids: &[&str]) -> SidebarTeam {
647 SidebarTeam {
648 team: store::TeamRecord {
649 id: id.into(),
650 name: id.into(),
651 },
652 channels: channel_ids
653 .iter()
654 .map(|channel_id| ChannelRecord {
655 id: (*channel_id).into(),
656 team_id: id.into(),
657 name: (*channel_id).into(),
658 membership_type: None,
659 last_message_at: None,
660 unread: false,
661 })
662 .collect(),
663 hidden,
664 hidden_channel_ids: hidden_channel_ids.iter().map(|id| (*id).to_owned()).collect(),
665 notifications: HashMap::new(),
666 }
667 }
668
669 #[test]
670 fn visible_channels_list_pinned_first_then_open_teams() {
671 let teams = [
672 team("t1", false, &["a", "b", "c"], &["b"]),
673 team("t2", false, &["d", "e"], &[]),
674 team("t3", true, &["f"], &[]),
675 ];
676 let pinned = ["e".to_owned(), "missing".to_owned()];
677 let order = |selected: Option<&str>,
678 hidden_teams_open: bool,
679 collapsed: &[&str],
680 revealed: &[&str]| {
681 let to_set = |ids: &[&str]| ids.iter().map(|id| (*id).to_owned()).collect::<HashSet<_>>();
682 let (collapsed, revealed) = (to_set(collapsed), to_set(revealed));
683 let input = ChannelOrderInput {
684 teams: &teams,
685 pinned_ids: &pinned,
686 collapsed_teams: &collapsed,
687 revealed_channel_teams: &revealed,
688 hidden_teams_open,
689 selected_channel: selected,
690 };
691 visible_channel_ids(&input).into_iter().map(str::to_owned).collect::<Vec<_>>()
692 };
693 assert_eq!(order(None, false, &[], &[]), vec!["e", "a", "c", "d"]);
694 assert_eq!(order(Some("b"), false, &[], &[]), vec!["e", "a", "b", "c", "d"]);
695 assert_eq!(order(Some("f"), false, &[], &[]), vec!["e", "a", "c", "d", "f"]);
696 assert_eq!(order(None, true, &[], &[]), vec!["e", "a", "c", "d", "f"]);
697 assert_eq!(order(None, true, &["t2"], &["t1"]), vec!["e", "a", "c", "b", "f"]);
698 }
699
520 #[test]
700 #[test]
521 fn muted_chats_stay_out_of_unread_counts() {
701 fn muted_chats_stay_out_of_unread_counts() {
522 let mut quiet = chat("a", "group", true);
702 let mut quiet = chat("a", "group", true);
crates/app/src/views/composer.rs +2 −20
@@ -70,7 +70,7 @@ const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);
70 70 const DEMO_FAILURE_STEP: u8 = 6;
71 71 const HISTORY_LIMIT: usize = 200;
72 72 const PASTE_HINT_DURATION: Duration = Duration::from_secs(4);
73 const KEY_CONTEXT: &str = "Composer";
73 pub(super) const KEY_CONTEXT: &str = "Composer";
74 74 const IMAGE_TOKEN_PREFIX: &str = "image-";
75 75
76 76 actions!(
@@ -89,25 +89,7 @@ actions!(
89 89 );
90 90
91 91 pub fn bind_keys(cx: &mut App) {
92 cx.bind_keys([
93 KeyBinding::new("ctrl-b", ToggleBold, Some(KEY_CONTEXT)),
94 KeyBinding::new("ctrl-i", ToggleItalic, Some(KEY_CONTEXT)),
95 KeyBinding::new("ctrl-u", ToggleUnderline, Some(KEY_CONTEXT)),
96 KeyBinding::new("ctrl-shift-x", ToggleStrike, Some(KEY_CONTEXT)),
97 KeyBinding::new("ctrl-shift-=", ToggleSuperscript, Some(KEY_CONTEXT)),
98 KeyBinding::new("ctrl-=", ToggleSubscript, Some(KEY_CONTEXT)),
99 KeyBinding::new("ctrl-shift-c", ToggleCode, Some(KEY_CONTEXT)),
100 KeyBinding::new("ctrl-k", EditLink, Some(KEY_CONTEXT)),
101 KeyBinding::new("ctrl-shift-enter", ScheduleSend, Some(KEY_CONTEXT)),
102 #[cfg(target_os = "macos")]
103 KeyBinding::new("cmd-b", ToggleBold, Some(KEY_CONTEXT)),
104 #[cfg(target_os = "macos")]
105 KeyBinding::new("cmd-i", ToggleItalic, Some(KEY_CONTEXT)),
106 #[cfg(target_os = "macos")]
107 KeyBinding::new("cmd-u", ToggleUnderline, Some(KEY_CONTEXT)),
108 #[cfg(target_os = "macos")]
109 KeyBinding::new("cmd-k", EditLink, Some(KEY_CONTEXT)),
110 ]);
92 super::shortcuts::bind_scopes(cx, &[super::shortcuts::Scope::Composer]);
111 93 }
112 94
113 95 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -70,7 +70,7 @@ const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);
70const DEMO_FAILURE_STEP: u8 = 6;
70const DEMO_FAILURE_STEP: u8 = 6;
71const HISTORY_LIMIT: usize = 200;
71const HISTORY_LIMIT: usize = 200;
72const PASTE_HINT_DURATION: Duration = Duration::from_secs(4);
72const PASTE_HINT_DURATION: Duration = Duration::from_secs(4);
73const KEY_CONTEXT: &str = "Composer";
73pub(super) const KEY_CONTEXT: &str = "Composer";
74const IMAGE_TOKEN_PREFIX: &str = "image-";
74const IMAGE_TOKEN_PREFIX: &str = "image-";
75
75
76actions!(
76actions!(
@@ -89,25 +89,7 @@ actions!(
89);
89);
90
90
91pub fn bind_keys(cx: &mut App) {
91pub fn bind_keys(cx: &mut App) {
92 cx.bind_keys([
92 super::shortcuts::bind_scopes(cx, &[super::shortcuts::Scope::Composer]);
93 KeyBinding::new("ctrl-b", ToggleBold, Some(KEY_CONTEXT)),
94 KeyBinding::new("ctrl-i", ToggleItalic, Some(KEY_CONTEXT)),
95 KeyBinding::new("ctrl-u", ToggleUnderline, Some(KEY_CONTEXT)),
96 KeyBinding::new("ctrl-shift-x", ToggleStrike, Some(KEY_CONTEXT)),
97 KeyBinding::new("ctrl-shift-=", ToggleSuperscript, Some(KEY_CONTEXT)),
98 KeyBinding::new("ctrl-=", ToggleSubscript, Some(KEY_CONTEXT)),
99 KeyBinding::new("ctrl-shift-c", ToggleCode, Some(KEY_CONTEXT)),
100 KeyBinding::new("ctrl-k", EditLink, Some(KEY_CONTEXT)),
101 KeyBinding::new("ctrl-shift-enter", ScheduleSend, Some(KEY_CONTEXT)),
102 #[cfg(target_os = "macos")]
103 KeyBinding::new("cmd-b", ToggleBold, Some(KEY_CONTEXT)),
104 #[cfg(target_os = "macos")]
105 KeyBinding::new("cmd-i", ToggleItalic, Some(KEY_CONTEXT)),
106 #[cfg(target_os = "macos")]
107 KeyBinding::new("cmd-u", ToggleUnderline, Some(KEY_CONTEXT)),
108 #[cfg(target_os = "macos")]
109 KeyBinding::new("cmd-k", EditLink, Some(KEY_CONTEXT)),
110 ]);
111}
93}
112
94
113#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
95#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
crates/app/src/views/mod.rs +2 −0
@@ -37,6 +37,8 @@ pub mod saved_panel;
37 37 pub mod scheduled_toolbar;
38 38 pub mod shared_tab;
39 39 pub mod shell;
40 pub mod shortcuts;
41 pub mod shortcuts_dialog;
40 42 pub mod sidebar;
41 43 pub mod status_bar;
42 44 pub mod status_menu;
@@ -37,6 +37,8 @@ pub mod saved_panel;
37pub mod scheduled_toolbar;
37pub mod scheduled_toolbar;
38pub mod shared_tab;
38pub mod shared_tab;
39pub mod shell;
39pub mod shell;
40pub mod shortcuts;
41pub mod shortcuts_dialog;
40pub mod sidebar;
42pub mod sidebar;
41pub mod status_bar;
43pub mod status_bar;
42pub mod status_menu;
44pub mod status_menu;
crates/app/src/views/shell.rs +74 −10
@@ -10,6 +10,12 @@ use super::dialog_overlay::render_task_dialog;
10 10 use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
11 11 use super::profile_card::{ProfileCard, ProfileCardEvent};
12 12 use super::saved_panel::{SavedPanel, SavedPanelEvent};
13 use super::shortcuts::{
14 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenChannelsTab,
15 OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts, ToggleCallCamera,
16 ToggleCallShare,
17 };
18 use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
13 19 use super::sidebar::SidebarView;
14 20 use super::status_bar::render_status_bar;
15 21 use super::status_menu::own_status_button;
@@ -21,6 +27,7 @@ use crate::app_state::{AppEvent, AppState, Selection};
21 27 use crate::embedded_web::{Overlays, RootFocus};
22 28 use crate::notice::NoticeAction;
23 29 use crate::notify::{NotificationCenter, selection_for};
30 use crate::sidebar_model::Step;
24 31 use crate::theme;
25 32 use crate::updater::{self, IdleInputs, UpdateStatus};
26 33
@@ -28,16 +35,7 @@ actions!(teams, [OpenSwitcher, NewChat, ToggleCallMute]);
28 35
29 36 pub fn bind_keys(cx: &mut App) {
30 37 super::composer::bind_keys(cx);
31 cx.bind_keys([
32 KeyBinding::new("ctrl-k", OpenSwitcher, None),
33 KeyBinding::new("ctrl-n", NewChat, None),
34 KeyBinding::new("alt-r", ReplyToHovered, None),
35 KeyBinding::new("ctrl-shift-m", ToggleCallMute, None),
36 #[cfg(target_os = "macos")]
37 KeyBinding::new("cmd-k", OpenSwitcher, None),
38 #[cfg(target_os = "macos")]
39 KeyBinding::new("cmd-n", NewChat, None),
40 ]);
38 super::shortcuts::bind_scopes(cx, &[Scope::Global, Scope::OutsideComposer, Scope::GlobalOverTextFields]);
41 39 }
42 40
43 41 #[derive(Debug, Clone, Copy)]
@@ -64,6 +62,7 @@ pub struct AppShell {
64 62 saved_panel: Option<Entity<SavedPanel>>,
65 63 forward_dialog: Option<Entity<ForwardDialog>>,
66 64 status_dialog: Option<Entity<StatusMessageDialog>>,
65 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
67 66 profile_card: Option<Entity<ProfileCard>>,
68 67 focus_handle: FocusHandle,
69 68 open_target: Option<OpenTarget>,
@@ -127,6 +126,7 @@ impl AppShell {
127 126 saved_panel: None,
128 127 forward_dialog: None,
129 128 status_dialog: None,
129 shortcuts_dialog: None,
130 130 profile_card: None,
131 131 focus_handle,
132 132 open_target,
@@ -389,6 +389,30 @@ impl AppShell {
389 389 cx.notify();
390 390 }
391 391
392 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
393 if self.shortcuts_dialog.take().is_some() {
394 window.focus(&self.focus_handle, cx);
395 cx.notify();
396 return;
397 }
398 self.switcher = None;
399 self.activity_panel = None;
400 self.saved_panel = None;
401 let dialog = cx.new(|cx| ShortcutsDialog::new(window, cx));
402 cx.subscribe_in(
403 &dialog,
404 window,
405 |this, _, _: &ShortcutsDialogEvent, window, cx| {
406 this.shortcuts_dialog = None;
407 window.focus(&this.focus_handle, cx);
408 cx.notify();
409 },
410 )
411 .detach();
412 self.shortcuts_dialog = Some(dialog);
413 cx.notify();
414 }
415
392 416 fn open_profile_card(&mut self, window: &mut Window, cx: &mut Context<Self>) {
393 417 let Some(request) = self
394 418 .state
@@ -482,6 +506,7 @@ impl Render for AppShell {
482 506 || self.saved_panel.is_some()
483 507 || self.forward_dialog.is_some()
484 508 || self.status_dialog.is_some()
509 || self.shortcuts_dialog.is_some()
485 510 || self.profile_card.is_some()
486 511 || {
487 512 let state = self.state.read(cx);
@@ -521,6 +546,44 @@ impl Render for AppShell {
521 546 .on_action(cx.listener(|this, _: &ToggleCallMute, _, cx| {
522 547 this.state.update(cx, |state, cx| state.toggle_call_mute(cx));
523 548 }))
549 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
550 this.toggle_shortcuts_dialog(window, cx);
551 }))
552 .on_action(cx.listener(|this, _: &OpenActivity, window, cx| {
553 this.toggle_activity_panel(window, cx);
554 }))
555 .on_action(cx.listener(|this, _: &OpenSaved, window, cx| {
556 this.toggle_saved_panel(window, cx);
557 }))
558 .on_action(cx.listener(|this, _: &OpenChatsTab, _, cx| {
559 this.sidebar.update(cx, |sidebar, cx| sidebar.show_chats(cx));
560 }))
561 .on_action(cx.listener(|this, _: &OpenChannelsTab, _, cx| {
562 this.sidebar.update(cx, |sidebar, cx| sidebar.show_channels(cx));
563 }))
564 .on_action(cx.listener(|this, _: &PreviousConversation, _, cx| {
565 this.sidebar
566 .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Previous, cx));
567 }))
568 .on_action(cx.listener(|this, _: &NextConversation, _, cx| {
569 this.sidebar
570 .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Next, cx));
571 }))
572 .on_action(cx.listener(|this, _: &AcceptCall, _, cx| {
573 this.state.update(cx, |state, cx| state.accept_ringing_call(cx));
574 }))
575 .on_action(cx.listener(|this, _: &DeclineCall, _, cx| {
576 this.state.update(cx, |state, cx| state.decline_ringing_call(cx));
577 }))
578 .on_action(cx.listener(|this, _: &HangUpCall, _, cx| {
579 this.state.update(cx, |state, cx| state.leave_call(cx));
580 }))
581 .on_action(cx.listener(|this, _: &ToggleCallCamera, _, cx| {
582 this.state.update(cx, |state, cx| state.toggle_call_camera(cx));
583 }))
584 .on_action(cx.listener(|this, _: &ToggleCallShare, _, cx| {
585 this.state.update(cx, |state, cx| state.toggle_call_share(cx));
586 }))
524 587 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
525 588 this.conversation.update(cx, |conversation, cx| {
526 589 conversation.reply_to_hovered(window, cx)
@@ -557,6 +620,7 @@ impl Render for AppShell {
557 620 .children(render_task_dialog(self.state.read(cx), cx))
558 621 .children(self.forward_dialog.clone())
559 622 .children(self.status_dialog.clone())
623 .children(self.shortcuts_dialog.clone())
560 624 .children(self.profile_card.clone())
561 625 .child(crate::frame_log::probe("last"))
562 626 }
@@ -10,6 +10,12 @@ use super::dialog_overlay::render_task_dialog;
10use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
10use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
11use super::profile_card::{ProfileCard, ProfileCardEvent};
11use super::profile_card::{ProfileCard, ProfileCardEvent};
12use super::saved_panel::{SavedPanel, SavedPanelEvent};
12use super::saved_panel::{SavedPanel, SavedPanelEvent};
13use super::shortcuts::{
14 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenChannelsTab,
15 OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts, ToggleCallCamera,
16 ToggleCallShare,
17};
18use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
13use super::sidebar::SidebarView;
19use super::sidebar::SidebarView;
14use super::status_bar::render_status_bar;
20use super::status_bar::render_status_bar;
15use super::status_menu::own_status_button;
21use super::status_menu::own_status_button;
@@ -21,6 +27,7 @@ use crate::app_state::{AppEvent, AppState, Selection};
21use crate::embedded_web::{Overlays, RootFocus};
27use crate::embedded_web::{Overlays, RootFocus};
22use crate::notice::NoticeAction;
28use crate::notice::NoticeAction;
23use crate::notify::{NotificationCenter, selection_for};
29use crate::notify::{NotificationCenter, selection_for};
30use crate::sidebar_model::Step;
24use crate::theme;
31use crate::theme;
25use crate::updater::{self, IdleInputs, UpdateStatus};
32use crate::updater::{self, IdleInputs, UpdateStatus};
26
33
@@ -28,16 +35,7 @@ actions!(teams, [OpenSwitcher, NewChat, ToggleCallMute]);
28
35
29pub fn bind_keys(cx: &mut App) {
36pub fn bind_keys(cx: &mut App) {
30 super::composer::bind_keys(cx);
37 super::composer::bind_keys(cx);
31 cx.bind_keys([
38 super::shortcuts::bind_scopes(cx, &[Scope::Global, Scope::OutsideComposer, Scope::GlobalOverTextFields]);
32 KeyBinding::new("ctrl-k", OpenSwitcher, None),
33 KeyBinding::new("ctrl-n", NewChat, None),
34 KeyBinding::new("alt-r", ReplyToHovered, None),
35 KeyBinding::new("ctrl-shift-m", ToggleCallMute, None),
36 #[cfg(target_os = "macos")]
37 KeyBinding::new("cmd-k", OpenSwitcher, None),
38 #[cfg(target_os = "macos")]
39 KeyBinding::new("cmd-n", NewChat, None),
40 ]);
41}
39}
42
40
43#[derive(Debug, Clone, Copy)]
41#[derive(Debug, Clone, Copy)]
@@ -64,6 +62,7 @@ pub struct AppShell {
64 saved_panel: Option<Entity<SavedPanel>>,
62 saved_panel: Option<Entity<SavedPanel>>,
65 forward_dialog: Option<Entity<ForwardDialog>>,
63 forward_dialog: Option<Entity<ForwardDialog>>,
66 status_dialog: Option<Entity<StatusMessageDialog>>,
64 status_dialog: Option<Entity<StatusMessageDialog>>,
65 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
67 profile_card: Option<Entity<ProfileCard>>,
66 profile_card: Option<Entity<ProfileCard>>,
68 focus_handle: FocusHandle,
67 focus_handle: FocusHandle,
69 open_target: Option<OpenTarget>,
68 open_target: Option<OpenTarget>,
@@ -127,6 +126,7 @@ impl AppShell {
127 saved_panel: None,
126 saved_panel: None,
128 forward_dialog: None,
127 forward_dialog: None,
129 status_dialog: None,
128 status_dialog: None,
129 shortcuts_dialog: None,
130 profile_card: None,
130 profile_card: None,
131 focus_handle,
131 focus_handle,
132 open_target,
132 open_target,
@@ -389,6 +389,30 @@ impl AppShell {
389 cx.notify();
389 cx.notify();
390 }
390 }
391
391
392 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
393 if self.shortcuts_dialog.take().is_some() {
394 window.focus(&self.focus_handle, cx);
395 cx.notify();
396 return;
397 }
398 self.switcher = None;
399 self.activity_panel = None;
400 self.saved_panel = None;
401 let dialog = cx.new(|cx| ShortcutsDialog::new(window, cx));
402 cx.subscribe_in(
403 &dialog,
404 window,
405 |this, _, _: &ShortcutsDialogEvent, window, cx| {
406 this.shortcuts_dialog = None;
407 window.focus(&this.focus_handle, cx);
408 cx.notify();
409 },
410 )
411 .detach();
412 self.shortcuts_dialog = Some(dialog);
413 cx.notify();
414 }
415
392 fn open_profile_card(&mut self, window: &mut Window, cx: &mut Context<Self>) {
416 fn open_profile_card(&mut self, window: &mut Window, cx: &mut Context<Self>) {
393 let Some(request) = self
417 let Some(request) = self
394 .state
418 .state
@@ -482,6 +506,7 @@ impl Render for AppShell {
482 || self.saved_panel.is_some()
506 || self.saved_panel.is_some()
483 || self.forward_dialog.is_some()
507 || self.forward_dialog.is_some()
484 || self.status_dialog.is_some()
508 || self.status_dialog.is_some()
509 || self.shortcuts_dialog.is_some()
485 || self.profile_card.is_some()
510 || self.profile_card.is_some()
486 || {
511 || {
487 let state = self.state.read(cx);
512 let state = self.state.read(cx);
@@ -521,6 +546,44 @@ impl Render for AppShell {
521 .on_action(cx.listener(|this, _: &ToggleCallMute, _, cx| {
546 .on_action(cx.listener(|this, _: &ToggleCallMute, _, cx| {
522 this.state.update(cx, |state, cx| state.toggle_call_mute(cx));
547 this.state.update(cx, |state, cx| state.toggle_call_mute(cx));
523 }))
548 }))
549 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
550 this.toggle_shortcuts_dialog(window, cx);
551 }))
552 .on_action(cx.listener(|this, _: &OpenActivity, window, cx| {
553 this.toggle_activity_panel(window, cx);
554 }))
555 .on_action(cx.listener(|this, _: &OpenSaved, window, cx| {
556 this.toggle_saved_panel(window, cx);
557 }))
558 .on_action(cx.listener(|this, _: &OpenChatsTab, _, cx| {
559 this.sidebar.update(cx, |sidebar, cx| sidebar.show_chats(cx));
560 }))
561 .on_action(cx.listener(|this, _: &OpenChannelsTab, _, cx| {
562 this.sidebar.update(cx, |sidebar, cx| sidebar.show_channels(cx));
563 }))
564 .on_action(cx.listener(|this, _: &PreviousConversation, _, cx| {
565 this.sidebar
566 .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Previous, cx));
567 }))
568 .on_action(cx.listener(|this, _: &NextConversation, _, cx| {
569 this.sidebar
570 .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Next, cx));
571 }))
572 .on_action(cx.listener(|this, _: &AcceptCall, _, cx| {
573 this.state.update(cx, |state, cx| state.accept_ringing_call(cx));
574 }))
575 .on_action(cx.listener(|this, _: &DeclineCall, _, cx| {
576 this.state.update(cx, |state, cx| state.decline_ringing_call(cx));
577 }))
578 .on_action(cx.listener(|this, _: &HangUpCall, _, cx| {
579 this.state.update(cx, |state, cx| state.leave_call(cx));
580 }))
581 .on_action(cx.listener(|this, _: &ToggleCallCamera, _, cx| {
582 this.state.update(cx, |state, cx| state.toggle_call_camera(cx));
583 }))
584 .on_action(cx.listener(|this, _: &ToggleCallShare, _, cx| {
585 this.state.update(cx, |state, cx| state.toggle_call_share(cx));
586 }))
524 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
587 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
525 this.conversation.update(cx, |conversation, cx| {
588 this.conversation.update(cx, |conversation, cx| {
526 conversation.reply_to_hovered(window, cx)
589 conversation.reply_to_hovered(window, cx)
@@ -557,6 +620,7 @@ impl Render for AppShell {
557 .children(render_task_dialog(self.state.read(cx), cx))
620 .children(render_task_dialog(self.state.read(cx), cx))
558 .children(self.forward_dialog.clone())
621 .children(self.forward_dialog.clone())
559 .children(self.status_dialog.clone())
622 .children(self.status_dialog.clone())
623 .children(self.shortcuts_dialog.clone())
560 .children(self.profile_card.clone())
624 .children(self.profile_card.clone())
561 .child(crate::frame_log::probe("last"))
625 .child(crate::frame_log::probe("last"))
562 }
626 }
crates/app/src/views/shortcuts.rs added +285 −0
@@ -0,0 +1,285 @@
1 use gpui_kit::*;
2
3 use super::composer::{
4 EditLink, KEY_CONTEXT as COMPOSER_CONTEXT, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic,
5 ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,
6 };
7 use super::conversation::ReplyToHovered;
8 use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
9
10 const TEXT_FIELD_CONTEXT: &str = "Input";
11 const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
12
13 actions!(
14 teams,
15 [
16 OpenActivity,
17 OpenChatsTab,
18 OpenChannelsTab,
19 OpenSaved,
20 PreviousConversation,
21 NextConversation,
22 AcceptCall,
23 DeclineCall,
24 HangUpCall,
25 ToggleCallCamera,
26 ToggleCallShare,
27 ShowShortcuts
28 ]
29 );
30
31 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
32 pub enum Group {
33 General,
34 Navigation,
35 Composer,
36 Calls,
37 }
38
39 impl Group {
40 pub const ALL: [Group; 4] = [
41 Group::General,
42 Group::Navigation,
43 Group::Composer,
44 Group::Calls,
45 ];
46
47 pub fn title(self) -> &'static str {
48 match self {
49 Group::General => "General",
50 Group::Navigation => "Navigation",
51 Group::Composer => "Messages and composer",
52 Group::Calls => "Calls",
53 }
54 }
55 }
56
57 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
58 pub enum Scope {
59 Global,
60 OutsideComposer,
61 GlobalOverTextFields,
62 Composer,
63 }
64
65 pub struct Shortcut {
66 pub group: Group,
67 pub label: &'static str,
68 pub keys: &'static str,
69 pub mac_keys: Option<&'static str>,
70 pub scope: Scope,
71 bind: fn(&str, Option<&str>) -> KeyBinding,
72 }
73
74 macro_rules! shortcut {
75 ($group:ident, $scope:ident, $label:expr, $keys:expr, $mac_keys:expr, $action:expr) => {
76 Shortcut {
77 group: Group::$group,
78 label: $label,
79 keys: $keys,
80 mac_keys: $mac_keys,
81 scope: Scope::$scope,
82 bind: |keys, context| KeyBinding::new(keys, $action, context),
83 }
84 };
85 }
86
87 #[rustfmt::skip]
88 pub const SHORTCUTS: &[Shortcut] = &[
89 shortcut!(General, OutsideComposer, "Search and switch chats", "ctrl-k", Some("cmd-k"), OpenSwitcher),
90 shortcut!(General, Global, "New chat", "ctrl-n", Some("cmd-n"), NewChat),
91 shortcut!(General, GlobalOverTextFields, "Keyboard shortcuts", "ctrl-.", Some("cmd-."), ShowShortcuts),
92 shortcut!(Navigation, GlobalOverTextFields, "Open Activity", "ctrl-1", Some("cmd-1"), OpenActivity),
93 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
94 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
95 shortcut!(Navigation, GlobalOverTextFields, "Open Saved", "ctrl-4", Some("cmd-4"), OpenSaved),
96 shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
97 shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),
98 shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),
99 shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),
100 shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),
101 shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),
102 shortcut!(Composer, Composer, "Strikethrough", "ctrl-shift-x", None, ToggleStrike),
103 shortcut!(Composer, Composer, "Superscript", "ctrl-shift-=", None, ToggleSuperscript),
104 shortcut!(Composer, Composer, "Subscript", "ctrl-=", None, ToggleSubscript),
105 shortcut!(Composer, Composer, "Code", "ctrl-shift-c", None, ToggleCode),
106 shortcut!(Composer, Composer, "Insert link", "ctrl-k", Some("cmd-k"), EditLink),
107 shortcut!(Composer, Composer, "Schedule send", "ctrl-shift-enter", None, ScheduleSend),
108 shortcut!(Calls, GlobalOverTextFields, "Accept incoming call", "ctrl-shift-a", Some("cmd-shift-a"), AcceptCall),
109 shortcut!(Calls, GlobalOverTextFields, "Decline incoming call", "ctrl-shift-d", Some("cmd-shift-d"), DeclineCall),
110 shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),
111 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
112 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
113 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
114 ];
115
116 impl Shortcut {
117 pub fn keys_for_platform(&self) -> &'static str {
118 match self.mac_keys {
119 Some(mac_keys) if cfg!(target_os = "macos") => mac_keys,
120 _ => self.keys,
121 }
122 }
123
124 pub fn display_keys(&self) -> String {
125 display_keys(self.keys_for_platform())
126 }
127
128 fn bindings(&self) -> Vec<KeyBinding> {
129 let contexts: &[Option<&str>] = match self.scope {
130 Scope::Global => &[None],
131 Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],
132 Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],
133 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
134 };
135 let mut keys = vec![self.keys];
136 keys.extend(self.mac_keys.filter(|_| cfg!(target_os = "macos")));
137 keys.iter()
138 .flat_map(|keys| contexts.iter().map(|context| (self.bind)(keys, *context)))
139 .collect()
140 }
141 }
142
143 pub fn display_keys(keys: &str) -> String {
144 keys.split('-')
145 .map(|part| match part {
146 "ctrl" => "Ctrl".to_owned(),
147 "cmd" => "Cmd".to_owned(),
148 "alt" => "Alt".to_owned(),
149 "shift" => "Shift".to_owned(),
150 "up" => "Up".to_owned(),
151 "down" => "Down".to_owned(),
152 "enter" => "Enter".to_owned(),
153 other => other.to_uppercase(),
154 })
155 .collect::<Vec<_>>()
156 .join("+")
157 }
158
159 pub fn bind_scopes(cx: &mut App, scopes: &[Scope]) {
160 cx.bind_keys(
161 SHORTCUTS
162 .iter()
163 .filter(|shortcut| scopes.contains(&shortcut.scope))
164 .flat_map(Shortcut::bindings),
165 );
166 }
167
168 pub fn shortcuts_in(group: Group) -> impl Iterator<Item = &'static Shortcut> {
169 SHORTCUTS
170 .iter()
171 .filter(move |shortcut| shortcut.group == group)
172 }
173
174 #[cfg(test)]
175 mod tests {
176 use std::collections::HashSet;
177
178 use gpui_kit::{KeyContext, Keystroke, TestAppContext};
179
180 use super::{Group, SHORTCUTS, Scope, Shortcut, display_keys, shortcuts_in};
181 use crate::views::shell::bind_keys;
182
183 fn bound_action(cx: &mut TestAppContext, keys: &str, contexts: &[&str]) -> Option<String> {
184 let stack: Vec<KeyContext> = contexts
185 .iter()
186 .map(|context| KeyContext::parse(context).unwrap())
187 .collect();
188 let keystroke = Keystroke::parse(keys).unwrap();
189 cx.update(|cx| {
190 let keymap = cx.key_bindings();
191 let (bindings, _) = keymap.borrow().bindings_for_input(&[keystroke], &stack);
192 bindings
193 .first()
194 .map(|binding| binding.action().name().to_owned())
195 })
196 }
197
198 fn registered(cx: &mut TestAppContext) {
199 cx.update(gpui_kit::init);
200 cx.update(bind_keys);
201 }
202
203 fn action_name(shortcut: &Shortcut) -> String {
204 shortcut.bindings()[0].action().name().to_owned()
205 }
206
207 #[gpui_kit::test]
208 fn every_listed_shortcut_resolves_to_its_action(cx: &mut TestAppContext) {
209 registered(cx);
210 for shortcut in SHORTCUTS {
211 let contexts: &[&str] = match shortcut.scope {
212 Scope::Global | Scope::OutsideComposer => &["AppShell"],
213 Scope::GlobalOverTextFields => &["AppShell"],
214 Scope::Composer => &["AppShell", "Composer"],
215 };
216 assert_eq!(
217 bound_action(cx, shortcut.keys, contexts),
218 Some(action_name(shortcut)),
219 "{} ({})",
220 shortcut.label,
221 shortcut.keys
222 );
223 }
224 }
225
226 #[gpui_kit::test]
227 fn global_shortcuts_survive_typing_in_the_composer(cx: &mut TestAppContext) {
228 registered(cx);
229 for shortcut in SHORTCUTS
230 .iter()
231 .filter(|shortcut| shortcut.scope == Scope::GlobalOverTextFields)
232 {
233 assert_eq!(
234 bound_action(cx, shortcut.keys, &["AppShell", "Composer", "Input"]),
235 Some(action_name(shortcut)),
236 "{} ({})",
237 shortcut.label,
238 shortcut.keys
239 );
240 }
241 }
242
243 #[gpui_kit::test]
244 fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {
245 registered(cx);
246 let typing = ["AppShell", "Composer", "Input"];
247 assert_eq!(
248 bound_action(cx, "ctrl-k", &typing),
249 Some(action_name(
250 SHORTCUTS
251 .iter()
252 .find(|shortcut| shortcut.label == "Insert link")
253 .unwrap()
254 ))
255 );
256 assert_eq!(
257 bound_action(cx, "ctrl-k", &["AppShell"]),
258 Some(action_name(
259 SHORTCUTS
260 .iter()
261 .find(|shortcut| shortcut.label == "Search and switch chats")
262 .unwrap()
263 ))
264 );
265 }
266
267 #[test]
268 fn no_two_shortcuts_share_keys_in_the_same_scope() {
269 let mut seen = HashSet::new();
270 for shortcut in SHORTCUTS {
271 let scope = matches!(shortcut.scope, Scope::Composer);
272 assert!(seen.insert((shortcut.keys, scope)), "{}", shortcut.keys);
273 }
274 }
275
276 #[test]
277 fn every_group_lists_shortcuts_and_keys_read_like_teams() {
278 for group in Group::ALL {
279 assert!(shortcuts_in(group).next().is_some(), "{group:?}");
280 }
281 assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");
282 assert_eq!(display_keys("alt-up"), "Alt+Up");
283 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
284 }
285 }
@@ -0,0 +1,285 @@
1use gpui_kit::*;
2
3use super::composer::{
4 EditLink, KEY_CONTEXT as COMPOSER_CONTEXT, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic,
5 ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,
6};
7use super::conversation::ReplyToHovered;
8use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
9
10const TEXT_FIELD_CONTEXT: &str = "Input";
11const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
12
13actions!(
14 teams,
15 [
16 OpenActivity,
17 OpenChatsTab,
18 OpenChannelsTab,
19 OpenSaved,
20 PreviousConversation,
21 NextConversation,
22 AcceptCall,
23 DeclineCall,
24 HangUpCall,
25 ToggleCallCamera,
26 ToggleCallShare,
27 ShowShortcuts
28 ]
29);
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum Group {
33 General,
34 Navigation,
35 Composer,
36 Calls,
37}
38
39impl Group {
40 pub const ALL: [Group; 4] = [
41 Group::General,
42 Group::Navigation,
43 Group::Composer,
44 Group::Calls,
45 ];
46
47 pub fn title(self) -> &'static str {
48 match self {
49 Group::General => "General",
50 Group::Navigation => "Navigation",
51 Group::Composer => "Messages and composer",
52 Group::Calls => "Calls",
53 }
54 }
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum Scope {
59 Global,
60 OutsideComposer,
61 GlobalOverTextFields,
62 Composer,
63}
64
65pub struct Shortcut {
66 pub group: Group,
67 pub label: &'static str,
68 pub keys: &'static str,
69 pub mac_keys: Option<&'static str>,
70 pub scope: Scope,
71 bind: fn(&str, Option<&str>) -> KeyBinding,
72}
73
74macro_rules! shortcut {
75 ($group:ident, $scope:ident, $label:expr, $keys:expr, $mac_keys:expr, $action:expr) => {
76 Shortcut {
77 group: Group::$group,
78 label: $label,
79 keys: $keys,
80 mac_keys: $mac_keys,
81 scope: Scope::$scope,
82 bind: |keys, context| KeyBinding::new(keys, $action, context),
83 }
84 };
85}
86
87#[rustfmt::skip]
88pub const SHORTCUTS: &[Shortcut] = &[
89 shortcut!(General, OutsideComposer, "Search and switch chats", "ctrl-k", Some("cmd-k"), OpenSwitcher),
90 shortcut!(General, Global, "New chat", "ctrl-n", Some("cmd-n"), NewChat),
91 shortcut!(General, GlobalOverTextFields, "Keyboard shortcuts", "ctrl-.", Some("cmd-."), ShowShortcuts),
92 shortcut!(Navigation, GlobalOverTextFields, "Open Activity", "ctrl-1", Some("cmd-1"), OpenActivity),
93 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
94 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
95 shortcut!(Navigation, GlobalOverTextFields, "Open Saved", "ctrl-4", Some("cmd-4"), OpenSaved),
96 shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
97 shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),
98 shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),
99 shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),
100 shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),
101 shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),
102 shortcut!(Composer, Composer, "Strikethrough", "ctrl-shift-x", None, ToggleStrike),
103 shortcut!(Composer, Composer, "Superscript", "ctrl-shift-=", None, ToggleSuperscript),
104 shortcut!(Composer, Composer, "Subscript", "ctrl-=", None, ToggleSubscript),
105 shortcut!(Composer, Composer, "Code", "ctrl-shift-c", None, ToggleCode),
106 shortcut!(Composer, Composer, "Insert link", "ctrl-k", Some("cmd-k"), EditLink),
107 shortcut!(Composer, Composer, "Schedule send", "ctrl-shift-enter", None, ScheduleSend),
108 shortcut!(Calls, GlobalOverTextFields, "Accept incoming call", "ctrl-shift-a", Some("cmd-shift-a"), AcceptCall),
109 shortcut!(Calls, GlobalOverTextFields, "Decline incoming call", "ctrl-shift-d", Some("cmd-shift-d"), DeclineCall),
110 shortcut!(Calls, GlobalOverTextFields, "Hang up or leave", "ctrl-shift-h", Some("cmd-shift-h"), HangUpCall),
111 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
112 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
113 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
114];
115
116impl Shortcut {
117 pub fn keys_for_platform(&self) -> &'static str {
118 match self.mac_keys {
119 Some(mac_keys) if cfg!(target_os = "macos") => mac_keys,
120 _ => self.keys,
121 }
122 }
123
124 pub fn display_keys(&self) -> String {
125 display_keys(self.keys_for_platform())
126 }
127
128 fn bindings(&self) -> Vec<KeyBinding> {
129 let contexts: &[Option<&str>] = match self.scope {
130 Scope::Global => &[None],
131 Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],
132 Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],
133 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
134 };
135 let mut keys = vec![self.keys];
136 keys.extend(self.mac_keys.filter(|_| cfg!(target_os = "macos")));
137 keys.iter()
138 .flat_map(|keys| contexts.iter().map(|context| (self.bind)(keys, *context)))
139 .collect()
140 }
141}
142
143pub fn display_keys(keys: &str) -> String {
144 keys.split('-')
145 .map(|part| match part {
146 "ctrl" => "Ctrl".to_owned(),
147 "cmd" => "Cmd".to_owned(),
148 "alt" => "Alt".to_owned(),
149 "shift" => "Shift".to_owned(),
150 "up" => "Up".to_owned(),
151 "down" => "Down".to_owned(),
152 "enter" => "Enter".to_owned(),
153 other => other.to_uppercase(),
154 })
155 .collect::<Vec<_>>()
156 .join("+")
157}
158
159pub fn bind_scopes(cx: &mut App, scopes: &[Scope]) {
160 cx.bind_keys(
161 SHORTCUTS
162 .iter()
163 .filter(|shortcut| scopes.contains(&shortcut.scope))
164 .flat_map(Shortcut::bindings),
165 );
166}
167
168pub fn shortcuts_in(group: Group) -> impl Iterator<Item = &'static Shortcut> {
169 SHORTCUTS
170 .iter()
171 .filter(move |shortcut| shortcut.group == group)
172}
173
174#[cfg(test)]
175mod tests {
176 use std::collections::HashSet;
177
178 use gpui_kit::{KeyContext, Keystroke, TestAppContext};
179
180 use super::{Group, SHORTCUTS, Scope, Shortcut, display_keys, shortcuts_in};
181 use crate::views::shell::bind_keys;
182
183 fn bound_action(cx: &mut TestAppContext, keys: &str, contexts: &[&str]) -> Option<String> {
184 let stack: Vec<KeyContext> = contexts
185 .iter()
186 .map(|context| KeyContext::parse(context).unwrap())
187 .collect();
188 let keystroke = Keystroke::parse(keys).unwrap();
189 cx.update(|cx| {
190 let keymap = cx.key_bindings();
191 let (bindings, _) = keymap.borrow().bindings_for_input(&[keystroke], &stack);
192 bindings
193 .first()
194 .map(|binding| binding.action().name().to_owned())
195 })
196 }
197
198 fn registered(cx: &mut TestAppContext) {
199 cx.update(gpui_kit::init);
200 cx.update(bind_keys);
201 }
202
203 fn action_name(shortcut: &Shortcut) -> String {
204 shortcut.bindings()[0].action().name().to_owned()
205 }
206
207 #[gpui_kit::test]
208 fn every_listed_shortcut_resolves_to_its_action(cx: &mut TestAppContext) {
209 registered(cx);
210 for shortcut in SHORTCUTS {
211 let contexts: &[&str] = match shortcut.scope {
212 Scope::Global | Scope::OutsideComposer => &["AppShell"],
213 Scope::GlobalOverTextFields => &["AppShell"],
214 Scope::Composer => &["AppShell", "Composer"],
215 };
216 assert_eq!(
217 bound_action(cx, shortcut.keys, contexts),
218 Some(action_name(shortcut)),
219 "{} ({})",
220 shortcut.label,
221 shortcut.keys
222 );
223 }
224 }
225
226 #[gpui_kit::test]
227 fn global_shortcuts_survive_typing_in_the_composer(cx: &mut TestAppContext) {
228 registered(cx);
229 for shortcut in SHORTCUTS
230 .iter()
231 .filter(|shortcut| shortcut.scope == Scope::GlobalOverTextFields)
232 {
233 assert_eq!(
234 bound_action(cx, shortcut.keys, &["AppShell", "Composer", "Input"]),
235 Some(action_name(shortcut)),
236 "{} ({})",
237 shortcut.label,
238 shortcut.keys
239 );
240 }
241 }
242
243 #[gpui_kit::test]
244 fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {
245 registered(cx);
246 let typing = ["AppShell", "Composer", "Input"];
247 assert_eq!(
248 bound_action(cx, "ctrl-k", &typing),
249 Some(action_name(
250 SHORTCUTS
251 .iter()
252 .find(|shortcut| shortcut.label == "Insert link")
253 .unwrap()
254 ))
255 );
256 assert_eq!(
257 bound_action(cx, "ctrl-k", &["AppShell"]),
258 Some(action_name(
259 SHORTCUTS
260 .iter()
261 .find(|shortcut| shortcut.label == "Search and switch chats")
262 .unwrap()
263 ))
264 );
265 }
266
267 #[test]
268 fn no_two_shortcuts_share_keys_in_the_same_scope() {
269 let mut seen = HashSet::new();
270 for shortcut in SHORTCUTS {
271 let scope = matches!(shortcut.scope, Scope::Composer);
272 assert!(seen.insert((shortcut.keys, scope)), "{}", shortcut.keys);
273 }
274 }
275
276 #[test]
277 fn every_group_lists_shortcuts_and_keys_read_like_teams() {
278 for group in Group::ALL {
279 assert!(shortcuts_in(group).next().is_some(), "{group:?}");
280 }
281 assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");
282 assert_eq!(display_keys("alt-up"), "Alt+Up");
283 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
284 }
285}
crates/app/src/views/shortcuts_dialog.rs added +160 −0
@@ -0,0 +1,160 @@
1 use gpui_kit::component::{h_flex, v_flex};
2 use gpui_kit::*;
3
4 use super::shortcuts::{Group, shortcuts_in};
5 use super::widgets::symbol;
6 use crate::theme;
7
8 const CARD_WIDTH: f32 = 520.;
9 const CARD_RADIUS: f32 = 12.;
10 const CARD_PADDING: f32 = 16.;
11 const CARD_MARGIN: f32 = 32.;
12 const SECTION_GAP: f32 = 12.;
13 const ROW_GAP: f32 = 6.;
14 const BACKDROP_OPACITY: f32 = 0.55;
15 const CLOSE_SIZE: f32 = 28.;
16
17 pub enum ShortcutsDialogEvent {
18 Close,
19 }
20
21 pub struct ShortcutsDialog {
22 focus_handle: FocusHandle,
23 }
24
25 impl EventEmitter<ShortcutsDialogEvent> for ShortcutsDialog {}
26
27 impl ShortcutsDialog {
28 pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
29 let focus_handle = cx.focus_handle();
30 window.focus(&focus_handle, cx);
31 ShortcutsDialog { focus_handle }
32 }
33
34 fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) {
35 if event.keystroke.key != "escape" {
36 return;
37 }
38 cx.emit(ShortcutsDialogEvent::Close);
39 cx.stop_propagation();
40 }
41
42 fn header(&self, cx: &mut Context<Self>) -> Div {
43 h_flex()
44 .w_full()
45 .items_center()
46 .gap(px(SECTION_GAP))
47 .child(
48 div()
49 .flex_1()
50 .text_size(px(15.))
51 .font_weight(FontWeight::SEMIBOLD)
52 .child("Keyboard shortcuts"),
53 )
54 .child(
55 div()
56 .id("shortcuts-close")
57 .size(px(CLOSE_SIZE))
58 .flex_none()
59 .flex()
60 .items_center()
61 .justify_center()
62 .rounded_full()
63 .cursor_pointer()
64 .hover(|button| button.bg(theme::row_hover()))
65 .on_click(cx.listener(|_, _, _, cx| cx.emit(ShortcutsDialogEvent::Close)))
66 .child(symbol("close", 16., theme::text_muted())),
67 )
68 }
69 }
70
71 fn key_chip(keys: String) -> Div {
72 div()
73 .flex_none()
74 .px(px(8.))
75 .py(px(2.))
76 .rounded(px(6.))
77 .bg(theme::surface())
78 .border_1()
79 .border_color(theme::border())
80 .text_size(px(12.))
81 .text_color(theme::text_muted())
82 .child(keys)
83 }
84
85 fn group_block(group: Group) -> Div {
86 let rows = shortcuts_in(group).map(|shortcut| {
87 h_flex()
88 .w_full()
89 .items_center()
90 .justify_between()
91 .gap(px(SECTION_GAP))
92 .text_size(px(13.))
93 .child(div().flex_1().min_w_0().child(shortcut.label))
94 .child(key_chip(shortcut.display_keys()))
95 });
96 v_flex()
97 .w_full()
98 .gap(px(ROW_GAP))
99 .child(
100 div()
101 .text_size(px(12.))
102 .font_weight(FontWeight::SEMIBOLD)
103 .text_color(theme::text_muted())
104 .child(group.title()),
105 )
106 .children(rows)
107 }
108
109 impl Render for ShortcutsDialog {
110 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
111 div()
112 .id("shortcuts-layer")
113 .absolute()
114 .top_0()
115 .left_0()
116 .size_full()
117 .flex()
118 .items_center()
119 .justify_center()
120 .child(
121 div()
122 .id("shortcuts-backdrop")
123 .absolute()
124 .top_0()
125 .left_0()
126 .size_full()
127 .bg(black().opacity(BACKDROP_OPACITY))
128 .occlude()
129 .on_click(cx.listener(|_, _, _, cx| cx.emit(ShortcutsDialogEvent::Close))),
130 )
131 .child(
132 v_flex()
133 .id("shortcuts-card")
134 .track_focus(&self.focus_handle)
135 .w(px(CARD_WIDTH))
136 .max_w(relative(1.))
137 .max_h(relative(1.))
138 .m(px(CARD_MARGIN))
139 .p(px(CARD_PADDING))
140 .gap(px(SECTION_GAP))
141 .rounded(px(CARD_RADIUS))
142 .bg(theme::background())
143 .border_1()
144 .border_color(theme::border_strong())
145 .text_color(theme::text())
146 .shadow_lg()
147 .occlude()
148 .capture_key_down(cx.listener(Self::on_key_down))
149 .child(self.header(cx))
150 .child(
151 v_flex()
152 .id("shortcuts-body")
153 .min_h_0()
154 .gap(px(SECTION_GAP))
155 .overflow_y_scroll()
156 .children(Group::ALL.into_iter().map(group_block)),
157 ),
158 )
159 }
160 }
@@ -0,0 +1,160 @@
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::shortcuts::{Group, shortcuts_in};
5use super::widgets::symbol;
6use crate::theme;
7
8const CARD_WIDTH: f32 = 520.;
9const CARD_RADIUS: f32 = 12.;
10const CARD_PADDING: f32 = 16.;
11const CARD_MARGIN: f32 = 32.;
12const SECTION_GAP: f32 = 12.;
13const ROW_GAP: f32 = 6.;
14const BACKDROP_OPACITY: f32 = 0.55;
15const CLOSE_SIZE: f32 = 28.;
16
17pub enum ShortcutsDialogEvent {
18 Close,
19}
20
21pub struct ShortcutsDialog {
22 focus_handle: FocusHandle,
23}
24
25impl EventEmitter<ShortcutsDialogEvent> for ShortcutsDialog {}
26
27impl ShortcutsDialog {
28 pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
29 let focus_handle = cx.focus_handle();
30 window.focus(&focus_handle, cx);
31 ShortcutsDialog { focus_handle }
32 }
33
34 fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) {
35 if event.keystroke.key != "escape" {
36 return;
37 }
38 cx.emit(ShortcutsDialogEvent::Close);
39 cx.stop_propagation();
40 }
41
42 fn header(&self, cx: &mut Context<Self>) -> Div {
43 h_flex()
44 .w_full()
45 .items_center()
46 .gap(px(SECTION_GAP))
47 .child(
48 div()
49 .flex_1()
50 .text_size(px(15.))
51 .font_weight(FontWeight::SEMIBOLD)
52 .child("Keyboard shortcuts"),
53 )
54 .child(
55 div()
56 .id("shortcuts-close")
57 .size(px(CLOSE_SIZE))
58 .flex_none()
59 .flex()
60 .items_center()
61 .justify_center()
62 .rounded_full()
63 .cursor_pointer()
64 .hover(|button| button.bg(theme::row_hover()))
65 .on_click(cx.listener(|_, _, _, cx| cx.emit(ShortcutsDialogEvent::Close)))
66 .child(symbol("close", 16., theme::text_muted())),
67 )
68 }
69}
70
71fn key_chip(keys: String) -> Div {
72 div()
73 .flex_none()
74 .px(px(8.))
75 .py(px(2.))
76 .rounded(px(6.))
77 .bg(theme::surface())
78 .border_1()
79 .border_color(theme::border())
80 .text_size(px(12.))
81 .text_color(theme::text_muted())
82 .child(keys)
83}
84
85fn group_block(group: Group) -> Div {
86 let rows = shortcuts_in(group).map(|shortcut| {
87 h_flex()
88 .w_full()
89 .items_center()
90 .justify_between()
91 .gap(px(SECTION_GAP))
92 .text_size(px(13.))
93 .child(div().flex_1().min_w_0().child(shortcut.label))
94 .child(key_chip(shortcut.display_keys()))
95 });
96 v_flex()
97 .w_full()
98 .gap(px(ROW_GAP))
99 .child(
100 div()
101 .text_size(px(12.))
102 .font_weight(FontWeight::SEMIBOLD)
103 .text_color(theme::text_muted())
104 .child(group.title()),
105 )
106 .children(rows)
107}
108
109impl Render for ShortcutsDialog {
110 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
111 div()
112 .id("shortcuts-layer")
113 .absolute()
114 .top_0()
115 .left_0()
116 .size_full()
117 .flex()
118 .items_center()
119 .justify_center()
120 .child(
121 div()
122 .id("shortcuts-backdrop")
123 .absolute()
124 .top_0()
125 .left_0()
126 .size_full()
127 .bg(black().opacity(BACKDROP_OPACITY))
128 .occlude()
129 .on_click(cx.listener(|_, _, _, cx| cx.emit(ShortcutsDialogEvent::Close))),
130 )
131 .child(
132 v_flex()
133 .id("shortcuts-card")
134 .track_focus(&self.focus_handle)
135 .w(px(CARD_WIDTH))
136 .max_w(relative(1.))
137 .max_h(relative(1.))
138 .m(px(CARD_MARGIN))
139 .p(px(CARD_PADDING))
140 .gap(px(SECTION_GAP))
141 .rounded(px(CARD_RADIUS))
142 .bg(theme::background())
143 .border_1()
144 .border_color(theme::border_strong())
145 .text_color(theme::text())
146 .shadow_lg()
147 .occlude()
148 .capture_key_down(cx.listener(Self::on_key_down))
149 .child(self.header(cx))
150 .child(
151 v_flex()
152 .id("shortcuts-body")
153 .min_h_0()
154 .gap(px(SECTION_GAP))
155 .overflow_y_scroll()
156 .children(Group::ALL.into_iter().map(group_block)),
157 ),
158 )
159 }
160}
crates/app/src/views/sidebar.rs +44 −2
@@ -21,8 +21,9 @@ use crate::format;
21 21 use crate::local_previews::LocalPreview;
22 22 use crate::notice::truncated;
23 23 use crate::sidebar_model::{
24 AvatarSpec, ChatItem, DELETED_PREVIEW, EMPTY_FOLDER_HINT, Preview, Section, SectionInput,
25 SectionKind, any_unread_channel, build_sections, unread_chat_count,
24 AvatarSpec, ChannelOrderInput, ChatItem, DELETED_PREVIEW, EMPTY_FOLDER_HINT, Preview, Section,
25 SectionInput, SectionKind, Step, any_unread_channel, build_sections, step_id, unread_chat_count,
26 visible_channel_ids,
26 27 };
27 28 use crate::theme;
28 29
@@ -356,6 +357,47 @@ impl SidebarView {
356 357 }
357 358 }
358 359
360 pub fn show_chats(&mut self, cx: &mut Context<Self>) {
361 self.tab = SidebarTab::Chats;
362 cx.notify();
363 }
364
365 pub fn show_channels(&mut self, cx: &mut Context<Self>) {
366 self.tab = SidebarTab::Channels;
367 cx.notify();
368 }
369
370 pub fn select_adjacent(&mut self, step: Step, cx: &mut Context<Self>) {
371 let selection = match self.tab {
372 SidebarTab::Chats => self
373 .state
374 .read(cx)
375 .adjacent_chat_id(step)
376 .map(Selection::Chat),
377 SidebarTab::Channels => self.adjacent_channel_id(step, cx).map(Selection::Channel),
378 };
379 if let Some(selection) = selection {
380 self.state.update(cx, |state, cx| state.select(selection, cx));
381 }
382 }
383
384 fn adjacent_channel_id(&self, step: Step, cx: &mut Context<Self>) -> Option<String> {
385 let state = self.state.read(cx);
386 let selected_channel = match &state.selection {
387 Some(Selection::Channel(channel_id)) => Some(channel_id.as_str()),
388 _ => None,
389 };
390 let input = ChannelOrderInput {
391 teams: &state.sidebar.teams,
392 pinned_ids: &state.directory.pinned_channels,
393 collapsed_teams: &self.collapsed_teams,
394 revealed_channel_teams: &self.revealed_channel_teams,
395 hidden_teams_open: self.hidden_teams_open,
396 selected_channel,
397 };
398 step_id(&visible_channel_ids(&input), selected_channel, step)
399 }
400
359 401 fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) {
360 402 let state = self.state.read(cx);
361 403 let Some(Selection::Channel(channel_id)) = state.selection.clone() else {
@@ -21,8 +21,9 @@ use crate::format;
21use crate::local_previews::LocalPreview;
21use crate::local_previews::LocalPreview;
22use crate::notice::truncated;
22use crate::notice::truncated;
23use crate::sidebar_model::{
23use crate::sidebar_model::{
24 AvatarSpec, ChatItem, DELETED_PREVIEW, EMPTY_FOLDER_HINT, Preview, Section, SectionInput,
24 AvatarSpec, ChannelOrderInput, ChatItem, DELETED_PREVIEW, EMPTY_FOLDER_HINT, Preview, Section,
25 SectionKind, any_unread_channel, build_sections, unread_chat_count,
25 SectionInput, SectionKind, Step, any_unread_channel, build_sections, step_id, unread_chat_count,
26 visible_channel_ids,
26};
27};
27use crate::theme;
28use crate::theme;
28
29
@@ -356,6 +357,47 @@ impl SidebarView {
356 }
357 }
357 }
358 }
358
359
360 pub fn show_chats(&mut self, cx: &mut Context<Self>) {
361 self.tab = SidebarTab::Chats;
362 cx.notify();
363 }
364
365 pub fn show_channels(&mut self, cx: &mut Context<Self>) {
366 self.tab = SidebarTab::Channels;
367 cx.notify();
368 }
369
370 pub fn select_adjacent(&mut self, step: Step, cx: &mut Context<Self>) {
371 let selection = match self.tab {
372 SidebarTab::Chats => self
373 .state
374 .read(cx)
375 .adjacent_chat_id(step)
376 .map(Selection::Chat),
377 SidebarTab::Channels => self.adjacent_channel_id(step, cx).map(Selection::Channel),
378 };
379 if let Some(selection) = selection {
380 self.state.update(cx, |state, cx| state.select(selection, cx));
381 }
382 }
383
384 fn adjacent_channel_id(&self, step: Step, cx: &mut Context<Self>) -> Option<String> {
385 let state = self.state.read(cx);
386 let selected_channel = match &state.selection {
387 Some(Selection::Channel(channel_id)) => Some(channel_id.as_str()),
388 _ => None,
389 };
390 let input = ChannelOrderInput {
391 teams: &state.sidebar.teams,
392 pinned_ids: &state.directory.pinned_channels,
393 collapsed_teams: &self.collapsed_teams,
394 revealed_channel_teams: &self.revealed_channel_teams,
395 hidden_teams_open: self.hidden_teams_open,
396 selected_channel,
397 };
398 step_id(&visible_channel_ids(&input), selected_channel, step)
399 }
400
359 fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) {
401 fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) {
360 let state = self.state.read(cx);
402 let state = self.state.read(cx);
361 let Some(Selection::Channel(channel_id)) = state.selection.clone() else {
403 let Some(Selection::Channel(channel_id)) = state.selection.clone() else {