feat(chat): Jump to newest button and Ctrl+J like Teams
- scroller button reads "Jump to newest" with the accent fill, tooltip shows Ctrl+J - Ctrl+J / Cmd+J: from the newest to the last-read line, from anywhere else to the newest, out of a deep-link window back to the live list - no Jump to last read button: Teams only shows it when chats open at the newest, ours open at the unread line Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -19,12 +19,40 @@ pub fn plan_read(window_active: bool, chat_unread: bool, trigger: ReadTrigger) -
19
19
})
20
20
}
21
21
22
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23
pub enum JumpTarget {
24
LastRead(usize),
25
Newest,
26
}
27
28
pub fn jump_target(
29
last_read_index: Option<usize>,
30
top_item: usize,
31
scrolled_up: bool,
32
) -> Option<JumpTarget> {
33
match last_read_index {
34
_ if scrolled_up => Some(JumpTarget::Newest),
35
Some(index) if index < top_item => Some(JumpTarget::LastRead(index)),
36
_ => None,
37
}
38
}
39
22
40
#[cfg(test)]
23
41
mod tests {
24
42
use std::collections::HashMap;
25
43
26
44
use super::*;
27
45
46
#[test]
47
fn jump_goes_to_last_read_from_the_newest_and_to_the_newest_from_anywhere_else() {
48
assert_eq!(jump_target(Some(4), 10, false), Some(JumpTarget::LastRead(4)));
49
assert_eq!(jump_target(Some(4), 2, true), Some(JumpTarget::Newest));
50
assert_eq!(jump_target(Some(4), 3, true), Some(JumpTarget::Newest));
51
assert_eq!(jump_target(None, 3, true), Some(JumpTarget::Newest));
52
assert_eq!(jump_target(Some(4), 4, false), None);
53
assert_eq!(jump_target(None, 0, false), None);
54
}
55
28
56
struct LocalState {
29
57
unread_counts: HashMap<String, u32>,
30
58
unread: bool,
@@ -19,12 +19,40 @@ pub fn plan_read(window_active: bool, chat_unread: bool, trigger: ReadTrigger) -19
})19
})20
}20
}21
21
22
#[derive(Debug, Clone, Copy, PartialEq, Eq)]23
pub enum JumpTarget {24
LastRead(usize),25
Newest,26
}27
28
pub fn jump_target(29
last_read_index: Option<usize>,30
top_item: usize,31
scrolled_up: bool,32
) -> Option<JumpTarget> {33
match last_read_index {34
_ if scrolled_up => Some(JumpTarget::Newest),35
Some(index) if index < top_item => Some(JumpTarget::LastRead(index)),36
_ => None,37
}38
}39
22
#[cfg(test)]40
#[cfg(test)]23
mod tests {41
mod tests {24
use std::collections::HashMap;42
use std::collections::HashMap;25
43
26
use super::*;44
use super::*;27
45
46
#[test]47
fn jump_goes_to_last_read_from_the_newest_and_to_the_newest_from_anywhere_else() {48
assert_eq!(jump_target(Some(4), 10, false), Some(JumpTarget::LastRead(4)));49
assert_eq!(jump_target(Some(4), 2, true), Some(JumpTarget::Newest));50
assert_eq!(jump_target(Some(4), 3, true), Some(JumpTarget::Newest));51
assert_eq!(jump_target(None, 3, true), Some(JumpTarget::Newest));52
assert_eq!(jump_target(Some(4), 4, false), None);53
assert_eq!(jump_target(None, 0, false), None);54
}55
28
struct LocalState {56
struct LocalState {29
unread_counts: HashMap<String, u32>,57
unread_counts: HashMap<String, u32>,30
unread: bool,58
unread: bool,@@ -24,6 +24,7 @@ use teams_core::{
24
24
mod detached;
25
25
mod feed;
26
26
mod pins;
27
mod jump;
27
28
mod proposal;
28
29
mod recap;
29
30
mod receipt_fade;
@@ -3517,6 +3518,15 @@ impl Render for ConversationView {
3517
3518
.child(icon(IconName::Loader, 12., theme::text_muted()))
3518
3519
.child("Loading newer messages")
3519
3520
.into_any_element()
3521
.with_jump_button_label(jump::JUMP_TO_NEWEST_LABEL)
3522
.with_jump_button_renderer(|button| {
3523
button
3524
.label(jump::JUMP_TO_NEWEST_LABEL)
3525
.tooltip(jump::jump_to_newest_tooltip())
3526
.border_0()
3527
.bg(theme::accent())
3528
.text_color(theme::on_accent())
3529
})
3520
3530
}
3521
3531
Some(Row::Start(start)) => {
3522
3532
let state = env.app.read(cx);
@@ -24,6 +24,7 @@ use teams_core::{24
mod detached;24
mod detached;25
mod feed;25
mod feed;26
mod pins;26
mod pins;27
mod jump;27
mod proposal;28
mod proposal;28
mod recap;29
mod recap;29
mod receipt_fade;30
mod receipt_fade;@@ -3517,6 +3518,15 @@ impl Render for ConversationView {3517
.child(icon(IconName::Loader, 12., theme::text_muted()))3518
.child(icon(IconName::Loader, 12., theme::text_muted()))3518
.child("Loading newer messages")3519
.child("Loading newer messages")3519
.into_any_element()3520
.into_any_element()3521
.with_jump_button_label(jump::JUMP_TO_NEWEST_LABEL)3522
.with_jump_button_renderer(|button| {3523
button3524
.label(jump::JUMP_TO_NEWEST_LABEL)3525
.tooltip(jump::jump_to_newest_tooltip())3526
.border_0()3527
.bg(theme::accent())3528
.text_color(theme::on_accent())3529
})3520
}3530
}3521
Some(Row::Start(start)) => {3531
Some(Row::Start(start)) => {3522
let state = env.app.read(cx);3532
let state = env.app.read(cx);@@ -0,0 +1,46 @@
1
use gpui_kit::*;
2
3
use super::ConversationView;
4
use crate::read_state::{JumpTarget, jump_target};
5
use crate::rows::Row;
6
use crate::views::shortcuts::keys_for_label;
7
8
pub(super) const JUMP_TO_NEWEST_LABEL: &str = "Jump to newest";
9
const JUMP_SHORTCUT_LABEL: &str = "Jump to last read or newest message";
10
11
pub(super) fn jump_to_newest_tooltip() -> SharedString {
12
match keys_for_label(JUMP_SHORTCUT_LABEL) {
13
Some(keys) => format!("{JUMP_TO_NEWEST_LABEL} ({keys})").into(),
14
None => JUMP_TO_NEWEST_LABEL.into(),
15
}
16
}
17
18
impl ConversationView {
19
pub fn jump_to_last_read_or_newest(&mut self, cx: &mut Context<Self>) {
20
if self.current.is_none() || self.in_feed() {
21
return;
22
}
23
if self.is_detached() {
24
self.leave_detached(cx);
25
return;
26
}
27
let last_read_index = self
28
.rows
29
.borrow()
30
.iter()
31
.position(|row| matches!(row, Row::Message(message) if message.new_marker));
32
let (top_item, scrolled_up) = {
33
let scroller = self.scroller.read(cx);
34
(scroller.top_item(), scroller.is_scrolled_up())
35
};
36
let Some(target) = jump_target(last_read_index, top_item, scrolled_up) else {
37
return;
38
};
39
self.scroller.update(cx, |scroller, cx| match target {
40
JumpTarget::Newest => scroller.scroll_to_end(cx),
41
JumpTarget::LastRead(index) => {
42
scroller.scroll_to_item(index, cx);
43
}
44
});
45
}
46
}
@@ -0,0 +1,46 @@1
use gpui_kit::*;2
3
use super::ConversationView;4
use crate::read_state::{JumpTarget, jump_target};5
use crate::rows::Row;6
use crate::views::shortcuts::keys_for_label;7
8
pub(super) const JUMP_TO_NEWEST_LABEL: &str = "Jump to newest";9
const JUMP_SHORTCUT_LABEL: &str = "Jump to last read or newest message";10
11
pub(super) fn jump_to_newest_tooltip() -> SharedString {12
match keys_for_label(JUMP_SHORTCUT_LABEL) {13
Some(keys) => format!("{JUMP_TO_NEWEST_LABEL} ({keys})").into(),14
None => JUMP_TO_NEWEST_LABEL.into(),15
}16
}17
18
impl ConversationView {19
pub fn jump_to_last_read_or_newest(&mut self, cx: &mut Context<Self>) {20
if self.current.is_none() || self.in_feed() {21
return;22
}23
if self.is_detached() {24
self.leave_detached(cx);25
return;26
}27
let last_read_index = self28
.rows29
.borrow()30
.iter()31
.position(|row| matches!(row, Row::Message(message) if message.new_marker));32
let (top_item, scrolled_up) = {33
let scroller = self.scroller.read(cx);34
(scroller.top_item(), scroller.is_scrolled_up())35
};36
let Some(target) = jump_target(last_read_index, top_item, scrolled_up) else {37
return;38
};39
self.scroller.update(cx, |scroller, cx| match target {40
JumpTarget::Newest => scroller.scroll_to_end(cx),41
JumpTarget::LastRead(index) => {42
scroller.scroll_to_item(index, cx);43
}44
});45
}46
}@@ -19,7 +19,7 @@ use gpui_kit::prelude::FluentBuilder as _;
19
19
use super::rail::RailView;
20
20
use super::saved_panel::{SavedPanel, SavedPanelEvent};
21
21
use super::shortcuts::{
22
AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, NextConversation, OpenActivity,
22
AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,
23
23
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
24
24
Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
25
25
ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
@@ -1030,6 +1030,14 @@ impl Render for AppShell {
1030
1030
.on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In))
1031
1031
.on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out))
1032
1032
.on_action(zoom_listener::<ZoomShareReset>(&self.state, ZoomStep::Reset))
1033
.on_action(cx.listener(|this, _: &JumpToLastReadOrNewest, _, cx| {
1034
if this.image_viewer.is_some() || this.state.read(cx).viewing_call() {
1035
cx.propagate();
1036
return;
1037
}
1038
this.conversation
1039
.update(cx, |conversation, cx| conversation.jump_to_last_read_or_newest(cx));
1040
}))
1033
1041
.on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
1034
1042
this.close_image_viewer(window, cx);
1035
1043
this.conversation.update(cx, |conversation, cx| {
@@ -19,7 +19,7 @@ use gpui_kit::prelude::FluentBuilder as _;19
use super::rail::RailView;19
use super::rail::RailView;20
use super::saved_panel::{SavedPanel, SavedPanelEvent};20
use super::saved_panel::{SavedPanel, SavedPanelEvent};21
use super::shortcuts::{21
use super::shortcuts::{22
AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, NextConversation, OpenActivity,22
AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,23
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,23
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,24
Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,24
Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,25
ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,25
ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,@@ -1030,6 +1030,14 @@ impl Render for AppShell {1030
.on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In))1030
.on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In))1031
.on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out))1031
.on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out))1032
.on_action(zoom_listener::<ZoomShareReset>(&self.state, ZoomStep::Reset))1032
.on_action(zoom_listener::<ZoomShareReset>(&self.state, ZoomStep::Reset))1033
.on_action(cx.listener(|this, _: &JumpToLastReadOrNewest, _, cx| {1034
if this.image_viewer.is_some() || this.state.read(cx).viewing_call() {1035
cx.propagate();1036
return;1037
}1038
this.conversation1039
.update(cx, |conversation, cx| conversation.jump_to_last_read_or_newest(cx));1040
}))1033
.on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {1041
.on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {1034
this.close_image_viewer(window, cx);1042
this.close_image_viewer(window, cx);1035
this.conversation.update(cx, |conversation, cx| {1043
this.conversation.update(cx, |conversation, cx| {@@ -24,6 +24,7 @@ actions!(
24
24
OpenAgents,
25
25
PreviousConversation,
26
26
NextConversation,
27
JumpToLastReadOrNewest,
27
28
AcceptCall,
28
29
DeclineCall,
29
30
JoinMeetingFromToast,
@@ -116,6 +117,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
116
117
shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
117
118
shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),
118
119
shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),
120
shortcut!(Composer, Global, "Jump to last read or newest message", "ctrl-j", Some("cmd-j"), JumpToLastReadOrNewest),
119
121
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),
120
122
shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),
121
123
shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),
@@ -24,6 +24,7 @@ actions!(24
OpenAgents,24
OpenAgents,25
PreviousConversation,25
PreviousConversation,26
NextConversation,26
NextConversation,27
JumpToLastReadOrNewest,27
AcceptCall,28
AcceptCall,28
DeclineCall,29
DeclineCall,29
JoinMeetingFromToast,30
JoinMeetingFromToast,@@ -116,6 +117,7 @@ pub const SHORTCUTS: &[Shortcut] = &[116
shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),117
shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),117
shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),118
shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),118
shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),119
shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),120
shortcut!(Composer, Global, "Jump to last read or newest message", "ctrl-j", Some("cmd-j"), JumpToLastReadOrNewest),119
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),121
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),120
shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),122
shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),121
shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),123
shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),@@ -67,6 +67,11 @@ impl MessageScrollerState {
67
67
&& !self.list_state.is_scrolled_to_end().unwrap_or(false)
68
68
}
69
69
70
/// Return the index of the row at the top of the viewport.
71
pub fn top_item(&self) -> usize {
72
self.list_state.logical_scroll_top().item_ix
73
}
74
70
75
/// Return whether the list is actively following its tail.
71
76
pub fn is_following_tail(&self) -> bool {
72
77
self.list_state.is_following_tail()
@@ -67,6 +67,11 @@ impl MessageScrollerState {67
&& !self.list_state.is_scrolled_to_end().unwrap_or(false)67
&& !self.list_state.is_scrolled_to_end().unwrap_or(false)68
}68
}69
69
70
/// Return the index of the row at the top of the viewport.71
pub fn top_item(&self) -> usize {72
self.list_state.logical_scroll_top().item_ix73
}74
70
/// Return whether the list is actively following its tail.75
/// Return whether the list is actively following its tail.71
pub fn is_following_tail(&self) -> bool {76
pub fn is_following_tail(&self) -> bool {72
self.list_state.is_following_tail()77
self.list_state.is_following_tail()