Merge remote-tracking branch 'origin/main' into feat/scroll-edge-lines
# Conflicts: # crates/app/src/layout_guard.rs
@@ -8,7 +8,7 @@ macro_rules! symbols {
8
8
};
9
9
}
10
10
11
const SYMBOLS: [(&str, &[u8]); 55] = symbols![
11
const SYMBOLS: [(&str, &[u8]); 59] = symbols![
12
12
"bot",
13
13
"done",
14
14
"table",
@@ -64,6 +64,10 @@ const SYMBOLS: [(&str, &[u8]); 55] = symbols![
64
64
"fluent_share",
65
65
"fluent_clock",
66
66
"fluent_document_text",
67
"fluent_text_edit_style",
68
"fluent_text_edit_style_filled",
69
"fluent_table_add",
70
"fluent_table_dismiss",
67
71
];
68
72
69
73
pub struct AppAssets;
@@ -8,7 +8,7 @@ macro_rules! symbols {8
};8
};9
}9
}10
10
11
const SYMBOLS: [(&str, &[u8]); 55] = symbols![11
const SYMBOLS: [(&str, &[u8]); 59] = symbols![12
"bot",12
"bot",13
"done",13
"done",14
"table",14
"table",@@ -64,6 +64,10 @@ const SYMBOLS: [(&str, &[u8]); 55] = symbols![64
"fluent_share",64
"fluent_share",65
"fluent_clock",65
"fluent_clock",66
"fluent_document_text",66
"fluent_document_text",67
"fluent_text_edit_style",68
"fluent_text_edit_style_filled",69
"fluent_table_add",70
"fluent_table_dismiss",67
];71
];68
72
69
pub struct AppAssets;73
pub struct AppAssets;@@ -216,6 +216,10 @@ pub fn border() -> Hsla {
216
216
color(scheme().border)
217
217
}
218
218
219
pub fn selection() -> Hsla {
220
color_with_alpha(scheme().selection)
221
}
222
219
223
pub fn border_strong() -> Hsla {
220
224
color(scheme().border_strong)
221
225
}
@@ -216,6 +216,10 @@ pub fn border() -> Hsla {216
color(scheme().border)216
color(scheme().border)217
}217
}218
218
219
pub fn selection() -> Hsla {220
color_with_alpha(scheme().selection)221
}222
219
pub fn border_strong() -> Hsla {223
pub fn border_strong() -> Hsla {220
color(scheme().border_strong)224
color(scheme().border_strong)221
}225
}@@ -0,0 +1 @@
1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17 5.5A2.5 2.5 0 0 0 14.5 3h-9A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h4.1c-.16-.32-.3-.65-.4-1H8v-3h1.2c.1-.35.24-.68.4-1H8V8h4v1.6c.32-.16.65-.3 1-.4V8h3v1.2c.35.1.68.24 1 .4V5.5Zm-13 9V13h3v3H5.36A1.5 1.5 0 0 1 4 14.5ZM12 4v3H8V4h4Zm1 0H14.64A1.5 1.5 0 0 1 16 5.5V7h-3V4ZM7 4v3H4V5.36A1.5 1.5 0 0 1 5.5 4H7Zm0 4v4H4V8h3Zm12 6.5a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Zm-4-2a.5.5 0 0 0-1 0V14h-1.5a.5.5 0 0 0 0 1H14v1.5a.5.5 0 0 0 1 0V15h1.5a.5.5 0 0 0 0-1H15v-1.5Z"/></svg>
@@ -0,0 +1 @@1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17 5.5A2.5 2.5 0 0 0 14.5 3h-9A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h4.1c-.16-.32-.3-.65-.4-1H8v-3h1.2c.1-.35.24-.68.4-1H8V8h4v1.6c.32-.16.65-.3 1-.4V8h3v1.2c.35.1.68.24 1 .4V5.5Zm-13 9V13h3v3H5.36A1.5 1.5 0 0 1 4 14.5ZM12 4v3H8V4h4Zm1 0H14.64A1.5 1.5 0 0 1 16 5.5V7h-3V4ZM7 4v3H4V5.36A1.5 1.5 0 0 1 5.5 4H7Zm0 4v4H4V8h3Zm12 6.5a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Zm-4-2a.5.5 0 0 0-1 0V14h-1.5a.5.5 0 0 0 0 1H14v1.5a.5.5 0 0 0 1 0V15h1.5a.5.5 0 0 0 0-1H15v-1.5Z"/></svg>@@ -0,0 +1 @@
1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17 5.5A2.5 2.5 0 0 0 14.5 3h-9A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h4.1c-.16-.32-.3-.65-.4-1H8v-3h1.2c.1-.35.24-.68.4-1H8V8h4v1.6c.32-.16.65-.3 1-.4V8h3v1.2c.35.1.68.24 1 .4V5.5Zm-13 9V13h3v3H5.36A1.5 1.5 0 0 1 4 14.5ZM12 4v3H8V4h4Zm1 0H14.64A1.5 1.5 0 0 1 16 5.5V7h-3V4ZM7 4v3H4V5.36A1.5 1.5 0 0 1 5.5 4H7Zm0 4v4H4V8h3Zm12 6.5a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Zm-3.8 0 1.15-1.15a.5.5 0 0 0-.7-.7l-1.15 1.14-1.15-1.14a.5.5 0 0 0-.7.7l1.14 1.15-1.14 1.15a.5.5 0 0 0 .7.7l1.15-1.14 1.15 1.14a.5.5 0 0 0 .7-.7l-1.14-1.15Z"/></svg>
@@ -0,0 +1 @@1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M17 5.5A2.5 2.5 0 0 0 14.5 3h-9A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h4.1c-.16-.32-.3-.65-.4-1H8v-3h1.2c.1-.35.24-.68.4-1H8V8h4v1.6c.32-.16.65-.3 1-.4V8h3v1.2c.35.1.68.24 1 .4V5.5Zm-13 9V13h3v3H5.36A1.5 1.5 0 0 1 4 14.5ZM12 4v3H8V4h4Zm1 0H14.64A1.5 1.5 0 0 1 16 5.5V7h-3V4ZM7 4v3H4V5.36A1.5 1.5 0 0 1 5.5 4H7Zm0 4v4H4V8h3Zm12 6.5a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Zm-3.8 0 1.15-1.15a.5.5 0 0 0-.7-.7l-1.15 1.14-1.15-1.14a.5.5 0 0 0-.7.7l1.14 1.15-1.14 1.15a.5.5 0 0 0 .7.7l1.15-1.14 1.15 1.14a.5.5 0 0 0 .7-.7l-1.14-1.15Z"/></svg>@@ -0,0 +1 @@
1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M14.09 6.7a2.26 2.26 0 0 1 3.07-.12l.13.12.12.13c.73.85.73 2.1 0 2.96l-.12.13-6.87 6.9a1.5 1.5 0 0 1-.55.35l-.16.05-3.08.76a.5.5 0 0 1-.62-.53l.01-.08.8-3.07c.05-.21.15-.4.28-.57l.1-.12 6.89-6.9Zm2.5.7a1.26 1.26 0 0 0-1.7-.08l-.1.09-6.88 6.9a.5.5 0 0 0-.1.15l-.03.08-.58 2.27 2.27-.56a.5.5 0 0 0 .12-.05l.05-.03.07-.06 6.87-6.9c.5-.5.5-1.3 0-1.8ZM6.41 2.24l.05.08 2.98 7.63-.77.78L8 9H4l-1.03 2.68a.5.5 0 0 1-.56.3l-.1-.02a.5.5 0 0 1-.3-.56l.02-.08 3.5-9a.5.5 0 0 1 .9-.1ZM6 3.87 4.4 8H7.6l-1.6-4.13Z"/></svg>
@@ -0,0 +1 @@1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M14.09 6.7a2.26 2.26 0 0 1 3.07-.12l.13.12.12.13c.73.85.73 2.1 0 2.96l-.12.13-6.87 6.9a1.5 1.5 0 0 1-.55.35l-.16.05-3.08.76a.5.5 0 0 1-.62-.53l.01-.08.8-3.07c.05-.21.15-.4.28-.57l.1-.12 6.89-6.9Zm2.5.7a1.26 1.26 0 0 0-1.7-.08l-.1.09-6.88 6.9a.5.5 0 0 0-.1.15l-.03.08-.58 2.27 2.27-.56a.5.5 0 0 0 .12-.05l.05-.03.07-.06 6.87-6.9c.5-.5.5-1.3 0-1.8ZM6.41 2.24l.05.08 2.98 7.63-.77.78L8 9H4l-1.03 2.68a.5.5 0 0 1-.56.3l-.1-.02a.5.5 0 0 1-.3-.56l.02-.08 3.5-9a.5.5 0 0 1 .9-.1ZM6 3.87 4.4 8H7.6l-1.6-4.13Z"/></svg>@@ -0,0 +1 @@
1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M14.09 6.7a2.26 2.26 0 0 1 3.07-.12l.13.12.12.13c.73.85.73 2.1 0 2.96l-.12.13-6.87 6.9a1.5 1.5 0 0 1-.55.35l-.16.05-3.08.76a.5.5 0 0 1-.62-.53l.01-.08.8-3.07c.05-.21.15-.4.28-.57l.1-.12 6.89-6.9ZM6.42 2.23l.05.08 2.98 7.63-.77.78L8 9H4l-1.03 2.68a.5.5 0 0 1-.56.3l-.1-.02a.5.5 0 0 1-.3-.56l.02-.08 3.5-9a.5.5 0 0 1 .9-.1ZM6 3.87 4.4 8H7.6l-1.6-4.13Z"/></svg>
@@ -0,0 +1 @@1
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M14.09 6.7a2.26 2.26 0 0 1 3.07-.12l.13.12.12.13c.73.85.73 2.1 0 2.96l-.12.13-6.87 6.9a1.5 1.5 0 0 1-.55.35l-.16.05-3.08.76a.5.5 0 0 1-.62-.53l.01-.08.8-3.07c.05-.21.15-.4.28-.57l.1-.12 6.89-6.9ZM6.42 2.23l.05.08 2.98 7.63-.77.78L8 9H4l-1.03 2.68a.5.5 0 0 1-.56.3l-.1-.02a.5.5 0 0 1-.3-.56l.02-.08 3.5-9a.5.5 0 0 1 .9-.1ZM6 3.87 4.4 8H7.6l-1.6-4.13Z"/></svg>@@ -176,7 +176,10 @@ mod frames {
176
176
use crate::user_activity::UserInput;
177
177
use crate::views::call_transcript::TranscriptPanel;
178
178
use crate::views::call_view::CHAT_PANEL_TAG;
179
use crate::views::composer::{COMPOSER_BOX_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG};
179
use crate::views::composer::{
180
COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
181
COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
182
};
180
183
use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON};
181
184
use crate::views::message_row::BUBBLE_TAGS;
182
185
use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};
@@ -1417,6 +1420,54 @@ mod frames {
1417
1420
}
1418
1421
}
1419
1422
1423
#[gpui_kit::test]
1424
fn the_format_bar_divider_runs_edge_to_edge_inside_the_composer(cx: &mut TestAppContext) {
1425
const FORMAT_TAGS: [&str; 6] = [
1426
COMPOSER_BOX_TAG,
1427
COMPOSER_FORMAT_BAR_TAG,
1428
COMPOSER_FORMAT_DIVIDER_TAG,
1429
COMPOSER_LEADING_TAG,
1430
COMPOSER_FORMAT_TAG,
1431
COMPOSER_SEND_TAG,
1432
];
1433
let (handle, _) = mount(cx);
1434
let mut visual = VisualTestContext::from_window(handle, cx);
1435
for (width, height) in SIZES {
1436
visual.simulate_resize(size(px(width), px(height)));
1437
let window = Bounds {
1438
origin: point(px(0.), px(0.)),
1439
size: size(px(width), px(height)),
1440
};
1441
collect(&mut visual, Some(COMPOSER_FORMAT_TAG));
1442
let toggle = visual
1443
.debug_bounds(COMPOSER_FORMAT_TAG)
1444
.expect("format button");
1445
visual.simulate_click(toggle.center(), Default::default());
1446
collect(&mut visual, Some(COMPOSER_FORMAT_DIVIDER_TAG));
1447
let tags: Vec<Tag> = FORMAT_TAGS
1448
.iter()
1449
.filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
1450
.collect();
1451
let found: Vec<String> = violations(&tags, window, &FORMAT_TAGS)
1452
.into_iter()
1453
.map(|(key, message)| format!("format@{width}x{height}:{key}: {message}"))
1454
.collect();
1455
let bar = visual.debug_bounds(COMPOSER_FORMAT_BAR_TAG).expect("bar");
1456
let leading = visual.debug_bounds(COMPOSER_LEADING_TAG).expect("leading");
1457
let toggle = visual
1458
.debug_bounds(COMPOSER_FORMAT_TAG)
1459
.expect("format button");
1460
visual.simulate_click(toggle.center(), Default::default());
1461
collect(&mut visual, None);
1462
assert!(found.is_empty(), "{}", found.join("\n"));
1463
assert!(
1464
bar.bottom() <= leading.top(),
1465
"bar {bar:?} over the buttons {leading:?}"
1466
);
1467
assert!(visual.debug_bounds(COMPOSER_FORMAT_BAR_TAG).is_none());
1468
}
1469
}
1470
1420
1471
#[gpui_kit::test]
1421
1472
fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
1422
1473
let (handle, state) = mount_with(cx, true);
@@ -176,7 +176,10 @@ mod frames {176
use crate::user_activity::UserInput;176
use crate::user_activity::UserInput;177
use crate::views::call_transcript::TranscriptPanel;177
use crate::views::call_transcript::TranscriptPanel;178
use crate::views::call_view::CHAT_PANEL_TAG;178
use crate::views::call_view::CHAT_PANEL_TAG;179
use crate::views::composer::{COMPOSER_BOX_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG};179
use crate::views::composer::{180
COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,181
COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,182
};180
use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON};183
use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON};181
use crate::views::message_row::BUBBLE_TAGS;184
use crate::views::message_row::BUBBLE_TAGS;182
use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};185
use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};@@ -1417,6 +1420,54 @@ mod frames {1417
}1420
}1418
}1421
}1419
1422
1423
#[gpui_kit::test]1424
fn the_format_bar_divider_runs_edge_to_edge_inside_the_composer(cx: &mut TestAppContext) {1425
const FORMAT_TAGS: [&str; 6] = [1426
COMPOSER_BOX_TAG,1427
COMPOSER_FORMAT_BAR_TAG,1428
COMPOSER_FORMAT_DIVIDER_TAG,1429
COMPOSER_LEADING_TAG,1430
COMPOSER_FORMAT_TAG,1431
COMPOSER_SEND_TAG,1432
];1433
let (handle, _) = mount(cx);1434
let mut visual = VisualTestContext::from_window(handle, cx);1435
for (width, height) in SIZES {1436
visual.simulate_resize(size(px(width), px(height)));1437
let window = Bounds {1438
origin: point(px(0.), px(0.)),1439
size: size(px(width), px(height)),1440
};1441
collect(&mut visual, Some(COMPOSER_FORMAT_TAG));1442
let toggle = visual1443
.debug_bounds(COMPOSER_FORMAT_TAG)1444
.expect("format button");1445
visual.simulate_click(toggle.center(), Default::default());1446
collect(&mut visual, Some(COMPOSER_FORMAT_DIVIDER_TAG));1447
let tags: Vec<Tag> = FORMAT_TAGS1448
.iter()1449
.filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))1450
.collect();1451
let found: Vec<String> = violations(&tags, window, &FORMAT_TAGS)1452
.into_iter()1453
.map(|(key, message)| format!("format@{width}x{height}:{key}: {message}"))1454
.collect();1455
let bar = visual.debug_bounds(COMPOSER_FORMAT_BAR_TAG).expect("bar");1456
let leading = visual.debug_bounds(COMPOSER_LEADING_TAG).expect("leading");1457
let toggle = visual1458
.debug_bounds(COMPOSER_FORMAT_TAG)1459
.expect("format button");1460
visual.simulate_click(toggle.center(), Default::default());1461
collect(&mut visual, None);1462
assert!(found.is_empty(), "{}", found.join("\n"));1463
assert!(1464
bar.bottom() <= leading.top(),1465
"bar {bar:?} over the buttons {leading:?}"1466
);1467
assert!(visual.debug_bounds(COMPOSER_FORMAT_BAR_TAG).is_none());1468
}1469
}1470
1420
#[gpui_kit::test]1471
#[gpui_kit::test]1421
fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {1472
fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {1422
let (handle, state) = mount_with(cx, true);1473
let (handle, state) = mount_with(cx, true);@@ -21,7 +21,10 @@ actions!(
21
21
InsertTableColumnRight,
22
22
DeleteTableRow,
23
23
DeleteTableColumn,
24
DeleteTable
24
DeleteTable,
25
ToggleFormatBar,
26
InsertTableLine,
27
RemoveTableLine
25
28
]
26
29
);
27
30
@@ -21,7 +21,10 @@ actions!(21
InsertTableColumnRight,21
InsertTableColumnRight,22
DeleteTableRow,22
DeleteTableRow,23
DeleteTableColumn,23
DeleteTableColumn,24
DeleteTable24
DeleteTable,25
ToggleFormatBar,26
InsertTableLine,27
RemoveTableLine25
]28
]26
);29
);27
30
@@ -35,9 +35,10 @@ mod table;
35
35
36
36
use super::actions::{
37
37
COMPOSER_KEY_CONTEXT, DeleteTable, DeleteTableColumn, DeleteTableRow, EditLink,
38
InsertTableColumnLeft, InsertTableColumnRight, InsertTableRowAbove, InsertTableRowBelow,
39
OpenSwitcher, PastePlainText, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic, ToggleStrike,
40
ToggleSubscript, ToggleSuperscript, ToggleUnderline,
38
InsertTableColumnLeft, InsertTableColumnRight, InsertTableLine, InsertTableRowAbove,
39
InsertTableRowBelow, OpenSwitcher, PastePlainText, RemoveTableLine, ScheduleSend, ToggleBold,
40
ToggleCode, ToggleFormatBar, ToggleItalic, ToggleStrike, ToggleSubscript, ToggleSuperscript,
41
ToggleUnderline,
41
42
};
42
43
use super::attachment_tray::{
43
44
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS, PasteAction, UploadJob,
@@ -47,7 +48,7 @@ use super::attachment_tray::{
47
48
use super::avatar::{person_avatar, square_avatar};
48
49
use super::draft_style::draft_style;
49
50
use super::emoji_popup::{self, EmojiPopup};
50
use super::format_toolbar::{self, FormatButton};
51
use super::format_toolbar::{self, ButtonState, FormatButton};
51
52
use super::fun_picker::{FunPicker, FunPickerEvent};
52
53
use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_join_chip};
53
54
use super::widgets::{icon, symbol};
@@ -59,7 +60,7 @@ use crate::runtime;
59
60
use crate::scheduled_rows::scheduled_label;
60
61
use crate::theme::{self, ElevatedSurface as _};
61
62
use crate::typing::OutgoingTyping;
62
use table::{TableKey, TablePicker, TableViews, is_table_token};
63
use table::{TableKey, TableLineMenu, TableMenu, TablePicker, TableViews, is_table_token};
63
64
64
65
const MIN_ROWS: usize = 1;
65
66
const MAX_ROWS: usize = 8;
@@ -77,6 +78,9 @@ const COMPOSER_BUTTON_INSET: f32 = 6.;
77
78
pub const COMPOSER_BOX_TAG: &str = "composer";
78
79
pub const COMPOSER_LEADING_TAG: &str = "composer/leading";
79
80
pub const COMPOSER_SEND_TAG: &str = "composer/send";
81
pub const COMPOSER_FORMAT_TAG: &str = "composer/leading/format";
82
pub const COMPOSER_FORMAT_BAR_TAG: &str = "composer/format-bar";
83
pub const COMPOSER_FORMAT_DIVIDER_TAG: &str = "composer/format-bar/divider";
80
84
/// gpui-kit draws a `Size::Size` button's icon at this fraction of the button size.
81
85
const BUTTON_ICON_SCALE: f32 = 0.75;
82
86
const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);
@@ -216,6 +220,8 @@ pub struct Composer {
216
220
tables: TableViews,
217
221
table_counter: usize,
218
222
table_picker: Option<TablePicker>,
223
table_menu: Option<TableMenu>,
224
format_bar: HashSet<String>,
219
225
active_cell: Option<(String, teams_core::Cell)>,
220
226
caret_before_table: usize,
221
227
caret_text: String,
@@ -425,6 +431,8 @@ impl Composer {
425
431
tables: TableViews::default(),
426
432
table_counter: 0,
427
433
table_picker: None,
434
table_menu: None,
435
format_bar: HashSet::new(),
428
436
active_cell: None,
429
437
caret_before_table: 0,
430
438
caret_text: String::new(),
@@ -948,14 +956,62 @@ impl Composer {
948
956
FormatButton::Numbered => self.toggle_lines(LineKind::Numbered(0), window, cx),
949
957
FormatButton::Quote => self.toggle_lines(LineKind::Quote, window, cx),
950
958
FormatButton::Table => {
959
self.table_menu = None;
951
960
self.toolbar_dismissed = Some(self.selection(cx));
952
961
self.open_table_picker(cx);
953
962
}
963
FormatButton::TableInsertLine => {
964
self.open_table_menu(TableLineMenu::Insert, window, cx);
965
}
966
FormatButton::TableRemoveLine => {
967
self.open_table_menu(TableLineMenu::Remove, window, cx);
968
}
969
}
970
}
971
972
fn typing_state(&self, cursor: usize, kind: &MarkKind) -> FormatState {
973
let style = self.draft.style_at(cursor);
974
let style = match self.pending_style.as_ref() {
975
Some(pending) if pending.at == cursor => pending.apply(style),
976
_ => style,
977
};
978
if style.iter().any(|active| active.same_format(kind)) {
979
FormatState::On
980
} else {
981
FormatState::Off
954
982
}
955
983
}
956
984
957
985
fn format_state(&self, button: FormatButton, selection: &Range<usize>) -> FormatState {
958
986
let range = selection.clone();
987
let mark = match button {
988
FormatButton::Bold => Some(MarkKind::Bold),
989
FormatButton::Italic => Some(MarkKind::Italic),
990
FormatButton::Underline => Some(MarkKind::Underline),
991
FormatButton::Strike => Some(MarkKind::Strike),
992
FormatButton::Superscript => Some(MarkKind::Superscript),
993
FormatButton::Subscript => Some(MarkKind::Subscript),
994
FormatButton::SizeSmall => Some(MarkKind::Size(SizeStep::Small)),
995
FormatButton::SizeLarge => Some(MarkKind::Size(SizeStep::Large)),
996
FormatButton::Code => Some(MarkKind::Code),
997
FormatButton::Link => Some(MarkKind::Link(String::new())),
998
_ => None,
999
};
1000
if range.is_empty() {
1001
if let Some(kind) = &mark {
1002
return self.typing_state(range.start, kind);
1003
}
1004
if button == FormatButton::SizeNormal {
1005
let sized = [SizeStep::Small, SizeStep::Large].into_iter().any(|step| {
1006
self.typing_state(range.start, &MarkKind::Size(step)) == FormatState::On
1007
});
1008
return if sized {
1009
FormatState::Off
1010
} else {
1011
FormatState::On
1012
};
1013
}
1014
}
959
1015
match button {
960
1016
FormatButton::Bold => self.draft.state(range, &MarkKind::Bold),
961
1017
FormatButton::Italic => self.draft.state(range, &MarkKind::Italic),
@@ -972,7 +1028,67 @@ impl Composer {
972
1028
FormatButton::Numbered => self.draft.line_state(range, &LineKind::Numbered(0)),
973
1029
FormatButton::Quote => self.draft.line_state(range, &LineKind::Quote),
974
1030
FormatButton::Table if self.table_picker.is_some() => FormatState::On,
975
FormatButton::Table => FormatState::Off,
1031
FormatButton::TableInsertLine
1032
if self
1033
.table_menu
1034
.is_some_and(|menu| menu.kind == TableLineMenu::Insert) =>
1035
{
1036
FormatState::On
1037
}
1038
FormatButton::TableRemoveLine
1039
if self
1040
.table_menu
1041
.is_some_and(|menu| menu.kind == TableLineMenu::Remove) =>
1042
{
1043
FormatState::On
1044
}
1045
FormatButton::Table | FormatButton::TableInsertLine | FormatButton::TableRemoveLine => {
1046
FormatState::Off
1047
}
1048
}
1049
}
1050
1051
/// Text formats do not apply inside a table cell; the row and column menus only there.
1052
fn button_state(
1053
&self,
1054
button: FormatButton,
1055
selection: &Range<usize>,
1056
in_table: bool,
1057
) -> ButtonState {
1058
let enabled = match button {
1059
FormatButton::TableInsertLine | FormatButton::TableRemoveLine => in_table,
1060
FormatButton::Table => true,
1061
_ => !in_table,
1062
};
1063
if enabled {
1064
ButtonState::enabled(self.format_state(button, selection))
1065
} else {
1066
ButtonState::disabled()
1067
}
1068
}
1069
1070
pub(super) fn format_bar_open(&self) -> bool {
1071
self.format_bar
1072
.contains(self.conversation_id.as_deref().unwrap_or_default())
1073
}
1074
1075
pub(super) fn set_format_bar(&mut self, open: bool, cx: &mut Context<Self>) {
1076
let key = self.conversation_id.clone().unwrap_or_default();
1077
if open {
1078
self.format_bar.insert(key);
1079
} else {
1080
self.format_bar.remove(&key);
1081
self.table_picker = None;
1082
self.table_menu = None;
1083
}
1084
cx.notify();
1085
}
1086
1087
fn toggle_format_bar(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1088
let open = !self.format_bar_open();
1089
self.set_format_bar(open, cx);
1090
if !self.cell_has_focus(window, cx) {
1091
self.focus(window, cx);
976
1092
}
977
1093
}
978
1094
@@ -1519,6 +1635,8 @@ impl Composer {
1519
1635
self.mention_inputs.clear();
1520
1636
self.close_popup();
1521
1637
self.schedule = None;
1638
self.table_picker = None;
1639
self.table_menu = None;
1522
1640
if !carry {
1523
1641
self.load_stored_draft(conversation_id, window, cx);
1524
1642
}
@@ -2308,7 +2426,8 @@ impl Composer {
2308
2426
2309
2427
fn render_toolbar(&self, focused: bool, cx: &mut Context<Self>) -> Option<AnyElement> {
2310
2428
let composer = cx.entity().downgrade();
2311
if self.link_editor.is_none() && !(focused && self.toolbar_requested(cx)) {
2429
let floating = focused && self.toolbar_requested(cx) && !self.format_bar_open();
2430
if self.link_editor.is_none() && !floating {
2312
2431
return None;
2313
2432
}
2314
2433
let state = self.input.read(cx);
@@ -2349,7 +2468,7 @@ impl Composer {
2349
2468
},
2350
2469
),
2351
2470
None => {
2352
let state_of = |button| self.format_state(button, &range);
2471
let state_of = |button| ButtonState::enabled(self.format_state(button, &range));
2353
2472
format_toolbar::render(
2354
2473
placement,
2355
2474
format_toolbar::Mode::Bar {
@@ -2366,6 +2485,37 @@ impl Composer {
2366
2485
Some(element)
2367
2486
}
2368
2487
2488
fn render_format_bar(&self, window: &Window, cx: &mut Context<Self>) -> AnyElement {
2489
let selection = self.selection(cx);
2490
let in_table = self.in_table(window, cx);
2491
let state_of = |button| self.button_state(button, &selection, in_table);
2492
let composer = cx.weak_entity();
2493
let on_press: format_toolbar::PressHandler = Rc::new(move |button, window, cx| {
2494
composer
2495
.update(cx, |this, cx| this.press_format(button, window, cx))
2496
.ok();
2497
});
2498
let mut overlay = |button| match button {
2499
FormatButton::Table => self.render_table_picker(cx),
2500
FormatButton::TableInsertLine => self.render_table_menu(TableLineMenu::Insert, cx),
2501
FormatButton::TableRemoveLine => self.render_table_menu(TableLineMenu::Remove, cx),
2502
_ => None,
2503
};
2504
let row = format_toolbar::render_format_bar(&state_of, on_press, &mut overlay);
2505
v_flex()
2506
.debug_selector(|| COMPOSER_FORMAT_BAR_TAG.into())
2507
.w_full()
2508
.child(row.w_full().p(px(COMPOSER_BUTTON_INSET)))
2509
.child(
2510
div()
2511
.debug_selector(|| COMPOSER_FORMAT_DIVIDER_TAG.into())
2512
.w_full()
2513
.h(px(1.))
2514
.bg(theme::border()),
2515
)
2516
.into_any_element()
2517
}
2518
2369
2519
fn render_paste_hint(&self) -> Option<Div> {
2370
2520
self.paste_hint.as_ref()?;
2371
2521
Some(
@@ -2579,6 +2729,37 @@ impl Render for Composer {
2579
2729
))
2580
2730
.on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2581
2731
});
2732
let format_open = self.format_bar_open();
2733
let format_toggle = div()
2734
.id("composer-format")
2735
.debug_selector(|| COMPOSER_FORMAT_TAG.into())
2736
.size(px(COMPOSER_BUTTON_SIZE))
2737
.flex_none()
2738
.flex()
2739
.items_center()
2740
.justify_center()
2741
.rounded(px(8.))
2742
.cursor_pointer()
2743
.when(format_open, |button| button.bg(theme::popup_hover()))
2744
.hover(|button| button.bg(theme::popup_hover()))
2745
.tooltip(move |window, cx| {
2746
Tooltip::new(format_toolbar::toggle_tooltip(format_open)).build(window, cx)
2747
})
2748
.child(symbol(
2749
format_toolbar::toggle_symbol(format_open),
2750
COMPOSER_ICON_SIZE,
2751
if format_open {
2752
theme::accent_soft()
2753
} else {
2754
theme::text_muted()
2755
},
2756
))
2757
.on_mouse_down(MouseButton::Left, |_, window, cx| {
2758
window.prevent_default();
2759
cx.stop_propagation();
2760
})
2761
.on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)));
2762
let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2582
2763
let composer = cx.weak_entity();
2583
2764
let tokens_composer = composer.clone();
2584
2765
let input = Textarea::new(&self.input)
@@ -2594,8 +2775,11 @@ impl Render for Composer {
2594
2775
if context.is_block() && is_table_token(context.token()) {
2595
2776
let token_id = context.token().id().to_string();
2596
2777
let width = context.available_width();
2778
let selected = context.is_selected();
2597
2779
if let Some(table) = tokens_composer
2598
.read_with(cx, |this, _| this.render_table_token(&token_id, width))
2780
.read_with(cx, |this, _| {
2781
this.render_table_token(&token_id, width, selected)
2782
})
2599
2783
.ok()
2600
2784
.flatten()
2601
2785
{
@@ -2740,6 +2924,15 @@ impl Render for Composer {
2740
2924
this.edit_table(TableEdit::DeleteTable, window, cx)
2741
2925
}))
2742
2926
.on_action(cx.listener(|this, _: &ScheduleSend, _, cx| this.open_schedule_picker(cx)))
2927
.on_action(cx.listener(|this, _: &ToggleFormatBar, window, cx| {
2928
this.toggle_format_bar(window, cx)
2929
}))
2930
.on_action(cx.listener(|this, _: &InsertTableLine, window, cx| {
2931
this.open_table_menu(TableLineMenu::Insert, window, cx);
2932
}))
2933
.on_action(cx.listener(|this, _: &RemoveTableLine, window, cx| {
2934
this.open_table_menu(TableLineMenu::Remove, window, cx);
2935
}))
2743
2936
.capture_action(cx.listener(|this, _: &Undo, window, cx| {
2744
2937
if this.link_editor.is_none() {
2745
2938
this.step_history(true, window, cx);
@@ -2771,7 +2964,11 @@ impl Render for Composer {
2771
2964
}
2772
2965
}))
2773
2966
.capture_action(cx.listener(|this, _: &MoveUp, window, cx| {
2774
if this.cell_has_focus(window, cx) {
2967
if let Some(menu) = this.table_menu.as_mut() {
2968
menu.step(-1);
2969
cx.notify();
2970
cx.stop_propagation();
2971
} else if this.cell_has_focus(window, cx) {
2775
2972
if this.table_key(TableKey::Up, window, cx) {
2776
2973
cx.stop_propagation();
2777
2974
}
@@ -2788,7 +2985,11 @@ impl Render for Composer {
2788
2985
}
2789
2986
}))
2790
2987
.capture_action(cx.listener(|this, _: &MoveDown, window, cx| {
2791
if this.cell_has_focus(window, cx) {
2988
if let Some(menu) = this.table_menu.as_mut() {
2989
menu.step(1);
2990
cx.notify();
2991
cx.stop_propagation();
2992
} else if this.cell_has_focus(window, cx) {
2792
2993
if this.table_key(TableKey::Down, window, cx) {
2793
2994
cx.stop_propagation();
2794
2995
}
@@ -2812,7 +3013,10 @@ impl Render for Composer {
2812
3013
}
2813
3014
}))
2814
3015
.capture_action(cx.listener(|this, action: &Enter, window, cx| {
2815
if this.cell_has_focus(window, cx) {
3016
if this.table_menu.is_some() {
3017
this.accept_table_menu(None, window, cx);
3018
cx.stop_propagation();
3019
} else if this.cell_has_focus(window, cx) {
2816
3020
} else if this.link_editor.is_some() {
2817
3021
this.apply_link(window, cx);
2818
3022
cx.stop_propagation();
@@ -2864,7 +3068,7 @@ impl Render for Composer {
2864
3068
}
2865
3069
}))
2866
3070
.capture_action(cx.listener(|this, _: &Escape, window, cx| {
2867
if this.table_picker.take().is_some() {
3071
if this.table_picker.take().is_some() || this.table_menu.take().is_some() {
2868
3072
cx.notify();
2869
3073
cx.stop_propagation();
2870
3074
return;
@@ -2879,7 +3083,7 @@ impl Render for Composer {
2879
3083
cx.stop_propagation();
2880
3084
return;
2881
3085
}
2882
if this.toolbar_requested(cx) {
3086
if this.toolbar_requested(cx) && !this.format_bar_open() {
2883
3087
this.toolbar_dismissed = Some(this.selection(cx));
2884
3088
cx.notify();
2885
3089
cx.stop_propagation();
@@ -2910,7 +3114,6 @@ impl Render for Composer {
2910
3114
.children(self.render_emoji_popup(window, cx))
2911
3115
.children(self.render_toolbar(focused, cx))
2912
3116
.children(self.render_schedule(cx))
2913
.children(self.render_table_picker(cx))
2914
3117
.child(
2915
3118
v_flex()
2916
3119
.debug_selector(|| COMPOSER_BOX_TAG.into())
@@ -2932,6 +3135,7 @@ impl Render for Composer {
2932
3135
.absolute()
2933
3136
.size_full(),
2934
3137
)
3138
.children(format_bar)
2935
3139
.children(tray)
2936
3140
.child(
2937
3141
h_flex()
@@ -2944,22 +3148,16 @@ impl Render for Composer {
2944
3148
}
2945
3149
})
2946
3150
.py(px(COMPOSER_BUTTON_INSET))
2947
.pl(px(if can_attach {
2948
COMPOSER_BUTTON_INSET
2949
} else {
2950
12.
2951
}))
2952
.pr(px(COMPOSER_BUTTON_INSET))
2953
.when(can_attach, |row| {
2954
row.child(
2955
h_flex()
2956
.debug_selector(|| COMPOSER_LEADING_TAG.into())
2957
.flex_none()
2958
.gap(px(COMPOSER_BUTTON_INSET))
2959
.children(fun)
2960
.children(attach),
2961
)
2962
})
3151
.px(px(COMPOSER_BUTTON_INSET))
3152
.child(
3153
h_flex()
3154
.debug_selector(|| COMPOSER_LEADING_TAG.into())
3155
.flex_none()
3156
.gap(px(COMPOSER_BUTTON_INSET))
3157
.child(format_toggle)
3158
.children(fun)
3159
.children(attach),
3160
)
2963
3161
.child(
2964
3162
div()
2965
3163
.flex_1()
@@ -4270,6 +4468,148 @@ mod tests {
4270
4468
);
4271
4469
}
4272
4470
4471
fn format_bar_open(typist: &mut Typist<'_>) -> bool {
4472
let composer = typist.composer.clone();
4473
typist.cx.update(|cx| composer.read(cx).format_bar_open())
4474
}
4475
4476
#[gpui_kit::test]
4477
fn ctrl_shift_x_opens_the_format_bar_per_conversation(cx: &mut TestAppContext) {
4478
let mut typist = typist(cx);
4479
let composer = typist.composer.clone();
4480
let open_chat = |typist: &mut Typist<'_>, id: &'static str| {
4481
let composer = composer.clone();
4482
typist.act(|window, cx| {
4483
composer.update(cx, |composer, cx| {
4484
composer.set_conversation(id, "", window, cx);
4485
composer.focus(window, cx);
4486
})
4487
});
4488
};
4489
open_chat(&mut typist, "chat-one");
4490
assert!(!format_bar_open(&mut typist));
4491
typist.press("ctrl-shift-x");
4492
assert!(format_bar_open(&mut typist));
4493
open_chat(&mut typist, "chat-two");
4494
assert!(!format_bar_open(&mut typist));
4495
open_chat(&mut typist, "chat-one");
4496
assert!(format_bar_open(&mut typist));
4497
typist.press("ctrl-shift-x");
4498
assert!(!format_bar_open(&mut typist));
4499
}
4500
4501
#[gpui_kit::test]
4502
fn ctrl_alt_x_strikes_through_now_that_ctrl_shift_x_is_format(cx: &mut TestAppContext) {
4503
let mut typist = typist(cx);
4504
typist.type_text("gone");
4505
typist.press("ctrl-a ctrl-alt-x");
4506
assert_eq!(typist.outgoing().html(), "<s>gone</s>");
4507
assert!(!format_bar_open(&mut typist));
4508
}
4509
4510
#[gpui_kit::test]
4511
fn the_format_bar_shows_the_style_at_the_caret_without_a_selection(
4512
cx: &mut TestAppContext,
4513
) {
4514
use teams_core::FormatState;
4515
4516
use super::super::FormatButton;
4517
4518
let mut typist = typist(cx);
4519
typist.press("ctrl-shift-x ctrl-b");
4520
let composer = typist.composer.clone();
4521
let bold = |typist: &mut Typist<'_>| {
4522
let composer = composer.clone();
4523
typist.cx.update(|cx| {
4524
let composer = composer.read(cx);
4525
let caret = composer.selection(cx);
4526
composer.button_state(FormatButton::Bold, &caret, false)
4527
})
4528
};
4529
assert_eq!(bold(&mut typist).format, FormatState::On);
4530
typist.type_text("x");
4531
assert_eq!(bold(&mut typist).format, FormatState::On);
4532
typist.press("ctrl-b");
4533
assert_eq!(bold(&mut typist).format, FormatState::Off);
4534
assert!(bold(&mut typist).enabled);
4535
}
4536
4537
#[gpui_kit::test]
4538
fn the_format_bar_inserts_a_table_without_a_selection(cx: &mut TestAppContext) {
4539
use super::super::FormatButton;
4540
4541
let mut typist = typist(cx);
4542
typist.press("ctrl-shift-x");
4543
let composer = typist.composer.clone();
4544
typist.act(|window, cx| {
4545
composer.update(cx, |composer, cx| {
4546
composer.press_format(FormatButton::Table, window, cx)
4547
})
4548
});
4549
let picker_open = typist
4550
.cx
4551
.update(|cx| composer.read(cx).table_picker.is_some());
4552
assert!(picker_open);
4553
insert_table(&mut typist, 2, 2);
4554
assert!(typist.draft().lines()[0].is_table());
4555
}
4556
4557
#[gpui_kit::test]
4558
fn ctrl_alt_plus_and_minus_open_the_teams_row_and_column_menus(cx: &mut TestAppContext) {
4559
use super::super::table::TableLineMenu;
4560
4561
let mut typist = typist(cx);
4562
let composer = typist.composer.clone();
4563
let menu = |typist: &mut Typist<'_>| {
4564
let composer = composer.clone();
4565
typist
4566
.cx
4567
.update(|cx| composer.read(cx).table_menu.map(|menu| menu.kind))
4568
};
4569
typist.press("ctrl-alt-=");
4570
assert_eq!(menu(&mut typist), None);
4571
insert_table(&mut typist, 1, 1);
4572
typist.type_text("a");
4573
typist.press("ctrl-alt-=");
4574
assert_eq!(menu(&mut typist), Some(TableLineMenu::Insert));
4575
assert!(format_bar_open(&mut typist));
4576
typist.press("enter");
4577
assert_eq!(menu(&mut typist), None);
4578
let shape = |typist: &mut Typist<'_>| {
4579
let draft = typist.draft();
4580
let table = draft.table(0).expect("table").clone();
4581
(table.row_count(), table.column_count())
4582
};
4583
assert_eq!(shape(&mut typist), (1, 2));
4584
typist.press("ctrl-alt-- enter");
4585
assert_eq!(shape(&mut typist), (1, 1));
4586
typist.press("ctrl-alt-- escape");
4587
assert_eq!(menu(&mut typist), None);
4588
assert_eq!(shape(&mut typist), (1, 1));
4589
}
4590
4591
#[gpui_kit::test]
4592
fn ctrl_a_highlights_a_table_like_selected_text(cx: &mut TestAppContext) {
4593
use gpui_kit::VisualTestContext;
4594
4595
use super::super::table::SELECTED_TABLE_TAG;
4596
4597
let mut typist = typist(cx);
4598
typist.type_text("before");
4599
insert_table(&mut typist, 1, 2);
4600
typist.type_text("a");
4601
typist.press("down");
4602
typist.type_text("after");
4603
let handle = typist.handle;
4604
let mut visual = VisualTestContext::from_window(handle, typist.cx);
4605
visual.update(|window, cx| window.render_frame(cx));
4606
assert!(visual.debug_bounds(SELECTED_TABLE_TAG).is_none());
4607
visual.simulate_keystrokes("ctrl-a");
4608
visual.run_until_parked();
4609
visual.update(|window, cx| window.render_frame(cx));
4610
assert!(visual.debug_bounds(SELECTED_TABLE_TAG).is_some());
4611
}
4612
4273
4613
#[gpui_kit::test]
4274
4614
fn deleting_the_last_column_deletes_the_table(cx: &mut TestAppContext) {
4275
4615
let mut typist = typist(cx);
@@ -35,9 +35,10 @@ mod table;35
35
36
use super::actions::{36
use super::actions::{37
COMPOSER_KEY_CONTEXT, DeleteTable, DeleteTableColumn, DeleteTableRow, EditLink,37
COMPOSER_KEY_CONTEXT, DeleteTable, DeleteTableColumn, DeleteTableRow, EditLink,38
InsertTableColumnLeft, InsertTableColumnRight, InsertTableRowAbove, InsertTableRowBelow,38
InsertTableColumnLeft, InsertTableColumnRight, InsertTableLine, InsertTableRowAbove,39
OpenSwitcher, PastePlainText, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic, ToggleStrike,39
InsertTableRowBelow, OpenSwitcher, PastePlainText, RemoveTableLine, ScheduleSend, ToggleBold,40
ToggleSubscript, ToggleSuperscript, ToggleUnderline,40
ToggleCode, ToggleFormatBar, ToggleItalic, ToggleStrike, ToggleSubscript, ToggleSuperscript,41
ToggleUnderline,41
};42
};42
use super::attachment_tray::{43
use super::attachment_tray::{43
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS, PasteAction, UploadJob,44
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS, PasteAction, UploadJob,@@ -47,7 +48,7 @@ use super::attachment_tray::{47
use super::avatar::{person_avatar, square_avatar};48
use super::avatar::{person_avatar, square_avatar};48
use super::draft_style::draft_style;49
use super::draft_style::draft_style;49
use super::emoji_popup::{self, EmojiPopup};50
use super::emoji_popup::{self, EmojiPopup};50
use super::format_toolbar::{self, FormatButton};51
use super::format_toolbar::{self, ButtonState, FormatButton};51
use super::fun_picker::{FunPicker, FunPickerEvent};52
use super::fun_picker::{FunPicker, FunPickerEvent};52
use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_join_chip};53
use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_join_chip};53
use super::widgets::{icon, symbol};54
use super::widgets::{icon, symbol};@@ -59,7 +60,7 @@ use crate::runtime;59
use crate::scheduled_rows::scheduled_label;60
use crate::scheduled_rows::scheduled_label;60
use crate::theme::{self, ElevatedSurface as _};61
use crate::theme::{self, ElevatedSurface as _};61
use crate::typing::OutgoingTyping;62
use crate::typing::OutgoingTyping;62
use table::{TableKey, TablePicker, TableViews, is_table_token};63
use table::{TableKey, TableLineMenu, TableMenu, TablePicker, TableViews, is_table_token};63
64
64
const MIN_ROWS: usize = 1;65
const MIN_ROWS: usize = 1;65
const MAX_ROWS: usize = 8;66
const MAX_ROWS: usize = 8;@@ -77,6 +78,9 @@ const COMPOSER_BUTTON_INSET: f32 = 6.;77
pub const COMPOSER_BOX_TAG: &str = "composer";78
pub const COMPOSER_BOX_TAG: &str = "composer";78
pub const COMPOSER_LEADING_TAG: &str = "composer/leading";79
pub const COMPOSER_LEADING_TAG: &str = "composer/leading";79
pub const COMPOSER_SEND_TAG: &str = "composer/send";80
pub const COMPOSER_SEND_TAG: &str = "composer/send";81
pub const COMPOSER_FORMAT_TAG: &str = "composer/leading/format";82
pub const COMPOSER_FORMAT_BAR_TAG: &str = "composer/format-bar";83
pub const COMPOSER_FORMAT_DIVIDER_TAG: &str = "composer/format-bar/divider";80
/// gpui-kit draws a `Size::Size` button's icon at this fraction of the button size.84
/// gpui-kit draws a `Size::Size` button's icon at this fraction of the button size.81
const BUTTON_ICON_SCALE: f32 = 0.75;85
const BUTTON_ICON_SCALE: f32 = 0.75;82
const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);86
const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);@@ -216,6 +220,8 @@ pub struct Composer {216
tables: TableViews,220
tables: TableViews,217
table_counter: usize,221
table_counter: usize,218
table_picker: Option<TablePicker>,222
table_picker: Option<TablePicker>,223
table_menu: Option<TableMenu>,224
format_bar: HashSet<String>,219
active_cell: Option<(String, teams_core::Cell)>,225
active_cell: Option<(String, teams_core::Cell)>,220
caret_before_table: usize,226
caret_before_table: usize,221
caret_text: String,227
caret_text: String,@@ -425,6 +431,8 @@ impl Composer {425
tables: TableViews::default(),431
tables: TableViews::default(),426
table_counter: 0,432
table_counter: 0,427
table_picker: None,433
table_picker: None,434
table_menu: None,435
format_bar: HashSet::new(),428
active_cell: None,436
active_cell: None,429
caret_before_table: 0,437
caret_before_table: 0,430
caret_text: String::new(),438
caret_text: String::new(),@@ -948,14 +956,62 @@ impl Composer {948
FormatButton::Numbered => self.toggle_lines(LineKind::Numbered(0), window, cx),956
FormatButton::Numbered => self.toggle_lines(LineKind::Numbered(0), window, cx),949
FormatButton::Quote => self.toggle_lines(LineKind::Quote, window, cx),957
FormatButton::Quote => self.toggle_lines(LineKind::Quote, window, cx),950
FormatButton::Table => {958
FormatButton::Table => {959
self.table_menu = None;951
self.toolbar_dismissed = Some(self.selection(cx));960
self.toolbar_dismissed = Some(self.selection(cx));952
self.open_table_picker(cx);961
self.open_table_picker(cx);953
}962
}963
FormatButton::TableInsertLine => {964
self.open_table_menu(TableLineMenu::Insert, window, cx);965
}966
FormatButton::TableRemoveLine => {967
self.open_table_menu(TableLineMenu::Remove, window, cx);968
}969
}970
}971
972
fn typing_state(&self, cursor: usize, kind: &MarkKind) -> FormatState {973
let style = self.draft.style_at(cursor);974
let style = match self.pending_style.as_ref() {975
Some(pending) if pending.at == cursor => pending.apply(style),976
_ => style,977
};978
if style.iter().any(|active| active.same_format(kind)) {979
FormatState::On980
} else {981
FormatState::Off954
}982
}955
}983
}956
984
957
fn format_state(&self, button: FormatButton, selection: &Range<usize>) -> FormatState {985
fn format_state(&self, button: FormatButton, selection: &Range<usize>) -> FormatState {958
let range = selection.clone();986
let range = selection.clone();987
let mark = match button {988
FormatButton::Bold => Some(MarkKind::Bold),989
FormatButton::Italic => Some(MarkKind::Italic),990
FormatButton::Underline => Some(MarkKind::Underline),991
FormatButton::Strike => Some(MarkKind::Strike),992
FormatButton::Superscript => Some(MarkKind::Superscript),993
FormatButton::Subscript => Some(MarkKind::Subscript),994
FormatButton::SizeSmall => Some(MarkKind::Size(SizeStep::Small)),995
FormatButton::SizeLarge => Some(MarkKind::Size(SizeStep::Large)),996
FormatButton::Code => Some(MarkKind::Code),997
FormatButton::Link => Some(MarkKind::Link(String::new())),998
_ => None,999
};1000
if range.is_empty() {1001
if let Some(kind) = &mark {1002
return self.typing_state(range.start, kind);1003
}1004
if button == FormatButton::SizeNormal {1005
let sized = [SizeStep::Small, SizeStep::Large].into_iter().any(|step| {1006
self.typing_state(range.start, &MarkKind::Size(step)) == FormatState::On1007
});1008
return if sized {1009
FormatState::Off1010
} else {1011
FormatState::On1012
};1013
}1014
}959
match button {1015
match button {960
FormatButton::Bold => self.draft.state(range, &MarkKind::Bold),1016
FormatButton::Bold => self.draft.state(range, &MarkKind::Bold),961
FormatButton::Italic => self.draft.state(range, &MarkKind::Italic),1017
FormatButton::Italic => self.draft.state(range, &MarkKind::Italic),@@ -972,7 +1028,67 @@ impl Composer {972
FormatButton::Numbered => self.draft.line_state(range, &LineKind::Numbered(0)),1028
FormatButton::Numbered => self.draft.line_state(range, &LineKind::Numbered(0)),973
FormatButton::Quote => self.draft.line_state(range, &LineKind::Quote),1029
FormatButton::Quote => self.draft.line_state(range, &LineKind::Quote),974
FormatButton::Table if self.table_picker.is_some() => FormatState::On,1030
FormatButton::Table if self.table_picker.is_some() => FormatState::On,975
FormatButton::Table => FormatState::Off,1031
FormatButton::TableInsertLine1032
if self1033
.table_menu1034
.is_some_and(|menu| menu.kind == TableLineMenu::Insert) =>1035
{1036
FormatState::On1037
}1038
FormatButton::TableRemoveLine1039
if self1040
.table_menu1041
.is_some_and(|menu| menu.kind == TableLineMenu::Remove) =>1042
{1043
FormatState::On1044
}1045
FormatButton::Table | FormatButton::TableInsertLine | FormatButton::TableRemoveLine => {1046
FormatState::Off1047
}1048
}1049
}1050
1051
/// Text formats do not apply inside a table cell; the row and column menus only there.1052
fn button_state(1053
&self,1054
button: FormatButton,1055
selection: &Range<usize>,1056
in_table: bool,1057
) -> ButtonState {1058
let enabled = match button {1059
FormatButton::TableInsertLine | FormatButton::TableRemoveLine => in_table,1060
FormatButton::Table => true,1061
_ => !in_table,1062
};1063
if enabled {1064
ButtonState::enabled(self.format_state(button, selection))1065
} else {1066
ButtonState::disabled()1067
}1068
}1069
1070
pub(super) fn format_bar_open(&self) -> bool {1071
self.format_bar1072
.contains(self.conversation_id.as_deref().unwrap_or_default())1073
}1074
1075
pub(super) fn set_format_bar(&mut self, open: bool, cx: &mut Context<Self>) {1076
let key = self.conversation_id.clone().unwrap_or_default();1077
if open {1078
self.format_bar.insert(key);1079
} else {1080
self.format_bar.remove(&key);1081
self.table_picker = None;1082
self.table_menu = None;1083
}1084
cx.notify();1085
}1086
1087
fn toggle_format_bar(&mut self, window: &mut Window, cx: &mut Context<Self>) {1088
let open = !self.format_bar_open();1089
self.set_format_bar(open, cx);1090
if !self.cell_has_focus(window, cx) {1091
self.focus(window, cx);976
}1092
}977
}1093
}978
1094
@@ -1519,6 +1635,8 @@ impl Composer {1519
self.mention_inputs.clear();1635
self.mention_inputs.clear();1520
self.close_popup();1636
self.close_popup();1521
self.schedule = None;1637
self.schedule = None;1638
self.table_picker = None;1639
self.table_menu = None;1522
if !carry {1640
if !carry {1523
self.load_stored_draft(conversation_id, window, cx);1641
self.load_stored_draft(conversation_id, window, cx);1524
}1642
}@@ -2308,7 +2426,8 @@ impl Composer {2308
2426
2309
fn render_toolbar(&self, focused: bool, cx: &mut Context<Self>) -> Option<AnyElement> {2427
fn render_toolbar(&self, focused: bool, cx: &mut Context<Self>) -> Option<AnyElement> {2310
let composer = cx.entity().downgrade();2428
let composer = cx.entity().downgrade();2311
if self.link_editor.is_none() && !(focused && self.toolbar_requested(cx)) {2429
let floating = focused && self.toolbar_requested(cx) && !self.format_bar_open();2430
if self.link_editor.is_none() && !floating {2312
return None;2431
return None;2313
}2432
}2314
let state = self.input.read(cx);2433
let state = self.input.read(cx);@@ -2349,7 +2468,7 @@ impl Composer {2349
},2468
},2350
),2469
),2351
None => {2470
None => {2352
let state_of = |button| self.format_state(button, &range);2471
let state_of = |button| ButtonState::enabled(self.format_state(button, &range));2353
format_toolbar::render(2472
format_toolbar::render(2354
placement,2473
placement,2355
format_toolbar::Mode::Bar {2474
format_toolbar::Mode::Bar {@@ -2366,6 +2485,37 @@ impl Composer {2366
Some(element)2485
Some(element)2367
}2486
}2368
2487
2488
fn render_format_bar(&self, window: &Window, cx: &mut Context<Self>) -> AnyElement {2489
let selection = self.selection(cx);2490
let in_table = self.in_table(window, cx);2491
let state_of = |button| self.button_state(button, &selection, in_table);2492
let composer = cx.weak_entity();2493
let on_press: format_toolbar::PressHandler = Rc::new(move |button, window, cx| {2494
composer2495
.update(cx, |this, cx| this.press_format(button, window, cx))2496
.ok();2497
});2498
let mut overlay = |button| match button {2499
FormatButton::Table => self.render_table_picker(cx),2500
FormatButton::TableInsertLine => self.render_table_menu(TableLineMenu::Insert, cx),2501
FormatButton::TableRemoveLine => self.render_table_menu(TableLineMenu::Remove, cx),2502
_ => None,2503
};2504
let row = format_toolbar::render_format_bar(&state_of, on_press, &mut overlay);2505
v_flex()2506
.debug_selector(|| COMPOSER_FORMAT_BAR_TAG.into())2507
.w_full()2508
.child(row.w_full().p(px(COMPOSER_BUTTON_INSET)))2509
.child(2510
div()2511
.debug_selector(|| COMPOSER_FORMAT_DIVIDER_TAG.into())2512
.w_full()2513
.h(px(1.))2514
.bg(theme::border()),2515
)2516
.into_any_element()2517
}2518
2369
fn render_paste_hint(&self) -> Option<Div> {2519
fn render_paste_hint(&self) -> Option<Div> {2370
self.paste_hint.as_ref()?;2520
self.paste_hint.as_ref()?;2371
Some(2521
Some(@@ -2579,6 +2729,37 @@ impl Render for Composer {2579
))2729
))2580
.on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))2730
.on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))2581
});2731
});2732
let format_open = self.format_bar_open();2733
let format_toggle = div()2734
.id("composer-format")2735
.debug_selector(|| COMPOSER_FORMAT_TAG.into())2736
.size(px(COMPOSER_BUTTON_SIZE))2737
.flex_none()2738
.flex()2739
.items_center()2740
.justify_center()2741
.rounded(px(8.))2742
.cursor_pointer()2743
.when(format_open, |button| button.bg(theme::popup_hover()))2744
.hover(|button| button.bg(theme::popup_hover()))2745
.tooltip(move |window, cx| {2746
Tooltip::new(format_toolbar::toggle_tooltip(format_open)).build(window, cx)2747
})2748
.child(symbol(2749
format_toolbar::toggle_symbol(format_open),2750
COMPOSER_ICON_SIZE,2751
if format_open {2752
theme::accent_soft()2753
} else {2754
theme::text_muted()2755
},2756
))2757
.on_mouse_down(MouseButton::Left, |_, window, cx| {2758
window.prevent_default();2759
cx.stop_propagation();2760
})2761
.on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)));2762
let format_bar = format_open.then(|| self.render_format_bar(window, cx));2582
let composer = cx.weak_entity();2763
let composer = cx.weak_entity();2583
let tokens_composer = composer.clone();2764
let tokens_composer = composer.clone();2584
let input = Textarea::new(&self.input)2765
let input = Textarea::new(&self.input)@@ -2594,8 +2775,11 @@ impl Render for Composer {2594
if context.is_block() && is_table_token(context.token()) {2775
if context.is_block() && is_table_token(context.token()) {2595
let token_id = context.token().id().to_string();2776
let token_id = context.token().id().to_string();2596
let width = context.available_width();2777
let width = context.available_width();2778
let selected = context.is_selected();2597
if let Some(table) = tokens_composer2779
if let Some(table) = tokens_composer2598
.read_with(cx, |this, _| this.render_table_token(&token_id, width))2780
.read_with(cx, |this, _| {2781
this.render_table_token(&token_id, width, selected)2782
})2599
.ok()2783
.ok()2600
.flatten()2784
.flatten()2601
{2785
{@@ -2740,6 +2924,15 @@ impl Render for Composer {2740
this.edit_table(TableEdit::DeleteTable, window, cx)2924
this.edit_table(TableEdit::DeleteTable, window, cx)2741
}))2925
}))2742
.on_action(cx.listener(|this, _: &ScheduleSend, _, cx| this.open_schedule_picker(cx)))2926
.on_action(cx.listener(|this, _: &ScheduleSend, _, cx| this.open_schedule_picker(cx)))2927
.on_action(cx.listener(|this, _: &ToggleFormatBar, window, cx| {2928
this.toggle_format_bar(window, cx)2929
}))2930
.on_action(cx.listener(|this, _: &InsertTableLine, window, cx| {2931
this.open_table_menu(TableLineMenu::Insert, window, cx);2932
}))2933
.on_action(cx.listener(|this, _: &RemoveTableLine, window, cx| {2934
this.open_table_menu(TableLineMenu::Remove, window, cx);2935
}))2743
.capture_action(cx.listener(|this, _: &Undo, window, cx| {2936
.capture_action(cx.listener(|this, _: &Undo, window, cx| {2744
if this.link_editor.is_none() {2937
if this.link_editor.is_none() {2745
this.step_history(true, window, cx);2938
this.step_history(true, window, cx);@@ -2771,7 +2964,11 @@ impl Render for Composer {2771
}2964
}2772
}))2965
}))2773
.capture_action(cx.listener(|this, _: &MoveUp, window, cx| {2966
.capture_action(cx.listener(|this, _: &MoveUp, window, cx| {2774
if this.cell_has_focus(window, cx) {2967
if let Some(menu) = this.table_menu.as_mut() {2968
menu.step(-1);2969
cx.notify();2970
cx.stop_propagation();2971
} else if this.cell_has_focus(window, cx) {2775
if this.table_key(TableKey::Up, window, cx) {2972
if this.table_key(TableKey::Up, window, cx) {2776
cx.stop_propagation();2973
cx.stop_propagation();2777
}2974
}@@ -2788,7 +2985,11 @@ impl Render for Composer {2788
}2985
}2789
}))2986
}))2790
.capture_action(cx.listener(|this, _: &MoveDown, window, cx| {2987
.capture_action(cx.listener(|this, _: &MoveDown, window, cx| {2791
if this.cell_has_focus(window, cx) {2988
if let Some(menu) = this.table_menu.as_mut() {2989
menu.step(1);2990
cx.notify();2991
cx.stop_propagation();2992
} else if this.cell_has_focus(window, cx) {2792
if this.table_key(TableKey::Down, window, cx) {2993
if this.table_key(TableKey::Down, window, cx) {2793
cx.stop_propagation();2994
cx.stop_propagation();2794
}2995
}@@ -2812,7 +3013,10 @@ impl Render for Composer {2812
}3013
}2813
}))3014
}))2814
.capture_action(cx.listener(|this, action: &Enter, window, cx| {3015
.capture_action(cx.listener(|this, action: &Enter, window, cx| {2815
if this.cell_has_focus(window, cx) {3016
if this.table_menu.is_some() {3017
this.accept_table_menu(None, window, cx);3018
cx.stop_propagation();3019
} else if this.cell_has_focus(window, cx) {2816
} else if this.link_editor.is_some() {3020
} else if this.link_editor.is_some() {2817
this.apply_link(window, cx);3021
this.apply_link(window, cx);2818
cx.stop_propagation();3022
cx.stop_propagation();@@ -2864,7 +3068,7 @@ impl Render for Composer {2864
}3068
}2865
}))3069
}))2866
.capture_action(cx.listener(|this, _: &Escape, window, cx| {3070
.capture_action(cx.listener(|this, _: &Escape, window, cx| {2867
if this.table_picker.take().is_some() {3071
if this.table_picker.take().is_some() || this.table_menu.take().is_some() {2868
cx.notify();3072
cx.notify();2869
cx.stop_propagation();3073
cx.stop_propagation();2870
return;3074
return;@@ -2879,7 +3083,7 @@ impl Render for Composer {2879
cx.stop_propagation();3083
cx.stop_propagation();2880
return;3084
return;2881
}3085
}2882
if this.toolbar_requested(cx) {3086
if this.toolbar_requested(cx) && !this.format_bar_open() {2883
this.toolbar_dismissed = Some(this.selection(cx));3087
this.toolbar_dismissed = Some(this.selection(cx));2884
cx.notify();3088
cx.notify();2885
cx.stop_propagation();3089
cx.stop_propagation();@@ -2910,7 +3114,6 @@ impl Render for Composer {2910
.children(self.render_emoji_popup(window, cx))3114
.children(self.render_emoji_popup(window, cx))2911
.children(self.render_toolbar(focused, cx))3115
.children(self.render_toolbar(focused, cx))2912
.children(self.render_schedule(cx))3116
.children(self.render_schedule(cx))2913
.children(self.render_table_picker(cx))2914
.child(3117
.child(2915
v_flex()3118
v_flex()2916
.debug_selector(|| COMPOSER_BOX_TAG.into())3119
.debug_selector(|| COMPOSER_BOX_TAG.into())@@ -2932,6 +3135,7 @@ impl Render for Composer {2932
.absolute()3135
.absolute()2933
.size_full(),3136
.size_full(),2934
)3137
)3138
.children(format_bar)2935
.children(tray)3139
.children(tray)2936
.child(3140
.child(2937
h_flex()3141
h_flex()@@ -2944,22 +3148,16 @@ impl Render for Composer {2944
}3148
}2945
})3149
})2946
.py(px(COMPOSER_BUTTON_INSET))3150
.py(px(COMPOSER_BUTTON_INSET))2947
.pl(px(if can_attach {3151
.px(px(COMPOSER_BUTTON_INSET))2948
COMPOSER_BUTTON_INSET3152
.child(2949
} else {3153
h_flex()2950
12.3154
.debug_selector(|| COMPOSER_LEADING_TAG.into())2951
}))3155
.flex_none()2952
.pr(px(COMPOSER_BUTTON_INSET))3156
.gap(px(COMPOSER_BUTTON_INSET))2953
.when(can_attach, |row| {3157
.child(format_toggle)2954
row.child(3158
.children(fun)2955
h_flex()3159
.children(attach),2956
.debug_selector(|| COMPOSER_LEADING_TAG.into())3160
)2957
.flex_none()2958
.gap(px(COMPOSER_BUTTON_INSET))2959
.children(fun)2960
.children(attach),2961
)2962
})2963
.child(3161
.child(2964
div()3162
div()2965
.flex_1()3163
.flex_1()@@ -4270,6 +4468,148 @@ mod tests {4270
);4468
);4271
}4469
}4272
4470
4471
fn format_bar_open(typist: &mut Typist<'_>) -> bool {4472
let composer = typist.composer.clone();4473
typist.cx.update(|cx| composer.read(cx).format_bar_open())4474
}4475
4476
#[gpui_kit::test]4477
fn ctrl_shift_x_opens_the_format_bar_per_conversation(cx: &mut TestAppContext) {4478
let mut typist = typist(cx);4479
let composer = typist.composer.clone();4480
let open_chat = |typist: &mut Typist<'_>, id: &'static str| {4481
let composer = composer.clone();4482
typist.act(|window, cx| {4483
composer.update(cx, |composer, cx| {4484
composer.set_conversation(id, "", window, cx);4485
composer.focus(window, cx);4486
})4487
});4488
};4489
open_chat(&mut typist, "chat-one");4490
assert!(!format_bar_open(&mut typist));4491
typist.press("ctrl-shift-x");4492
assert!(format_bar_open(&mut typist));4493
open_chat(&mut typist, "chat-two");4494
assert!(!format_bar_open(&mut typist));4495
open_chat(&mut typist, "chat-one");4496
assert!(format_bar_open(&mut typist));4497
typist.press("ctrl-shift-x");4498
assert!(!format_bar_open(&mut typist));4499
}4500
4501
#[gpui_kit::test]4502
fn ctrl_alt_x_strikes_through_now_that_ctrl_shift_x_is_format(cx: &mut TestAppContext) {4503
let mut typist = typist(cx);4504
typist.type_text("gone");4505
typist.press("ctrl-a ctrl-alt-x");4506
assert_eq!(typist.outgoing().html(), "<s>gone</s>");4507
assert!(!format_bar_open(&mut typist));4508
}4509
4510
#[gpui_kit::test]4511
fn the_format_bar_shows_the_style_at_the_caret_without_a_selection(4512
cx: &mut TestAppContext,4513
) {4514
use teams_core::FormatState;4515
4516
use super::super::FormatButton;4517
4518
let mut typist = typist(cx);4519
typist.press("ctrl-shift-x ctrl-b");4520
let composer = typist.composer.clone();4521
let bold = |typist: &mut Typist<'_>| {4522
let composer = composer.clone();4523
typist.cx.update(|cx| {4524
let composer = composer.read(cx);4525
let caret = composer.selection(cx);4526
composer.button_state(FormatButton::Bold, &caret, false)4527
})4528
};4529
assert_eq!(bold(&mut typist).format, FormatState::On);4530
typist.type_text("x");4531
assert_eq!(bold(&mut typist).format, FormatState::On);4532
typist.press("ctrl-b");4533
assert_eq!(bold(&mut typist).format, FormatState::Off);4534
assert!(bold(&mut typist).enabled);4535
}4536
4537
#[gpui_kit::test]4538
fn the_format_bar_inserts_a_table_without_a_selection(cx: &mut TestAppContext) {4539
use super::super::FormatButton;4540
4541
let mut typist = typist(cx);4542
typist.press("ctrl-shift-x");4543
let composer = typist.composer.clone();4544
typist.act(|window, cx| {4545
composer.update(cx, |composer, cx| {4546
composer.press_format(FormatButton::Table, window, cx)4547
})4548
});4549
let picker_open = typist4550
.cx4551
.update(|cx| composer.read(cx).table_picker.is_some());4552
assert!(picker_open);4553
insert_table(&mut typist, 2, 2);4554
assert!(typist.draft().lines()[0].is_table());4555
}4556
4557
#[gpui_kit::test]4558
fn ctrl_alt_plus_and_minus_open_the_teams_row_and_column_menus(cx: &mut TestAppContext) {4559
use super::super::table::TableLineMenu;4560
4561
let mut typist = typist(cx);4562
let composer = typist.composer.clone();4563
let menu = |typist: &mut Typist<'_>| {4564
let composer = composer.clone();4565
typist4566
.cx4567
.update(|cx| composer.read(cx).table_menu.map(|menu| menu.kind))4568
};4569
typist.press("ctrl-alt-=");4570
assert_eq!(menu(&mut typist), None);4571
insert_table(&mut typist, 1, 1);4572
typist.type_text("a");4573
typist.press("ctrl-alt-=");4574
assert_eq!(menu(&mut typist), Some(TableLineMenu::Insert));4575
assert!(format_bar_open(&mut typist));4576
typist.press("enter");4577
assert_eq!(menu(&mut typist), None);4578
let shape = |typist: &mut Typist<'_>| {4579
let draft = typist.draft();4580
let table = draft.table(0).expect("table").clone();4581
(table.row_count(), table.column_count())4582
};4583
assert_eq!(shape(&mut typist), (1, 2));4584
typist.press("ctrl-alt-- enter");4585
assert_eq!(shape(&mut typist), (1, 1));4586
typist.press("ctrl-alt-- escape");4587
assert_eq!(menu(&mut typist), None);4588
assert_eq!(shape(&mut typist), (1, 1));4589
}4590
4591
#[gpui_kit::test]4592
fn ctrl_a_highlights_a_table_like_selected_text(cx: &mut TestAppContext) {4593
use gpui_kit::VisualTestContext;4594
4595
use super::super::table::SELECTED_TABLE_TAG;4596
4597
let mut typist = typist(cx);4598
typist.type_text("before");4599
insert_table(&mut typist, 1, 2);4600
typist.type_text("a");4601
typist.press("down");4602
typist.type_text("after");4603
let handle = typist.handle;4604
let mut visual = VisualTestContext::from_window(handle, typist.cx);4605
visual.update(|window, cx| window.render_frame(cx));4606
assert!(visual.debug_bounds(SELECTED_TABLE_TAG).is_none());4607
visual.simulate_keystrokes("ctrl-a");4608
visual.run_until_parked();4609
visual.update(|window, cx| window.render_frame(cx));4610
assert!(visual.debug_bounds(SELECTED_TABLE_TAG).is_some());4611
}4612
4273
#[gpui_kit::test]4613
#[gpui_kit::test]4274
fn deleting_the_last_column_deletes_the_table(cx: &mut TestAppContext) {4614
fn deleting_the_last_column_deletes_the_table(cx: &mut TestAppContext) {4275
let mut typist = typist(cx);4615
let mut typist = typist(cx);@@ -6,6 +6,7 @@ use gpui_kit::component::input::{
6
6
};
7
7
use gpui_kit::component::native_menu::NativeMenu;
8
8
use gpui_kit::component::{Sizable as _, h_flex, v_flex};
9
use gpui_kit::prelude::FluentBuilder as _;
9
10
use gpui_kit::*;
10
11
use teams_core::{Cell, PICKER_COLUMNS, PICKER_ROWS, TABLE_MARK, Table, TableEdit};
11
12
@@ -23,6 +24,11 @@ const PICKER_GAP: f32 = 3.;
23
24
const TABLE_MARGIN: f32 = 4.;
24
25
const CELL_PADDING_X: f32 = 2.;
25
26
const CELL_PADDING_Y: f32 = 3.;
27
const MENU_WIDTH: f32 = 200.;
28
const MENU_PADDING: f32 = 4.;
29
const MENU_ROW_PADDING_X: f32 = 10.;
30
const MENU_ROW_PADDING_Y: f32 = 6.;
31
pub(super) const SELECTED_TABLE_TAG: &str = "composer/table-selected";
26
32
27
33
pub(super) struct TableView {
28
34
cells: Vec<Vec<Entity<TextareaState>>>,
@@ -41,6 +47,55 @@ pub(super) struct TablePicker {
41
47
columns: usize,
42
48
}
43
49
50
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51
pub(super) enum TableLineMenu {
52
Insert,
53
Remove,
54
}
55
56
impl TableLineMenu {
57
/// Teams' order: "Insert column or row" and "Delete column, row, or table".
58
pub(super) fn edits(self) -> &'static [TableEdit] {
59
match self {
60
TableLineMenu::Insert => &[
61
TableEdit::InsertColumnRight,
62
TableEdit::InsertColumnLeft,
63
TableEdit::InsertRowAbove,
64
TableEdit::InsertRowBelow,
65
],
66
TableLineMenu::Remove => &[
67
TableEdit::DeleteColumn,
68
TableEdit::DeleteRow,
69
TableEdit::DeleteTable,
70
],
71
}
72
}
73
}
74
75
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76
pub(super) struct TableMenu {
77
pub(super) kind: TableLineMenu,
78
pub(super) highlighted: usize,
79
}
80
81
impl TableMenu {
82
pub(super) fn new(kind: TableLineMenu) -> Self {
83
TableMenu {
84
kind,
85
highlighted: 0,
86
}
87
}
88
89
pub(super) fn step(&mut self, delta: isize) {
90
let count = self.kind.edits().len() as isize;
91
self.highlighted = (self.highlighted as isize + delta).rem_euclid(count) as usize;
92
}
93
94
pub(super) fn chosen(&self) -> TableEdit {
95
self.kind.edits()[self.highlighted]
96
}
97
}
98
44
99
pub(super) fn token(number: usize) -> InlineToken {
45
100
InlineToken::new(format!("{TOKEN_PREFIX}{number}"), TABLE_MARK.to_string()).block()
46
101
}
@@ -480,6 +535,87 @@ impl Composer {
480
535
self.focus_cell(&token_id, Cell::new(row, 0), window, cx);
481
536
}
482
537
538
pub(super) fn in_table(&self, window: &Window, cx: &App) -> bool {
539
self.focused_cell(window, cx).is_some()
540
}
541
542
/// Ctrl+Alt+= and Ctrl+Alt+- or the format bar buttons; only inside a table, like Teams.
543
pub(super) fn open_table_menu(
544
&mut self,
545
kind: TableLineMenu,
546
window: &mut Window,
547
cx: &mut Context<Self>,
548
) -> bool {
549
if !self.in_table(window, cx) {
550
return false;
551
}
552
self.table_picker = None;
553
self.table_menu = Some(TableMenu::new(kind));
554
if !self.format_bar_open() {
555
self.set_format_bar(true, cx);
556
}
557
cx.notify();
558
true
559
}
560
561
pub(super) fn accept_table_menu(
562
&mut self,
563
edit: Option<TableEdit>,
564
window: &mut Window,
565
cx: &mut Context<Self>,
566
) {
567
let Some(menu) = self.table_menu.take() else {
568
return;
569
};
570
self.edit_table(edit.unwrap_or(menu.chosen()), window, cx);
571
}
572
573
pub(super) fn render_table_menu(
574
&self,
575
kind: TableLineMenu,
576
cx: &mut Context<Self>,
577
) -> Option<AnyElement> {
578
let menu = self.table_menu.filter(|menu| menu.kind == kind)?;
579
let rows = kind.edits().iter().enumerate().map(|(index, edit)| {
580
let edit = *edit;
581
div()
582
.id(ElementId::Name(format!("table-menu-{edit:?}").into()))
583
.px(px(MENU_ROW_PADDING_X))
584
.py(px(MENU_ROW_PADDING_Y))
585
.rounded(px(6.))
586
.text_size(px(13.))
587
.text_color(theme::text())
588
.cursor_pointer()
589
.when(index == menu.highlighted, |row| {
590
row.bg(theme::popup_hover())
591
})
592
.hover(|row| row.bg(theme::popup_hover()))
593
.on_mouse_down(MouseButton::Left, |_, window, cx| {
594
window.prevent_default();
595
cx.stop_propagation();
596
})
597
.on_click(cx.listener(move |this, _, window, cx| {
598
this.accept_table_menu(Some(edit), window, cx)
599
}))
600
.child(edit.label())
601
});
602
Some(
603
v_flex()
604
.id("table-line-menu")
605
.min_w(px(MENU_WIDTH))
606
.p(px(MENU_PADDING))
607
.rounded(px(10.))
608
.flyout_surface()
609
.occlude()
610
.on_mouse_down_out(cx.listener(|this, _, _, cx| {
611
this.table_menu = None;
612
cx.notify();
613
}))
614
.children(rows)
615
.into_any_element(),
616
)
617
}
618
483
619
pub(super) fn open_table_picker(&mut self, cx: &mut Context<Self>) {
484
620
self.table_picker = Some(TablePicker {
485
621
rows: 1,
@@ -522,10 +658,6 @@ impl Composer {
522
658
Some(
523
659
v_flex()
524
660
.id("table-picker")
525
.absolute()
526
.bottom(relative(1.))
527
.left_0()
528
.mb(px(6.))
529
661
.p(px(10.))
530
662
.gap(px(8.))
531
663
.rounded(px(10.))
@@ -547,7 +679,14 @@ impl Composer {
547
679
}
548
680
549
681
/// The table token: a grid of cell inputs over the full width, solid lines like Teams.
550
pub(super) fn render_table_token(&self, token_id: &str, width: Pixels) -> Option<AnyElement> {
682
/// The editor leaves a selected token's highlight to the token, so a selection over the
683
/// table tints every cell in the text selection color.
684
pub(super) fn render_table_token(
685
&self,
686
token_id: &str,
687
width: Pixels,
688
selected: bool,
689
) -> Option<AnyElement> {
551
690
let view = self.tables.get(token_id)?;
552
691
let rows = view.cells.iter().map(|inputs| {
553
692
h_flex()
@@ -562,6 +701,7 @@ impl Composer {
562
701
.border_r_1()
563
702
.border_b_1()
564
703
.border_color(theme::border_strong())
704
.when(selected, |cell| cell.bg(theme::selection()))
565
705
.child(
566
706
Textarea::new(input)
567
707
.appearance(false)
@@ -574,6 +714,9 @@ impl Composer {
574
714
Some(
575
715
v_flex()
576
716
.id(ElementId::Name(format!("composer-{token_id}").into()))
717
.when(selected, |table| {
718
table.debug_selector(|| SELECTED_TABLE_TAG.into())
719
})
577
720
.w(width)
578
721
.my(px(TABLE_MARGIN))
579
722
.border_t_1()
@@ -628,3 +771,42 @@ fn edit_action(edit: TableEdit) -> Box<dyn Action> {
628
771
}
629
772
630
773
pub(super) type TableViews = HashMap<String, TableView>;
774
775
#[cfg(test)]
776
mod tests {
777
use teams_core::TableEdit;
778
779
use super::{TableLineMenu, TableMenu};
780
781
#[test]
782
fn the_line_menus_list_teams_entries_in_teams_order() {
783
assert_eq!(
784
TableLineMenu::Insert.edits(),
785
&[
786
TableEdit::InsertColumnRight,
787
TableEdit::InsertColumnLeft,
788
TableEdit::InsertRowAbove,
789
TableEdit::InsertRowBelow
790
]
791
);
792
assert_eq!(
793
TableLineMenu::Remove.edits(),
794
&[
795
TableEdit::DeleteColumn,
796
TableEdit::DeleteRow,
797
TableEdit::DeleteTable
798
]
799
);
800
}
801
802
#[test]
803
fn the_menu_highlight_wraps_both_ways() {
804
let mut menu = TableMenu::new(TableLineMenu::Remove);
805
assert_eq!(menu.chosen(), TableEdit::DeleteColumn);
806
menu.step(-1);
807
assert_eq!(menu.chosen(), TableEdit::DeleteTable);
808
menu.step(1);
809
menu.step(1);
810
assert_eq!(menu.chosen(), TableEdit::DeleteRow);
811
}
812
}
@@ -6,6 +6,7 @@ use gpui_kit::component::input::{6
};6
};7
use gpui_kit::component::native_menu::NativeMenu;7
use gpui_kit::component::native_menu::NativeMenu;8
use gpui_kit::component::{Sizable as _, h_flex, v_flex};8
use gpui_kit::component::{Sizable as _, h_flex, v_flex};9
use gpui_kit::prelude::FluentBuilder as _;9
use gpui_kit::*;10
use gpui_kit::*;10
use teams_core::{Cell, PICKER_COLUMNS, PICKER_ROWS, TABLE_MARK, Table, TableEdit};11
use teams_core::{Cell, PICKER_COLUMNS, PICKER_ROWS, TABLE_MARK, Table, TableEdit};11
12
@@ -23,6 +24,11 @@ const PICKER_GAP: f32 = 3.;23
const TABLE_MARGIN: f32 = 4.;24
const TABLE_MARGIN: f32 = 4.;24
const CELL_PADDING_X: f32 = 2.;25
const CELL_PADDING_X: f32 = 2.;25
const CELL_PADDING_Y: f32 = 3.;26
const CELL_PADDING_Y: f32 = 3.;27
const MENU_WIDTH: f32 = 200.;28
const MENU_PADDING: f32 = 4.;29
const MENU_ROW_PADDING_X: f32 = 10.;30
const MENU_ROW_PADDING_Y: f32 = 6.;31
pub(super) const SELECTED_TABLE_TAG: &str = "composer/table-selected";26
32
27
pub(super) struct TableView {33
pub(super) struct TableView {28
cells: Vec<Vec<Entity<TextareaState>>>,34
cells: Vec<Vec<Entity<TextareaState>>>,@@ -41,6 +47,55 @@ pub(super) struct TablePicker {41
columns: usize,47
columns: usize,42
}48
}43
49
50
#[derive(Debug, Clone, Copy, PartialEq, Eq)]51
pub(super) enum TableLineMenu {52
Insert,53
Remove,54
}55
56
impl TableLineMenu {57
/// Teams' order: "Insert column or row" and "Delete column, row, or table".58
pub(super) fn edits(self) -> &'static [TableEdit] {59
match self {60
TableLineMenu::Insert => &[61
TableEdit::InsertColumnRight,62
TableEdit::InsertColumnLeft,63
TableEdit::InsertRowAbove,64
TableEdit::InsertRowBelow,65
],66
TableLineMenu::Remove => &[67
TableEdit::DeleteColumn,68
TableEdit::DeleteRow,69
TableEdit::DeleteTable,70
],71
}72
}73
}74
75
#[derive(Debug, Clone, Copy, PartialEq, Eq)]76
pub(super) struct TableMenu {77
pub(super) kind: TableLineMenu,78
pub(super) highlighted: usize,79
}80
81
impl TableMenu {82
pub(super) fn new(kind: TableLineMenu) -> Self {83
TableMenu {84
kind,85
highlighted: 0,86
}87
}88
89
pub(super) fn step(&mut self, delta: isize) {90
let count = self.kind.edits().len() as isize;91
self.highlighted = (self.highlighted as isize + delta).rem_euclid(count) as usize;92
}93
94
pub(super) fn chosen(&self) -> TableEdit {95
self.kind.edits()[self.highlighted]96
}97
}98
44
pub(super) fn token(number: usize) -> InlineToken {99
pub(super) fn token(number: usize) -> InlineToken {45
InlineToken::new(format!("{TOKEN_PREFIX}{number}"), TABLE_MARK.to_string()).block()100
InlineToken::new(format!("{TOKEN_PREFIX}{number}"), TABLE_MARK.to_string()).block()46
}101
}@@ -480,6 +535,87 @@ impl Composer {480
self.focus_cell(&token_id, Cell::new(row, 0), window, cx);535
self.focus_cell(&token_id, Cell::new(row, 0), window, cx);481
}536
}482
537
538
pub(super) fn in_table(&self, window: &Window, cx: &App) -> bool {539
self.focused_cell(window, cx).is_some()540
}541
542
/// Ctrl+Alt+= and Ctrl+Alt+- or the format bar buttons; only inside a table, like Teams.543
pub(super) fn open_table_menu(544
&mut self,545
kind: TableLineMenu,546
window: &mut Window,547
cx: &mut Context<Self>,548
) -> bool {549
if !self.in_table(window, cx) {550
return false;551
}552
self.table_picker = None;553
self.table_menu = Some(TableMenu::new(kind));554
if !self.format_bar_open() {555
self.set_format_bar(true, cx);556
}557
cx.notify();558
true559
}560
561
pub(super) fn accept_table_menu(562
&mut self,563
edit: Option<TableEdit>,564
window: &mut Window,565
cx: &mut Context<Self>,566
) {567
let Some(menu) = self.table_menu.take() else {568
return;569
};570
self.edit_table(edit.unwrap_or(menu.chosen()), window, cx);571
}572
573
pub(super) fn render_table_menu(574
&self,575
kind: TableLineMenu,576
cx: &mut Context<Self>,577
) -> Option<AnyElement> {578
let menu = self.table_menu.filter(|menu| menu.kind == kind)?;579
let rows = kind.edits().iter().enumerate().map(|(index, edit)| {580
let edit = *edit;581
div()582
.id(ElementId::Name(format!("table-menu-{edit:?}").into()))583
.px(px(MENU_ROW_PADDING_X))584
.py(px(MENU_ROW_PADDING_Y))585
.rounded(px(6.))586
.text_size(px(13.))587
.text_color(theme::text())588
.cursor_pointer()589
.when(index == menu.highlighted, |row| {590
row.bg(theme::popup_hover())591
})592
.hover(|row| row.bg(theme::popup_hover()))593
.on_mouse_down(MouseButton::Left, |_, window, cx| {594
window.prevent_default();595
cx.stop_propagation();596
})597
.on_click(cx.listener(move |this, _, window, cx| {598
this.accept_table_menu(Some(edit), window, cx)599
}))600
.child(edit.label())601
});602
Some(603
v_flex()604
.id("table-line-menu")605
.min_w(px(MENU_WIDTH))606
.p(px(MENU_PADDING))607
.rounded(px(10.))608
.flyout_surface()609
.occlude()610
.on_mouse_down_out(cx.listener(|this, _, _, cx| {611
this.table_menu = None;612
cx.notify();613
}))614
.children(rows)615
.into_any_element(),616
)617
}618
483
pub(super) fn open_table_picker(&mut self, cx: &mut Context<Self>) {619
pub(super) fn open_table_picker(&mut self, cx: &mut Context<Self>) {484
self.table_picker = Some(TablePicker {620
self.table_picker = Some(TablePicker {485
rows: 1,621
rows: 1,@@ -522,10 +658,6 @@ impl Composer {522
Some(658
Some(523
v_flex()659
v_flex()524
.id("table-picker")660
.id("table-picker")525
.absolute()526
.bottom(relative(1.))527
.left_0()528
.mb(px(6.))529
.p(px(10.))661
.p(px(10.))530
.gap(px(8.))662
.gap(px(8.))531
.rounded(px(10.))663
.rounded(px(10.))@@ -547,7 +679,14 @@ impl Composer {547
}679
}548
680
549
/// The table token: a grid of cell inputs over the full width, solid lines like Teams.681
/// The table token: a grid of cell inputs over the full width, solid lines like Teams.550
pub(super) fn render_table_token(&self, token_id: &str, width: Pixels) -> Option<AnyElement> {682
/// The editor leaves a selected token's highlight to the token, so a selection over the683
/// table tints every cell in the text selection color.684
pub(super) fn render_table_token(685
&self,686
token_id: &str,687
width: Pixels,688
selected: bool,689
) -> Option<AnyElement> {551
let view = self.tables.get(token_id)?;690
let view = self.tables.get(token_id)?;552
let rows = view.cells.iter().map(|inputs| {691
let rows = view.cells.iter().map(|inputs| {553
h_flex()692
h_flex()@@ -562,6 +701,7 @@ impl Composer {562
.border_r_1()701
.border_r_1()563
.border_b_1()702
.border_b_1()564
.border_color(theme::border_strong())703
.border_color(theme::border_strong())704
.when(selected, |cell| cell.bg(theme::selection()))565
.child(705
.child(566
Textarea::new(input)706
Textarea::new(input)567
.appearance(false)707
.appearance(false)@@ -574,6 +714,9 @@ impl Composer {574
Some(714
Some(575
v_flex()715
v_flex()576
.id(ElementId::Name(format!("composer-{token_id}").into()))716
.id(ElementId::Name(format!("composer-{token_id}").into()))717
.when(selected, |table| {718
table.debug_selector(|| SELECTED_TABLE_TAG.into())719
})577
.w(width)720
.w(width)578
.my(px(TABLE_MARGIN))721
.my(px(TABLE_MARGIN))579
.border_t_1()722
.border_t_1()@@ -628,3 +771,42 @@ fn edit_action(edit: TableEdit) -> Box<dyn Action> {628
}771
}629
772
630
pub(super) type TableViews = HashMap<String, TableView>;773
pub(super) type TableViews = HashMap<String, TableView>;774
775
#[cfg(test)]776
mod tests {777
use teams_core::TableEdit;778
779
use super::{TableLineMenu, TableMenu};780
781
#[test]782
fn the_line_menus_list_teams_entries_in_teams_order() {783
assert_eq!(784
TableLineMenu::Insert.edits(),785
&[786
TableEdit::InsertColumnRight,787
TableEdit::InsertColumnLeft,788
TableEdit::InsertRowAbove,789
TableEdit::InsertRowBelow790
]791
);792
assert_eq!(793
TableLineMenu::Remove.edits(),794
&[795
TableEdit::DeleteColumn,796
TableEdit::DeleteRow,797
TableEdit::DeleteTable798
]799
);800
}801
802
#[test]803
fn the_menu_highlight_wraps_both_ways() {804
let mut menu = TableMenu::new(TableLineMenu::Remove);805
assert_eq!(menu.chosen(), TableEdit::DeleteColumn);806
menu.step(-1);807
assert_eq!(menu.chosen(), TableEdit::DeleteTable);808
menu.step(1);809
menu.step(1);810
assert_eq!(menu.chosen(), TableEdit::DeleteRow);811
}812
}@@ -42,8 +42,8 @@ use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPrevi
42
42
use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
43
43
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
44
44
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
45
use super::post_card::render_post;
46
45
use super::pin_banner::{pin_banner_inset, pin_banner_overlay};
46
use super::post_card::render_post;
47
47
use super::profile_card::opens_profile;
48
48
use super::reaction_picker::{PickHandler, ReactionPicker};
49
49
use super::reaction_pills::{ReactionControls, ReactionPopover};
@@ -71,10 +71,9 @@ use crate::read_state::{ReadTrigger, plan_read};
71
71
use crate::rows::{
72
72
Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
73
73
apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
74
forward_sender_ids,
75
has_own_reaction, message_draft, message_text, own_reaction_glyph, place_local_rows,
76
placeholder_rows,
77
reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,
74
forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,
75
place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,
76
thread_list_rows, thread_rows,
78
77
};
79
78
use crate::runtime;
80
79
use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
@@ -3465,6 +3464,7 @@ impl Render for ConversationView {
3465
3464
let pin_banner = self
3466
3465
.render_pin_banner(cx)
3467
3466
.filter(|_| !drafting && !self.shared_active() && !self.recap_active());
3467
let timeline_top_inset = pin_banner_inset(pin_banner.is_some());
3468
3468
let scroller = MessageScroller::new(
3469
3469
"messages",
3470
3470
self.scroller.clone(),
@@ -3568,7 +3568,7 @@ impl Render for ConversationView {
3568
3568
})
3569
3569
})
3570
3570
.with_bottom_fade(background)
3571
.with_top_inset(pin_banner_inset(pin_banner.is_some()));
3571
.with_top_inset(timeline_top_inset);
3572
3572
3573
3573
root = match self.current.as_ref().filter(|_| !drafting) {
3574
3574
Some(current) => {
@@ -3653,7 +3653,7 @@ impl Render for ConversationView {
3653
3653
.relative()
3654
3654
.flex_1()
3655
3655
.min_h_0()
3656
.child(record_bounds(&self.timeline_bounds))
3656
.child(record_bounds(&self.timeline_bounds, timeline_top_inset))
3657
3657
.on_scroll_wheel(
3658
3658
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3659
3659
)
@@ -42,8 +42,8 @@ use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPrevi42
use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};42
use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};43
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};43
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};44
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};44
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};45
use super::post_card::render_post;46
use super::pin_banner::{pin_banner_inset, pin_banner_overlay};45
use super::pin_banner::{pin_banner_inset, pin_banner_overlay};46
use super::post_card::render_post;47
use super::profile_card::opens_profile;47
use super::profile_card::opens_profile;48
use super::reaction_picker::{PickHandler, ReactionPicker};48
use super::reaction_picker::{PickHandler, ReactionPicker};49
use super::reaction_pills::{ReactionControls, ReactionPopover};49
use super::reaction_pills::{ReactionControls, ReactionPopover};@@ -71,10 +71,9 @@ use crate::read_state::{ReadTrigger, plan_read};71
use crate::rows::{71
use crate::rows::{72
Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,72
Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,73
apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,73
apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,74
forward_sender_ids,74
forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,75
has_own_reaction, message_draft, message_text, own_reaction_glyph, place_local_rows,75
place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,76
placeholder_rows,76
thread_list_rows, thread_rows,77
reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,78
};77
};79
use crate::runtime;78
use crate::runtime;80
use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;79
use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;@@ -3465,6 +3464,7 @@ impl Render for ConversationView {3465
let pin_banner = self3464
let pin_banner = self3466
.render_pin_banner(cx)3465
.render_pin_banner(cx)3467
.filter(|_| !drafting && !self.shared_active() && !self.recap_active());3466
.filter(|_| !drafting && !self.shared_active() && !self.recap_active());3467
let timeline_top_inset = pin_banner_inset(pin_banner.is_some());3468
let scroller = MessageScroller::new(3468
let scroller = MessageScroller::new(3469
"messages",3469
"messages",3470
self.scroller.clone(),3470
self.scroller.clone(),@@ -3568,7 +3568,7 @@ impl Render for ConversationView {3568
})3568
})3569
})3569
})3570
.with_bottom_fade(background)3570
.with_bottom_fade(background)3571
.with_top_inset(pin_banner_inset(pin_banner.is_some()));3571
.with_top_inset(timeline_top_inset);3572
3572
3573
root = match self.current.as_ref().filter(|_| !drafting) {3573
root = match self.current.as_ref().filter(|_| !drafting) {3574
Some(current) => {3574
Some(current) => {@@ -3653,7 +3653,7 @@ impl Render for ConversationView {3653
.relative()3653
.relative()3654
.flex_1()3654
.flex_1()3655
.min_h_0()3655
.min_h_0()3656
.child(record_bounds(&self.timeline_bounds))3656
.child(record_bounds(&self.timeline_bounds, timeline_top_inset))3657
.on_scroll_wheel(3657
.on_scroll_wheel(3658
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),3658
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),3659
)3659
)@@ -20,6 +20,7 @@ const ARROW_MARGIN: f32 = 12.;
20
20
const LINK_FIELD_WIDTH: f32 = 240.;
21
21
const APPLY_WIDTH: f32 = 64.;
22
22
const ACTIVE_ALPHA: f32 = 0.22;
23
const DISABLED_OPACITY: f32 = 0.4;
23
24
const SMALL_LETTER: f32 = 11.;
24
25
const NORMAL_LETTER: f32 = 15.;
25
26
const LARGE_LETTER: f32 = 19.;
@@ -43,29 +44,93 @@ pub enum FormatButton {
43
44
Numbered,
44
45
Quote,
45
46
Table,
47
TableInsertLine,
48
TableRemoveLine,
46
49
}
47
50
48
pub const GROUPS: [&[FormatButton]; 6] = [
49
&[
50
FormatButton::Bold,
51
FormatButton::Italic,
52
FormatButton::Underline,
53
FormatButton::Strike,
54
],
55
&[FormatButton::Superscript, FormatButton::Subscript],
56
&[
57
FormatButton::SizeSmall,
58
FormatButton::SizeNormal,
59
FormatButton::SizeLarge,
60
],
61
&[FormatButton::Code, FormatButton::Link],
62
&[
63
FormatButton::Bulleted,
64
FormatButton::Numbered,
65
FormatButton::Quote,
66
],
67
&[FormatButton::Table],
51
const STYLE_GROUP: &[FormatButton] = &[
52
FormatButton::Bold,
53
FormatButton::Italic,
54
FormatButton::Underline,
55
FormatButton::Strike,
68
56
];
57
const SCRIPT_GROUP: &[FormatButton] = &[FormatButton::Superscript, FormatButton::Subscript];
58
const SIZE_GROUP: &[FormatButton] = &[
59
FormatButton::SizeSmall,
60
FormatButton::SizeNormal,
61
FormatButton::SizeLarge,
62
];
63
const INLINE_GROUP: &[FormatButton] = &[FormatButton::Code, FormatButton::Link];
64
const LINE_GROUP: &[FormatButton] = &[
65
FormatButton::Bulleted,
66
FormatButton::Numbered,
67
FormatButton::Quote,
68
];
69
const TABLE_GROUP: &[FormatButton] = &[
70
FormatButton::Table,
71
FormatButton::TableInsertLine,
72
FormatButton::TableRemoveLine,
73
];
74
75
/// The floating bar over a selection: text formats only, tables live in the format bar.
76
pub const SELECTION_GROUPS: [&[FormatButton]; 5] = [
77
STYLE_GROUP,
78
SCRIPT_GROUP,
79
SIZE_GROUP,
80
INLINE_GROUP,
81
LINE_GROUP,
82
];
83
84
/// The format bar the Format button opens, table group second to last like Teams.
85
pub const BAR_GROUPS: [&[FormatButton]; 6] = [
86
STYLE_GROUP,
87
SCRIPT_GROUP,
88
SIZE_GROUP,
89
INLINE_GROUP,
90
TABLE_GROUP,
91
LINE_GROUP,
92
];
93
94
pub const TOGGLE_SHORTCUT: &str = "Ctrl+Shift+X";
95
96
pub fn toggle_tooltip(open: bool) -> String {
97
let label = if open {
98
"Hide Formatting options"
99
} else {
100
"Show Formatting options"
101
};
102
format!("{label} ({TOGGLE_SHORTCUT})")
103
}
104
105
pub fn toggle_symbol(open: bool) -> &'static str {
106
if open {
107
"fluent_text_edit_style_filled"
108
} else {
109
"fluent_text_edit_style"
110
}
111
}
112
113
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
114
pub struct ButtonState {
115
pub format: FormatState,
116
pub enabled: bool,
117
}
118
119
impl ButtonState {
120
pub fn enabled(format: FormatState) -> Self {
121
ButtonState {
122
format,
123
enabled: true,
124
}
125
}
126
127
pub fn disabled() -> Self {
128
ButtonState {
129
format: FormatState::Off,
130
enabled: false,
131
}
132
}
133
}
69
134
70
135
impl FormatButton {
71
136
fn tooltip(self) -> &'static str {
@@ -73,7 +138,7 @@ impl FormatButton {
73
138
FormatButton::Bold => "Bold (Ctrl+B)",
74
139
FormatButton::Italic => "Italic (Ctrl+I)",
75
140
FormatButton::Underline => "Underline (Ctrl+U)",
76
FormatButton::Strike => "Strikethrough (Ctrl+Shift+X)",
141
FormatButton::Strike => "Strikethrough (Ctrl+Alt+X)",
77
142
FormatButton::Superscript => "Superscript (Ctrl+Shift+=)",
78
143
FormatButton::Subscript => "Subscript (Ctrl+=)",
79
144
FormatButton::SizeSmall => "Small text",
@@ -85,6 +150,8 @@ impl FormatButton {
85
150
FormatButton::Numbered => "Numbered list",
86
151
FormatButton::Quote => "Quote",
87
152
FormatButton::Table => "Insert table",
153
FormatButton::TableInsertLine => "Insert column or row (Ctrl+Alt+=)",
154
FormatButton::TableRemoveLine => "Delete column, row, or table (Ctrl+Alt+-)",
88
155
}
89
156
}
90
157
@@ -106,6 +173,12 @@ impl FormatButton {
106
173
FormatButton::Numbered => symbol("format_list_numbered", 18., color).into_any_element(),
107
174
FormatButton::Quote => symbol("format_quote", 18., color).into_any_element(),
108
175
FormatButton::Table => symbol("table", 18., color).into_any_element(),
176
FormatButton::TableInsertLine => {
177
symbol("fluent_table_add", 20., color).into_any_element()
178
}
179
FormatButton::TableRemoveLine => {
180
symbol("fluent_table_dismiss", 20., color).into_any_element()
181
}
109
182
}
110
183
}
111
184
}
@@ -134,9 +207,10 @@ fn sized_letter(size: f32, color: Hsla) -> AnyElement {
134
207
}
135
208
136
209
pub fn bar_width() -> f32 {
137
let buttons: usize = GROUPS.iter().map(|group| group.len()).sum();
138
let gaps: usize = GROUPS.iter().map(|group| group.len() - 1).sum();
139
let separators = (GROUPS.len() - 1) as f32 * (1. + 2. * SEPARATOR_MARGIN);
210
let groups = SELECTION_GROUPS;
211
let buttons: usize = groups.iter().map(|group| group.len()).sum();
212
let gaps: usize = groups.iter().map(|group| group.len() - 1).sum();
213
let separators = (groups.len() - 1) as f32 * (1. + 2. * SEPARATOR_MARGIN);
140
214
2. * PADDING + buttons as f32 * BUTTON + gaps as f32 * BUTTON_GAP + separators
141
215
}
142
216
@@ -172,7 +246,7 @@ pub type ApplyHandler = Rc<dyn Fn(&mut Window, &mut App)>;
172
246
173
247
pub enum Mode<'a> {
174
248
Bar {
175
state: &'a dyn Fn(FormatButton) -> FormatState,
249
state: &'a dyn Fn(FormatButton) -> ButtonState,
176
250
on_press: PressHandler,
177
251
},
178
252
Link {
@@ -182,8 +256,13 @@ pub enum Mode<'a> {
182
256
},
183
257
}
184
258
185
fn button(format: FormatButton, state: FormatState, on_press: PressHandler) -> impl IntoElement {
186
let on = state == FormatState::On;
259
fn button(
260
format: FormatButton,
261
state: ButtonState,
262
on_press: PressHandler,
263
overlay: Option<AnyElement>,
264
) -> impl IntoElement {
265
let on = state.enabled && state.format == FormatState::On;
187
266
let color = if on {
188
267
theme::accent_soft()
189
268
} else {
@@ -198,30 +277,44 @@ fn button(format: FormatButton, state: FormatState, on_press: PressHandler) -> i
198
277
.items_center()
199
278
.justify_center()
200
279
.rounded(px(6.))
201
.cursor_pointer()
202
.when(on, |button| {
203
button.bg(theme::accent().opacity(ACTIVE_ALPHA))
204
})
205
.hover(|button| button.bg(theme::popup_hover()))
206
280
.tooltip(move |window, cx| Tooltip::new(format.tooltip()).build(window, cx))
207
281
.child(format.content(color))
208
.when(state == FormatState::Mixed, |button| {
209
button.child(
210
div()
211
.absolute()
212
.bottom(px(2.))
213
.left(px(7.))
214
.w(px(BUTTON - 16.))
215
.h(px(2.))
216
.rounded(px(1.))
217
.bg(theme::accent()),
218
)
219
})
220
282
.on_mouse_down(MouseButton::Left, |_, window, cx| {
221
283
window.prevent_default();
222
284
cx.stop_propagation();
223
285
})
224
.on_click(move |_, window, cx| on_press(format, window, cx))
286
.when(!state.enabled, |button| button.opacity(DISABLED_OPACITY))
287
.when(state.enabled, |button| {
288
button
289
.cursor_pointer()
290
.when(on, |button| {
291
button.bg(theme::accent().opacity(ACTIVE_ALPHA))
292
})
293
.hover(|button| button.bg(theme::popup_hover()))
294
.when(state.format == FormatState::Mixed, |button| {
295
button.child(
296
div()
297
.absolute()
298
.bottom(px(2.))
299
.left(px(7.))
300
.w(px(BUTTON - 16.))
301
.h(px(2.))
302
.rounded(px(1.))
303
.bg(theme::accent()),
304
)
305
})
306
.on_click(move |_, window, cx| on_press(format, window, cx))
307
})
308
.children(overlay.map(|overlay| {
309
div().absolute().top(px(BUTTON + GAP / 2.)).left_0().child(
310
deferred(
311
anchored()
312
.snap_to_window_with_margin(px(GAP))
313
.child(overlay),
314
)
315
.with_priority(2),
316
)
317
}))
225
318
}
226
319
227
320
fn separator() -> Div {
@@ -232,19 +325,42 @@ fn separator() -> Div {
232
325
.bg(theme::popup_hover())
233
326
}
234
327
235
fn bar(state: &dyn Fn(FormatButton) -> FormatState, on_press: PressHandler) -> Div {
236
let mut row = h_flex().gap(px(BUTTON_GAP)).items_center();
237
for (index, group) in GROUPS.iter().enumerate() {
328
fn groups_row(
329
groups: &[&[FormatButton]],
330
state: &dyn Fn(FormatButton) -> ButtonState,
331
on_press: PressHandler,
332
overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
333
) -> Div {
334
let mut row = h_flex().flex_wrap().gap(px(BUTTON_GAP)).items_center();
335
for (index, group) in groups.iter().enumerate() {
238
336
if index > 0 {
239
337
row = row.child(separator());
240
338
}
241
339
for format in group.iter().copied() {
242
row = row.child(button(format, state(format), on_press.clone()));
340
row = row.child(button(
341
format,
342
state(format),
343
on_press.clone(),
344
overlay(format),
345
));
243
346
}
244
347
}
245
348
row
246
349
}
247
350
351
fn bar(state: &dyn Fn(FormatButton) -> ButtonState, on_press: PressHandler) -> Div {
352
groups_row(&SELECTION_GROUPS, state, on_press, &mut |_| None)
353
}
354
355
/// The format bar inside the composer box. `overlay` hangs a popup under a button.
356
pub fn render_format_bar(
357
state: &dyn Fn(FormatButton) -> ButtonState,
358
on_press: PressHandler,
359
overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
360
) -> Div {
361
groups_row(&BAR_GROUPS, state, on_press, overlay)
362
}
363
248
364
fn link_editor(field: &Entity<InputState>, refused: bool, on_apply: ApplyHandler) -> Div {
249
365
let row = h_flex()
250
366
.gap(px(BUTTON_GAP * 2.))
@@ -357,7 +473,10 @@ pub fn render(placement: Placement, mode: Mode<'_>) -> AnyElement {
357
473
mod tests {
358
474
use gpui_kit::px;
359
475
360
use super::{ARROW_MARGIN, BUTTON, FormatButton, GROUPS, bar_width, place};
476
use super::{
477
ARROW_MARGIN, BAR_GROUPS, BUTTON, FormatButton, SELECTION_GROUPS, bar_width, place,
478
toggle_symbol, toggle_tooltip,
479
};
361
480
362
481
#[test]
363
482
fn the_bar_centers_over_the_selection() {
@@ -385,9 +504,49 @@ mod tests {
385
504
}
386
505
387
506
#[test]
388
fn the_bar_holds_fifteen_buttons_in_six_groups_with_the_table_last() {
389
assert_eq!(GROUPS.iter().map(|group| group.len()).sum::<usize>(), 15);
390
assert_eq!(GROUPS.last().copied(), Some(&[FormatButton::Table][..]));
391
assert!(bar_width() > 15. * BUTTON);
507
fn the_selection_bar_holds_the_text_formats_without_the_table() {
508
assert_eq!(
509
SELECTION_GROUPS
510
.iter()
511
.map(|group| group.len())
512
.sum::<usize>(),
513
14
514
);
515
assert!(
516
SELECTION_GROUPS
517
.iter()
518
.all(|group| !group.contains(&FormatButton::Table))
519
);
520
assert!(bar_width() > 14. * BUTTON);
521
}
522
523
#[test]
524
fn the_format_bar_has_the_teams_table_group_second_to_last() {
525
let table_group = BAR_GROUPS[BAR_GROUPS.len() - 2];
526
assert_eq!(
527
table_group,
528
&[
529
FormatButton::Table,
530
FormatButton::TableInsertLine,
531
FormatButton::TableRemoveLine
532
][..]
533
);
534
for group in SELECTION_GROUPS {
535
assert!(BAR_GROUPS.contains(&group));
536
}
537
}
538
539
#[test]
540
fn the_format_toggle_reads_like_teams() {
541
assert_eq!(
542
toggle_tooltip(false),
543
"Show Formatting options (Ctrl+Shift+X)"
544
);
545
assert_eq!(
546
toggle_tooltip(true),
547
"Hide Formatting options (Ctrl+Shift+X)"
548
);
549
assert_ne!(toggle_symbol(false), toggle_symbol(true));
550
assert_eq!(FormatButton::Strike.tooltip(), "Strikethrough (Ctrl+Alt+X)");
392
551
}
393
552
}
@@ -20,6 +20,7 @@ const ARROW_MARGIN: f32 = 12.;20
const LINK_FIELD_WIDTH: f32 = 240.;20
const LINK_FIELD_WIDTH: f32 = 240.;21
const APPLY_WIDTH: f32 = 64.;21
const APPLY_WIDTH: f32 = 64.;22
const ACTIVE_ALPHA: f32 = 0.22;22
const ACTIVE_ALPHA: f32 = 0.22;23
const DISABLED_OPACITY: f32 = 0.4;23
const SMALL_LETTER: f32 = 11.;24
const SMALL_LETTER: f32 = 11.;24
const NORMAL_LETTER: f32 = 15.;25
const NORMAL_LETTER: f32 = 15.;25
const LARGE_LETTER: f32 = 19.;26
const LARGE_LETTER: f32 = 19.;@@ -43,29 +44,93 @@ pub enum FormatButton {43
Numbered,44
Numbered,44
Quote,45
Quote,45
Table,46
Table,47
TableInsertLine,48
TableRemoveLine,46
}49
}47
50
48
pub const GROUPS: [&[FormatButton]; 6] = [51
const STYLE_GROUP: &[FormatButton] = &[49
&[52
FormatButton::Bold,50
FormatButton::Bold,53
FormatButton::Italic,51
FormatButton::Italic,54
FormatButton::Underline,52
FormatButton::Underline,55
FormatButton::Strike,53
FormatButton::Strike,54
],55
&[FormatButton::Superscript, FormatButton::Subscript],56
&[57
FormatButton::SizeSmall,58
FormatButton::SizeNormal,59
FormatButton::SizeLarge,60
],61
&[FormatButton::Code, FormatButton::Link],62
&[63
FormatButton::Bulleted,64
FormatButton::Numbered,65
FormatButton::Quote,66
],67
&[FormatButton::Table],68
];56
];57
const SCRIPT_GROUP: &[FormatButton] = &[FormatButton::Superscript, FormatButton::Subscript];58
const SIZE_GROUP: &[FormatButton] = &[59
FormatButton::SizeSmall,60
FormatButton::SizeNormal,61
FormatButton::SizeLarge,62
];63
const INLINE_GROUP: &[FormatButton] = &[FormatButton::Code, FormatButton::Link];64
const LINE_GROUP: &[FormatButton] = &[65
FormatButton::Bulleted,66
FormatButton::Numbered,67
FormatButton::Quote,68
];69
const TABLE_GROUP: &[FormatButton] = &[70
FormatButton::Table,71
FormatButton::TableInsertLine,72
FormatButton::TableRemoveLine,73
];74
75
/// The floating bar over a selection: text formats only, tables live in the format bar.76
pub const SELECTION_GROUPS: [&[FormatButton]; 5] = [77
STYLE_GROUP,78
SCRIPT_GROUP,79
SIZE_GROUP,80
INLINE_GROUP,81
LINE_GROUP,82
];83
84
/// The format bar the Format button opens, table group second to last like Teams.85
pub const BAR_GROUPS: [&[FormatButton]; 6] = [86
STYLE_GROUP,87
SCRIPT_GROUP,88
SIZE_GROUP,89
INLINE_GROUP,90
TABLE_GROUP,91
LINE_GROUP,92
];93
94
pub const TOGGLE_SHORTCUT: &str = "Ctrl+Shift+X";95
96
pub fn toggle_tooltip(open: bool) -> String {97
let label = if open {98
"Hide Formatting options"99
} else {100
"Show Formatting options"101
};102
format!("{label} ({TOGGLE_SHORTCUT})")103
}104
105
pub fn toggle_symbol(open: bool) -> &'static str {106
if open {107
"fluent_text_edit_style_filled"108
} else {109
"fluent_text_edit_style"110
}111
}112
113
#[derive(Debug, Clone, Copy, PartialEq, Eq)]114
pub struct ButtonState {115
pub format: FormatState,116
pub enabled: bool,117
}118
119
impl ButtonState {120
pub fn enabled(format: FormatState) -> Self {121
ButtonState {122
format,123
enabled: true,124
}125
}126
127
pub fn disabled() -> Self {128
ButtonState {129
format: FormatState::Off,130
enabled: false,131
}132
}133
}69
134
70
impl FormatButton {135
impl FormatButton {71
fn tooltip(self) -> &'static str {136
fn tooltip(self) -> &'static str {@@ -73,7 +138,7 @@ impl FormatButton {73
FormatButton::Bold => "Bold (Ctrl+B)",138
FormatButton::Bold => "Bold (Ctrl+B)",74
FormatButton::Italic => "Italic (Ctrl+I)",139
FormatButton::Italic => "Italic (Ctrl+I)",75
FormatButton::Underline => "Underline (Ctrl+U)",140
FormatButton::Underline => "Underline (Ctrl+U)",76
FormatButton::Strike => "Strikethrough (Ctrl+Shift+X)",141
FormatButton::Strike => "Strikethrough (Ctrl+Alt+X)",77
FormatButton::Superscript => "Superscript (Ctrl+Shift+=)",142
FormatButton::Superscript => "Superscript (Ctrl+Shift+=)",78
FormatButton::Subscript => "Subscript (Ctrl+=)",143
FormatButton::Subscript => "Subscript (Ctrl+=)",79
FormatButton::SizeSmall => "Small text",144
FormatButton::SizeSmall => "Small text",@@ -85,6 +150,8 @@ impl FormatButton {85
FormatButton::Numbered => "Numbered list",150
FormatButton::Numbered => "Numbered list",86
FormatButton::Quote => "Quote",151
FormatButton::Quote => "Quote",87
FormatButton::Table => "Insert table",152
FormatButton::Table => "Insert table",153
FormatButton::TableInsertLine => "Insert column or row (Ctrl+Alt+=)",154
FormatButton::TableRemoveLine => "Delete column, row, or table (Ctrl+Alt+-)",88
}155
}89
}156
}90
157
@@ -106,6 +173,12 @@ impl FormatButton {106
FormatButton::Numbered => symbol("format_list_numbered", 18., color).into_any_element(),173
FormatButton::Numbered => symbol("format_list_numbered", 18., color).into_any_element(),107
FormatButton::Quote => symbol("format_quote", 18., color).into_any_element(),174
FormatButton::Quote => symbol("format_quote", 18., color).into_any_element(),108
FormatButton::Table => symbol("table", 18., color).into_any_element(),175
FormatButton::Table => symbol("table", 18., color).into_any_element(),176
FormatButton::TableInsertLine => {177
symbol("fluent_table_add", 20., color).into_any_element()178
}179
FormatButton::TableRemoveLine => {180
symbol("fluent_table_dismiss", 20., color).into_any_element()181
}109
}182
}110
}183
}111
}184
}@@ -134,9 +207,10 @@ fn sized_letter(size: f32, color: Hsla) -> AnyElement {134
}207
}135
208
136
pub fn bar_width() -> f32 {209
pub fn bar_width() -> f32 {137
let buttons: usize = GROUPS.iter().map(|group| group.len()).sum();210
let groups = SELECTION_GROUPS;138
let gaps: usize = GROUPS.iter().map(|group| group.len() - 1).sum();211
let buttons: usize = groups.iter().map(|group| group.len()).sum();139
let separators = (GROUPS.len() - 1) as f32 * (1. + 2. * SEPARATOR_MARGIN);212
let gaps: usize = groups.iter().map(|group| group.len() - 1).sum();213
let separators = (groups.len() - 1) as f32 * (1. + 2. * SEPARATOR_MARGIN);140
2. * PADDING + buttons as f32 * BUTTON + gaps as f32 * BUTTON_GAP + separators214
2. * PADDING + buttons as f32 * BUTTON + gaps as f32 * BUTTON_GAP + separators141
}215
}142
216
@@ -172,7 +246,7 @@ pub type ApplyHandler = Rc<dyn Fn(&mut Window, &mut App)>;172
246
173
pub enum Mode<'a> {247
pub enum Mode<'a> {174
Bar {248
Bar {175
state: &'a dyn Fn(FormatButton) -> FormatState,249
state: &'a dyn Fn(FormatButton) -> ButtonState,176
on_press: PressHandler,250
on_press: PressHandler,177
},251
},178
Link {252
Link {@@ -182,8 +256,13 @@ pub enum Mode<'a> {182
},256
},183
}257
}184
258
185
fn button(format: FormatButton, state: FormatState, on_press: PressHandler) -> impl IntoElement {259
fn button(186
let on = state == FormatState::On;260
format: FormatButton,261
state: ButtonState,262
on_press: PressHandler,263
overlay: Option<AnyElement>,264
) -> impl IntoElement {265
let on = state.enabled && state.format == FormatState::On;187
let color = if on {266
let color = if on {188
theme::accent_soft()267
theme::accent_soft()189
} else {268
} else {@@ -198,30 +277,44 @@ fn button(format: FormatButton, state: FormatState, on_press: PressHandler) -> i198
.items_center()277
.items_center()199
.justify_center()278
.justify_center()200
.rounded(px(6.))279
.rounded(px(6.))201
.cursor_pointer()202
.when(on, |button| {203
button.bg(theme::accent().opacity(ACTIVE_ALPHA))204
})205
.hover(|button| button.bg(theme::popup_hover()))206
.tooltip(move |window, cx| Tooltip::new(format.tooltip()).build(window, cx))280
.tooltip(move |window, cx| Tooltip::new(format.tooltip()).build(window, cx))207
.child(format.content(color))281
.child(format.content(color))208
.when(state == FormatState::Mixed, |button| {209
button.child(210
div()211
.absolute()212
.bottom(px(2.))213
.left(px(7.))214
.w(px(BUTTON - 16.))215
.h(px(2.))216
.rounded(px(1.))217
.bg(theme::accent()),218
)219
})220
.on_mouse_down(MouseButton::Left, |_, window, cx| {282
.on_mouse_down(MouseButton::Left, |_, window, cx| {221
window.prevent_default();283
window.prevent_default();222
cx.stop_propagation();284
cx.stop_propagation();223
})285
})224
.on_click(move |_, window, cx| on_press(format, window, cx))286
.when(!state.enabled, |button| button.opacity(DISABLED_OPACITY))287
.when(state.enabled, |button| {288
button289
.cursor_pointer()290
.when(on, |button| {291
button.bg(theme::accent().opacity(ACTIVE_ALPHA))292
})293
.hover(|button| button.bg(theme::popup_hover()))294
.when(state.format == FormatState::Mixed, |button| {295
button.child(296
div()297
.absolute()298
.bottom(px(2.))299
.left(px(7.))300
.w(px(BUTTON - 16.))301
.h(px(2.))302
.rounded(px(1.))303
.bg(theme::accent()),304
)305
})306
.on_click(move |_, window, cx| on_press(format, window, cx))307
})308
.children(overlay.map(|overlay| {309
div().absolute().top(px(BUTTON + GAP / 2.)).left_0().child(310
deferred(311
anchored()312
.snap_to_window_with_margin(px(GAP))313
.child(overlay),314
)315
.with_priority(2),316
)317
}))225
}318
}226
319
227
fn separator() -> Div {320
fn separator() -> Div {@@ -232,19 +325,42 @@ fn separator() -> Div {232
.bg(theme::popup_hover())325
.bg(theme::popup_hover())233
}326
}234
327
235
fn bar(state: &dyn Fn(FormatButton) -> FormatState, on_press: PressHandler) -> Div {328
fn groups_row(236
let mut row = h_flex().gap(px(BUTTON_GAP)).items_center();329
groups: &[&[FormatButton]],237
for (index, group) in GROUPS.iter().enumerate() {330
state: &dyn Fn(FormatButton) -> ButtonState,331
on_press: PressHandler,332
overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,333
) -> Div {334
let mut row = h_flex().flex_wrap().gap(px(BUTTON_GAP)).items_center();335
for (index, group) in groups.iter().enumerate() {238
if index > 0 {336
if index > 0 {239
row = row.child(separator());337
row = row.child(separator());240
}338
}241
for format in group.iter().copied() {339
for format in group.iter().copied() {242
row = row.child(button(format, state(format), on_press.clone()));340
row = row.child(button(341
format,342
state(format),343
on_press.clone(),344
overlay(format),345
));243
}346
}244
}347
}245
row348
row246
}349
}247
350
351
fn bar(state: &dyn Fn(FormatButton) -> ButtonState, on_press: PressHandler) -> Div {352
groups_row(&SELECTION_GROUPS, state, on_press, &mut |_| None)353
}354
355
/// The format bar inside the composer box. `overlay` hangs a popup under a button.356
pub fn render_format_bar(357
state: &dyn Fn(FormatButton) -> ButtonState,358
on_press: PressHandler,359
overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,360
) -> Div {361
groups_row(&BAR_GROUPS, state, on_press, overlay)362
}363
248
fn link_editor(field: &Entity<InputState>, refused: bool, on_apply: ApplyHandler) -> Div {364
fn link_editor(field: &Entity<InputState>, refused: bool, on_apply: ApplyHandler) -> Div {249
let row = h_flex()365
let row = h_flex()250
.gap(px(BUTTON_GAP * 2.))366
.gap(px(BUTTON_GAP * 2.))@@ -357,7 +473,10 @@ pub fn render(placement: Placement, mode: Mode<'_>) -> AnyElement {357
mod tests {473
mod tests {358
use gpui_kit::px;474
use gpui_kit::px;359
475
360
use super::{ARROW_MARGIN, BUTTON, FormatButton, GROUPS, bar_width, place};476
use super::{477
ARROW_MARGIN, BAR_GROUPS, BUTTON, FormatButton, SELECTION_GROUPS, bar_width, place,478
toggle_symbol, toggle_tooltip,479
};361
480
362
#[test]481
#[test]363
fn the_bar_centers_over_the_selection() {482
fn the_bar_centers_over_the_selection() {@@ -385,9 +504,49 @@ mod tests {385
}504
}386
505
387
#[test]506
#[test]388
fn the_bar_holds_fifteen_buttons_in_six_groups_with_the_table_last() {507
fn the_selection_bar_holds_the_text_formats_without_the_table() {389
assert_eq!(GROUPS.iter().map(|group| group.len()).sum::<usize>(), 15);508
assert_eq!(390
assert_eq!(GROUPS.last().copied(), Some(&[FormatButton::Table][..]));509
SELECTION_GROUPS391
assert!(bar_width() > 15. * BUTTON);510
.iter()511
.map(|group| group.len())512
.sum::<usize>(),513
14514
);515
assert!(516
SELECTION_GROUPS517
.iter()518
.all(|group| !group.contains(&FormatButton::Table))519
);520
assert!(bar_width() > 14. * BUTTON);521
}522
523
#[test]524
fn the_format_bar_has_the_teams_table_group_second_to_last() {525
let table_group = BAR_GROUPS[BAR_GROUPS.len() - 2];526
assert_eq!(527
table_group,528
&[529
FormatButton::Table,530
FormatButton::TableInsertLine,531
FormatButton::TableRemoveLine532
][..]533
);534
for group in SELECTION_GROUPS {535
assert!(BAR_GROUPS.contains(&group));536
}537
}538
539
#[test]540
fn the_format_toggle_reads_like_teams() {541
assert_eq!(542
toggle_tooltip(false),543
"Show Formatting options (Ctrl+Shift+X)"544
);545
assert_eq!(546
toggle_tooltip(true),547
"Hide Formatting options (Ctrl+Shift+X)"548
);549
assert_ne!(toggle_symbol(false), toggle_symbol(true));550
assert_eq!(FormatButton::Strike.tooltip(), "Strikethrough (Ctrl+Alt+X)");392
}551
}393
}552
}@@ -893,11 +893,15 @@ impl Render for AppShell {
893
893
let title_bar = render_title_bar(
894
894
crate::active_appearance::current(cx).app_icon,
895
895
mode_label(state.mode),
896
update_button(
897
&self.update,
898
cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
899
),
900
own_status_button(&self.state, state),
896
[
897
update_button(
898
&self.update,
899
cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
900
),
901
own_status_button(&self.state, state),
902
]
903
.into_iter()
904
.flatten(),
901
905
cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
902
906
);
903
907
div()
@@ -893,11 +893,15 @@ impl Render for AppShell {893
let title_bar = render_title_bar(893
let title_bar = render_title_bar(894
crate::active_appearance::current(cx).app_icon,894
crate::active_appearance::current(cx).app_icon,895
mode_label(state.mode),895
mode_label(state.mode),896
update_button(896
[897
&self.update,897
update_button(898
cx.listener(|this, _, _, cx| this.restart_into_update(cx)),898
&self.update,899
),899
cx.listener(|this, _, _, cx| this.restart_into_update(cx)),900
own_status_button(&self.state, state),900
),901
own_status_button(&self.state, state),902
]903
.into_iter()904
.flatten(),901
cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),905
cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),902
);906
);903
div()907
div()@@ -1,15 +1,17 @@
1
1
use gpui_kit::*;
2
2
3
3
use super::actions::{
4
COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, NewChat, OpenSwitcher, PastePlainText,
5
ReplyToHovered, ScheduleSend, ToggleBold, ToggleCallMute, ToggleCode, ToggleItalic,
6
ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,
4
COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, InsertTableLine, NewChat, OpenSwitcher,
5
PastePlainText, RemoveTableLine, ReplyToHovered, ScheduleSend, ToggleBold, ToggleCallMute,
6
ToggleCode, ToggleFormatBar, ToggleItalic, ToggleStrike, ToggleSubscript, ToggleSuperscript,
7
ToggleUnderline,
7
8
};
8
9
9
10
const TEXT_FIELD_CONTEXT: &str = "Input";
10
11
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
11
12
const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";
12
const ALTERNATE_KEYS: &[(&str, &str)] = &[("alt-shift-=", "alt-shift-+")];
13
const ALTERNATE_KEYS: &[(&str, &str)] =
14
&[("alt-shift-=", "alt-shift-+"), ("ctrl-alt-=", "ctrl-alt-+")];
13
15
14
16
actions!(
15
17
teams,
@@ -117,13 +119,16 @@ pub const SHORTCUTS: &[Shortcut] = &[
117
119
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),
118
120
shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),
119
121
shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),
120
shortcut!(Composer, Composer, "Strikethrough", "ctrl-shift-x", None, ToggleStrike),
122
shortcut!(Composer, Composer, "Format", "ctrl-shift-x", Some("cmd-shift-x"), ToggleFormatBar),
123
shortcut!(Composer, Composer, "Strikethrough", "ctrl-alt-x", None, ToggleStrike),
121
124
shortcut!(Composer, Composer, "Superscript", "ctrl-shift-=", None, ToggleSuperscript),
122
125
shortcut!(Composer, Composer, "Subscript", "ctrl-=", None, ToggleSubscript),
123
126
shortcut!(Composer, Composer, "Code", "ctrl-shift-c", None, ToggleCode),
124
127
shortcut!(Composer, Composer, "Insert link", "ctrl-k", Some("cmd-k"), EditLink),
125
128
shortcut!(Composer, Composer, "Paste as plain text", "ctrl-shift-v", Some("cmd-shift-v"), PastePlainText),
126
129
shortcut!(Composer, Composer, "Schedule send", "ctrl-shift-enter", None, ScheduleSend),
130
shortcut!(Composer, Composer, "Insert column or row", "ctrl-alt-=", None, InsertTableLine),
131
shortcut!(Composer, Composer, "Delete column, row, or table", "ctrl-alt--", None, RemoveTableLine),
127
132
shortcut!(Calls, GlobalOverTextFields, "Accept incoming call", "ctrl-shift-a", Some("cmd-shift-a"), AcceptCall),
128
133
shortcut!(Calls, GlobalOverTextFields, "Decline incoming call", "ctrl-shift-d", Some("cmd-shift-d"), DeclineCall),
129
134
shortcut!(Calls, GlobalOverTextFields, "Join the meeting from its reminder", "ctrl-shift-j", Some("cmd-shift-j"), JoinMeetingFromToast),
@@ -348,5 +353,33 @@ mod tests {
348
353
assert_eq!(display_keys("alt-shift-="), "Alt+Shift+Plus");
349
354
assert_eq!(display_keys("alt-shift--"), "Alt+Shift+Minus");
350
355
assert_eq!(display_keys("alt-shift-0"), "Alt+Shift+0");
356
assert_eq!(display_keys("ctrl-alt--"), "Ctrl+Alt+Minus");
357
}
358
359
#[gpui_kit::test]
360
fn composer_format_and_table_keys_match_teams(cx: &mut TestAppContext) {
361
registered(cx);
362
let typing = ["AppShell", "Composer", "Input"];
363
let action_of = |label: &str| {
364
action_name(
365
SHORTCUTS
366
.iter()
367
.find(|shortcut| shortcut.label == label)
368
.unwrap(),
369
)
370
};
371
for (keys, label) in [
372
("ctrl-shift-x", "Format"),
373
("ctrl-alt-x", "Strikethrough"),
374
("ctrl-alt-=", "Insert column or row"),
375
("ctrl-alt-+", "Insert column or row"),
376
("ctrl-alt--", "Delete column, row, or table"),
377
] {
378
assert_eq!(
379
bound_action(cx, keys, &typing),
380
Some(action_of(label)),
381
"{keys}"
382
);
383
}
351
384
}
352
385
}
@@ -1,15 +1,17 @@1
use gpui_kit::*;1
use gpui_kit::*;2
2
3
use super::actions::{3
use super::actions::{4
COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, NewChat, OpenSwitcher, PastePlainText,4
COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, InsertTableLine, NewChat, OpenSwitcher,5
ReplyToHovered, ScheduleSend, ToggleBold, ToggleCallMute, ToggleCode, ToggleItalic,5
PastePlainText, RemoveTableLine, ReplyToHovered, ScheduleSend, ToggleBold, ToggleCallMute,6
ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,6
ToggleCode, ToggleFormatBar, ToggleItalic, ToggleStrike, ToggleSubscript, ToggleSuperscript,7
ToggleUnderline,7
};8
};8
9
9
const TEXT_FIELD_CONTEXT: &str = "Input";10
const TEXT_FIELD_CONTEXT: &str = "Input";10
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";11
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";11
const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";12
const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";12
const ALTERNATE_KEYS: &[(&str, &str)] = &[("alt-shift-=", "alt-shift-+")];13
const ALTERNATE_KEYS: &[(&str, &str)] =14
&[("alt-shift-=", "alt-shift-+"), ("ctrl-alt-=", "ctrl-alt-+")];13
15
14
actions!(16
actions!(15
teams,17
teams,@@ -117,13 +119,16 @@ pub const SHORTCUTS: &[Shortcut] = &[117
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),119
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),118
shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),120
shortcut!(Composer, Composer, "Italic", "ctrl-i", Some("cmd-i"), ToggleItalic),119
shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),121
shortcut!(Composer, Composer, "Underline", "ctrl-u", Some("cmd-u"), ToggleUnderline),120
shortcut!(Composer, Composer, "Strikethrough", "ctrl-shift-x", None, ToggleStrike),122
shortcut!(Composer, Composer, "Format", "ctrl-shift-x", Some("cmd-shift-x"), ToggleFormatBar),123
shortcut!(Composer, Composer, "Strikethrough", "ctrl-alt-x", None, ToggleStrike),121
shortcut!(Composer, Composer, "Superscript", "ctrl-shift-=", None, ToggleSuperscript),124
shortcut!(Composer, Composer, "Superscript", "ctrl-shift-=", None, ToggleSuperscript),122
shortcut!(Composer, Composer, "Subscript", "ctrl-=", None, ToggleSubscript),125
shortcut!(Composer, Composer, "Subscript", "ctrl-=", None, ToggleSubscript),123
shortcut!(Composer, Composer, "Code", "ctrl-shift-c", None, ToggleCode),126
shortcut!(Composer, Composer, "Code", "ctrl-shift-c", None, ToggleCode),124
shortcut!(Composer, Composer, "Insert link", "ctrl-k", Some("cmd-k"), EditLink),127
shortcut!(Composer, Composer, "Insert link", "ctrl-k", Some("cmd-k"), EditLink),125
shortcut!(Composer, Composer, "Paste as plain text", "ctrl-shift-v", Some("cmd-shift-v"), PastePlainText),128
shortcut!(Composer, Composer, "Paste as plain text", "ctrl-shift-v", Some("cmd-shift-v"), PastePlainText),126
shortcut!(Composer, Composer, "Schedule send", "ctrl-shift-enter", None, ScheduleSend),129
shortcut!(Composer, Composer, "Schedule send", "ctrl-shift-enter", None, ScheduleSend),130
shortcut!(Composer, Composer, "Insert column or row", "ctrl-alt-=", None, InsertTableLine),131
shortcut!(Composer, Composer, "Delete column, row, or table", "ctrl-alt--", None, RemoveTableLine),127
shortcut!(Calls, GlobalOverTextFields, "Accept incoming call", "ctrl-shift-a", Some("cmd-shift-a"), AcceptCall),132
shortcut!(Calls, GlobalOverTextFields, "Accept incoming call", "ctrl-shift-a", Some("cmd-shift-a"), AcceptCall),128
shortcut!(Calls, GlobalOverTextFields, "Decline incoming call", "ctrl-shift-d", Some("cmd-shift-d"), DeclineCall),133
shortcut!(Calls, GlobalOverTextFields, "Decline incoming call", "ctrl-shift-d", Some("cmd-shift-d"), DeclineCall),129
shortcut!(Calls, GlobalOverTextFields, "Join the meeting from its reminder", "ctrl-shift-j", Some("cmd-shift-j"), JoinMeetingFromToast),134
shortcut!(Calls, GlobalOverTextFields, "Join the meeting from its reminder", "ctrl-shift-j", Some("cmd-shift-j"), JoinMeetingFromToast),@@ -348,5 +353,33 @@ mod tests {348
assert_eq!(display_keys("alt-shift-="), "Alt+Shift+Plus");353
assert_eq!(display_keys("alt-shift-="), "Alt+Shift+Plus");349
assert_eq!(display_keys("alt-shift--"), "Alt+Shift+Minus");354
assert_eq!(display_keys("alt-shift--"), "Alt+Shift+Minus");350
assert_eq!(display_keys("alt-shift-0"), "Alt+Shift+0");355
assert_eq!(display_keys("alt-shift-0"), "Alt+Shift+0");356
assert_eq!(display_keys("ctrl-alt--"), "Ctrl+Alt+Minus");357
}358
359
#[gpui_kit::test]360
fn composer_format_and_table_keys_match_teams(cx: &mut TestAppContext) {361
registered(cx);362
let typing = ["AppShell", "Composer", "Input"];363
let action_of = |label: &str| {364
action_name(365
SHORTCUTS366
.iter()367
.find(|shortcut| shortcut.label == label)368
.unwrap(),369
)370
};371
for (keys, label) in [372
("ctrl-shift-x", "Format"),373
("ctrl-alt-x", "Strikethrough"),374
("ctrl-alt-=", "Insert column or row"),375
("ctrl-alt-+", "Insert column or row"),376
("ctrl-alt--", "Delete column, row, or table"),377
] {378
assert_eq!(379
bound_action(cx, keys, &typing),380
Some(action_of(label)),381
"{keys}"382
);383
}351
}384
}352
}385
}@@ -129,27 +129,29 @@ struct Reserved {
129
129
struct TitleBarRow {
130
130
app_icon: AppIcon,
131
131
mode_label: Option<&'static str>,
132
update: Option<AnyElement>,
133
own: Option<AnyElement>,
132
controls: Vec<AnyElement>,
134
133
on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
135
134
}
136
135
137
136
pub fn render_title_bar(
138
137
app_icon: AppIcon,
139
138
mode_label: Option<&'static str>,
140
update: Option<AnyElement>,
141
own: Option<AnyElement>,
139
controls: impl IntoIterator<Item = AnyElement>,
142
140
on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
143
141
) -> impl IntoElement {
144
142
TitleBarRow {
145
143
app_icon,
146
144
mode_label,
147
update,
148
own,
145
controls: controls.into_iter().collect(),
149
146
on_search: Box::new(on_search),
150
147
}
151
148
}
152
149
150
// The Windows caption hit-test takes every point the Drag area reaches, so a control without occlusion never gets its click.
151
fn outside_caption(control: AnyElement) -> Div {
152
div().flex_none().occlude().child(control)
153
}
154
153
155
fn search_box(
154
156
span: SearchSpan,
155
157
on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
@@ -229,8 +231,7 @@ impl RenderOnce for TitleBarRow {
229
231
.h_full()
230
232
.gap(px(12.))
231
233
.items_center()
232
.children(self.update)
233
.children(self.own)
234
.children(self.controls.into_iter().map(outside_caption))
234
235
.child(div().w(px(4.)));
235
236
let row = h_flex()
236
237
.flex_1()
@@ -278,7 +279,104 @@ impl RenderOnce for TitleBarRow {
278
279
279
280
#[cfg(test)]
280
281
mod tests {
281
use super::{SEARCH_MIN_WIDTH, SEARCH_WIDTH, search_span};
282
use std::cell::{Cell, RefCell};
283
use std::rc::Rc;
284
285
use gpui_kit::component::button::{Button, ButtonVariants as _};
286
use gpui_kit::{
287
Context, Hitbox, HitboxBehavior, InteractiveElement as _, IntoElement, Modifiers,
288
ParentElement, Render, Styled, TestAppContext, Window, canvas, div, px, size,
289
};
290
291
use super::{
292
AppIcon, SEARCH_MIN_WIDTH, SEARCH_WIDTH, UpdateStatus, render_title_bar, search_span,
293
update_button,
294
};
295
296
struct CaptionHarness {
297
caption: Rc<RefCell<Option<Hitbox>>>,
298
restarts: Rc<Cell<usize>>,
299
}
300
301
impl Render for CaptionHarness {
302
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
303
let caption = self.caption.clone();
304
let restarts = self.restarts.clone();
305
let own = div()
306
.debug_selector(|| "shell/title-bar/own-status".into())
307
.child(Button::new("own").ghost().size(px(32.)).child("O"))
308
.into_any_element();
309
div()
310
.relative()
311
.size_full()
312
.child(
313
canvas(
314
|bounds, window, _| window.insert_hitbox(bounds, HitboxBehavior::Normal),
315
move |_, hitbox, _, _| *caption.borrow_mut() = Some(hitbox),
316
)
317
.absolute()
318
.size_full(),
319
)
320
.child(render_title_bar(
321
AppIcon::ALL[0],
322
Some("Demo"),
323
[
324
update_button(&UpdateStatus::Ready, move |_, _, _| {
325
restarts.set(restarts.get() + 1)
326
}),
327
Some(own),
328
]
329
.into_iter()
330
.flatten(),
331
|_, _, _| {},
332
))
333
}
334
}
335
336
#[gpui_kit::test]
337
fn title_bar_controls_stay_out_of_the_caption(cx: &mut TestAppContext) {
338
cx.update(gpui_kit::init);
339
cx.update(crate::theme::apply);
340
let caption = Rc::new(RefCell::new(None));
341
let restarts = Rc::new(Cell::new(0));
342
let (_, window_cx) = cx.add_window_view({
343
let caption = caption.clone();
344
let restarts = restarts.clone();
345
move |_, _| CaptionHarness { caption, restarts }
346
});
347
window_cx.simulate_resize(size(px(1280.), px(800.)));
348
for _ in 0..2 {
349
window_cx.update(|window, cx| window.draw(cx).clear(cx));
350
}
351
let mut found = Vec::new();
352
for (selector, caption_expected) in [
353
("shell/title-bar/update", false),
354
("shell/title-bar/own-status", false),
355
("shell/title-bar/search", false),
356
("shell/title-bar/leading", true),
357
] {
358
let Some(bounds) = window_cx.debug_bounds(selector) else {
359
found.push(format!("{selector} was not rendered"));
360
continue;
361
};
362
let center = bounds.center();
363
let in_caption = window_cx.update(|window, _| {
364
caption
365
.borrow()
366
.as_ref()
367
.is_some_and(|hitbox| hitbox.is_hovered_at(center, window))
368
});
369
if in_caption != caption_expected {
370
found.push(format!("{selector} in caption: {in_caption}"));
371
}
372
}
373
assert!(found.is_empty(), "{}", found.join("\n"));
374
let update = window_cx
375
.debug_bounds("shell/title-bar/update")
376
.expect("update button rendered");
377
window_cx.simulate_click(update.center(), Modifiers::default());
378
assert_eq!(restarts.get(), 1);
379
}
282
380
283
381
#[test]
284
382
fn search_stays_centered_while_it_fits() {
@@ -129,27 +129,29 @@ struct Reserved {129
struct TitleBarRow {129
struct TitleBarRow {130
app_icon: AppIcon,130
app_icon: AppIcon,131
mode_label: Option<&'static str>,131
mode_label: Option<&'static str>,132
update: Option<AnyElement>,132
controls: Vec<AnyElement>,133
own: Option<AnyElement>,134
on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,133
on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,135
}134
}136
135
137
pub fn render_title_bar(136
pub fn render_title_bar(138
app_icon: AppIcon,137
app_icon: AppIcon,139
mode_label: Option<&'static str>,138
mode_label: Option<&'static str>,140
update: Option<AnyElement>,139
controls: impl IntoIterator<Item = AnyElement>,141
own: Option<AnyElement>,142
on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,140
on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,143
) -> impl IntoElement {141
) -> impl IntoElement {144
TitleBarRow {142
TitleBarRow {145
app_icon,143
app_icon,146
mode_label,144
mode_label,147
update,145
controls: controls.into_iter().collect(),148
own,149
on_search: Box::new(on_search),146
on_search: Box::new(on_search),150
}147
}151
}148
}152
149
150
// The Windows caption hit-test takes every point the Drag area reaches, so a control without occlusion never gets its click.151
fn outside_caption(control: AnyElement) -> Div {152
div().flex_none().occlude().child(control)153
}154
153
fn search_box(155
fn search_box(154
span: SearchSpan,156
span: SearchSpan,155
on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,157
on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,@@ -229,8 +231,7 @@ impl RenderOnce for TitleBarRow {229
.h_full()231
.h_full()230
.gap(px(12.))232
.gap(px(12.))231
.items_center()233
.items_center()232
.children(self.update)234
.children(self.controls.into_iter().map(outside_caption))233
.children(self.own)234
.child(div().w(px(4.)));235
.child(div().w(px(4.)));235
let row = h_flex()236
let row = h_flex()236
.flex_1()237
.flex_1()@@ -278,7 +279,104 @@ impl RenderOnce for TitleBarRow {278
279
279
#[cfg(test)]280
#[cfg(test)]280
mod tests {281
mod tests {281
use super::{SEARCH_MIN_WIDTH, SEARCH_WIDTH, search_span};282
use std::cell::{Cell, RefCell};283
use std::rc::Rc;284
285
use gpui_kit::component::button::{Button, ButtonVariants as _};286
use gpui_kit::{287
Context, Hitbox, HitboxBehavior, InteractiveElement as _, IntoElement, Modifiers,288
ParentElement, Render, Styled, TestAppContext, Window, canvas, div, px, size,289
};290
291
use super::{292
AppIcon, SEARCH_MIN_WIDTH, SEARCH_WIDTH, UpdateStatus, render_title_bar, search_span,293
update_button,294
};295
296
struct CaptionHarness {297
caption: Rc<RefCell<Option<Hitbox>>>,298
restarts: Rc<Cell<usize>>,299
}300
301
impl Render for CaptionHarness {302
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {303
let caption = self.caption.clone();304
let restarts = self.restarts.clone();305
let own = div()306
.debug_selector(|| "shell/title-bar/own-status".into())307
.child(Button::new("own").ghost().size(px(32.)).child("O"))308
.into_any_element();309
div()310
.relative()311
.size_full()312
.child(313
canvas(314
|bounds, window, _| window.insert_hitbox(bounds, HitboxBehavior::Normal),315
move |_, hitbox, _, _| *caption.borrow_mut() = Some(hitbox),316
)317
.absolute()318
.size_full(),319
)320
.child(render_title_bar(321
AppIcon::ALL[0],322
Some("Demo"),323
[324
update_button(&UpdateStatus::Ready, move |_, _, _| {325
restarts.set(restarts.get() + 1)326
}),327
Some(own),328
]329
.into_iter()330
.flatten(),331
|_, _, _| {},332
))333
}334
}335
336
#[gpui_kit::test]337
fn title_bar_controls_stay_out_of_the_caption(cx: &mut TestAppContext) {338
cx.update(gpui_kit::init);339
cx.update(crate::theme::apply);340
let caption = Rc::new(RefCell::new(None));341
let restarts = Rc::new(Cell::new(0));342
let (_, window_cx) = cx.add_window_view({343
let caption = caption.clone();344
let restarts = restarts.clone();345
move |_, _| CaptionHarness { caption, restarts }346
});347
window_cx.simulate_resize(size(px(1280.), px(800.)));348
for _ in 0..2 {349
window_cx.update(|window, cx| window.draw(cx).clear(cx));350
}351
let mut found = Vec::new();352
for (selector, caption_expected) in [353
("shell/title-bar/update", false),354
("shell/title-bar/own-status", false),355
("shell/title-bar/search", false),356
("shell/title-bar/leading", true),357
] {358
let Some(bounds) = window_cx.debug_bounds(selector) else {359
found.push(format!("{selector} was not rendered"));360
continue;361
};362
let center = bounds.center();363
let in_caption = window_cx.update(|window, _| {364
caption365
.borrow()366
.as_ref()367
.is_some_and(|hitbox| hitbox.is_hovered_at(center, window))368
});369
if in_caption != caption_expected {370
found.push(format!("{selector} in caption: {in_caption}"));371
}372
}373
assert!(found.is_empty(), "{}", found.join("\n"));374
let update = window_cx375
.debug_bounds("shell/title-bar/update")376
.expect("update button rendered");377
window_cx.simulate_click(update.center(), Modifiers::default());378
assert_eq!(restarts.get(), 1);379
}282
380
283
#[test]381
#[test]284
fn search_stays_centered_while_it_fits() {382
fn search_stays_centered_while_it_fits() {@@ -19,16 +19,47 @@ pub fn toolbar_slot(id: ElementId, hover: HoverChange, bar: impl IntoElement) ->
19
19
.child(bar)
20
20
}
21
21
22
pub fn record_bounds(timeline: &TimelineBounds) -> impl IntoElement {
22
pub fn record_bounds(timeline: &TimelineBounds, top_inset: Pixels) -> impl IntoElement {
23
23
let timeline = timeline.clone();
24
24
canvas(
25
25
move |bounds, _, _| timeline.set(Some(bounds)),
26
26
|_, _, _, _| {},
27
27
)
28
28
.absolute()
29
.top_0()
29
.top(top_inset)
30
30
.left_0()
31
.size_full()
31
.right_0()
32
.bottom_0()
33
}
34
35
#[derive(Clone, Copy, Debug, PartialEq)]
36
pub enum ToolbarSide {
37
Above,
38
Below,
39
ViewportTop,
40
}
41
42
pub fn toolbar_side(anchor: Bounds<Pixels>, viewport: Bounds<Pixels>) -> ToolbarSide {
43
let above_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
44
let below_bottom = anchor.bottom() + px(SLOT_HEIGHT - TOOLBAR_GAP);
45
if above_top >= viewport.top() {
46
ToolbarSide::Above
47
} else if below_bottom <= viewport.bottom() {
48
ToolbarSide::Below
49
} else {
50
ToolbarSide::ViewportTop
51
}
52
}
53
54
fn toolbar_offset(anchor: Bounds<Pixels>, viewport: Option<Bounds<Pixels>>) -> Pixels {
55
let Some(viewport) = viewport else {
56
return px(0.);
57
};
58
match toolbar_side(anchor, viewport) {
59
ToolbarSide::Above => px(0.),
60
ToolbarSide::Below => anchor.size.height + px(SLOT_HEIGHT),
61
ToolbarSide::ViewportTop => viewport.top() - anchor.top() + px(SLOT_HEIGHT),
62
}
32
63
}
33
64
34
65
pub fn placed_toolbar(
@@ -59,16 +90,6 @@ struct PlacedToolbar {
59
90
overlay: AnyElement,
60
91
}
61
92
62
impl PlacedToolbar {
63
fn flip_offset(&self, anchor: Bounds<Pixels>) -> Pixels {
64
let bar_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
65
match self.timeline.get() {
66
Some(timeline) if bar_top < timeline.top() => anchor.size.height + px(SLOT_HEIGHT),
67
_ => px(0.),
68
}
69
}
70
}
71
72
93
impl Element for PlacedToolbar {
73
94
type RequestLayoutState = ();
74
95
type PrepaintState = ();
@@ -100,7 +121,7 @@ impl Element for PlacedToolbar {
100
121
window: &mut Window,
101
122
cx: &mut App,
102
123
) {
103
let offset = point(px(0.), self.flip_offset(bounds));
124
let offset = point(px(0.), toolbar_offset(bounds, self.timeline.get()));
104
125
window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));
105
126
}
106
127
@@ -125,3 +146,49 @@ impl IntoElement for PlacedToolbar {
125
146
self
126
147
}
127
148
}
149
150
#[cfg(test)]
151
mod tests {
152
use super::{SLOT_HEIGHT, TOOLBAR_GAP, ToolbarSide, toolbar_offset, toolbar_side};
153
use gpui_kit::{Bounds, point, px, size};
154
155
fn span(top: f32, bottom: f32) -> Bounds<gpui_kit::Pixels> {
156
Bounds::new(point(px(0.), px(top)), size(px(400.), px(bottom - top)))
157
}
158
159
const VIEWPORT: (f32, f32) = (100., 600.);
160
const BAR_ROOM: f32 = SLOT_HEIGHT - TOOLBAR_GAP;
161
162
#[test]
163
fn stays_above_with_room_below_the_viewport_top() {
164
let viewport = span(VIEWPORT.0, VIEWPORT.1);
165
let message = span(VIEWPORT.0 + BAR_ROOM, 300.);
166
assert_eq!(toolbar_side(message, viewport), ToolbarSide::Above);
167
assert_eq!(toolbar_offset(message, Some(viewport)), px(0.));
168
}
169
170
#[test]
171
fn flips_below_when_the_bar_would_cross_the_viewport_top() {
172
let viewport = span(VIEWPORT.0, VIEWPORT.1);
173
let message = span(VIEWPORT.0 + BAR_ROOM - 1., 300.);
174
assert_eq!(toolbar_side(message, viewport), ToolbarSide::Below);
175
assert_eq!(
176
toolbar_offset(message, Some(viewport)),
177
message.size.height + px(SLOT_HEIGHT)
178
);
179
}
180
181
#[test]
182
fn sticks_to_the_viewport_top_when_neither_side_fits() {
183
let viewport = span(VIEWPORT.0, VIEWPORT.1);
184
let message = span(VIEWPORT.0 - 50., VIEWPORT.1 - BAR_ROOM + 1.);
185
assert_eq!(toolbar_side(message, viewport), ToolbarSide::ViewportTop);
186
let bar_top = message.top() - px(SLOT_HEIGHT) + toolbar_offset(message, Some(viewport));
187
assert_eq!(bar_top, viewport.top());
188
}
189
190
#[test]
191
fn stays_above_without_measured_viewport() {
192
assert_eq!(toolbar_offset(span(0., 100.), None), px(0.));
193
}
194
}
@@ -19,16 +19,47 @@ pub fn toolbar_slot(id: ElementId, hover: HoverChange, bar: impl IntoElement) ->19
.child(bar)19
.child(bar)20
}20
}21
21
22
pub fn record_bounds(timeline: &TimelineBounds) -> impl IntoElement {22
pub fn record_bounds(timeline: &TimelineBounds, top_inset: Pixels) -> impl IntoElement {23
let timeline = timeline.clone();23
let timeline = timeline.clone();24
canvas(24
canvas(25
move |bounds, _, _| timeline.set(Some(bounds)),25
move |bounds, _, _| timeline.set(Some(bounds)),26
|_, _, _, _| {},26
|_, _, _, _| {},27
)27
)28
.absolute()28
.absolute()29
.top_0()29
.top(top_inset)30
.left_0()30
.left_0()31
.size_full()31
.right_0()32
.bottom_0()33
}34
35
#[derive(Clone, Copy, Debug, PartialEq)]36
pub enum ToolbarSide {37
Above,38
Below,39
ViewportTop,40
}41
42
pub fn toolbar_side(anchor: Bounds<Pixels>, viewport: Bounds<Pixels>) -> ToolbarSide {43
let above_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);44
let below_bottom = anchor.bottom() + px(SLOT_HEIGHT - TOOLBAR_GAP);45
if above_top >= viewport.top() {46
ToolbarSide::Above47
} else if below_bottom <= viewport.bottom() {48
ToolbarSide::Below49
} else {50
ToolbarSide::ViewportTop51
}52
}53
54
fn toolbar_offset(anchor: Bounds<Pixels>, viewport: Option<Bounds<Pixels>>) -> Pixels {55
let Some(viewport) = viewport else {56
return px(0.);57
};58
match toolbar_side(anchor, viewport) {59
ToolbarSide::Above => px(0.),60
ToolbarSide::Below => anchor.size.height + px(SLOT_HEIGHT),61
ToolbarSide::ViewportTop => viewport.top() - anchor.top() + px(SLOT_HEIGHT),62
}32
}63
}33
64
34
pub fn placed_toolbar(65
pub fn placed_toolbar(@@ -59,16 +90,6 @@ struct PlacedToolbar {59
overlay: AnyElement,90
overlay: AnyElement,60
}91
}61
92
62
impl PlacedToolbar {63
fn flip_offset(&self, anchor: Bounds<Pixels>) -> Pixels {64
let bar_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);65
match self.timeline.get() {66
Some(timeline) if bar_top < timeline.top() => anchor.size.height + px(SLOT_HEIGHT),67
_ => px(0.),68
}69
}70
}71
72
impl Element for PlacedToolbar {93
impl Element for PlacedToolbar {73
type RequestLayoutState = ();94
type RequestLayoutState = ();74
type PrepaintState = ();95
type PrepaintState = ();@@ -100,7 +121,7 @@ impl Element for PlacedToolbar {100
window: &mut Window,121
window: &mut Window,101
cx: &mut App,122
cx: &mut App,102
) {123
) {103
let offset = point(px(0.), self.flip_offset(bounds));124
let offset = point(px(0.), toolbar_offset(bounds, self.timeline.get()));104
window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));125
window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));105
}126
}106
127
@@ -125,3 +146,49 @@ impl IntoElement for PlacedToolbar {125
self146
self126
}147
}127
}148
}149
150
#[cfg(test)]151
mod tests {152
use super::{SLOT_HEIGHT, TOOLBAR_GAP, ToolbarSide, toolbar_offset, toolbar_side};153
use gpui_kit::{Bounds, point, px, size};154
155
fn span(top: f32, bottom: f32) -> Bounds<gpui_kit::Pixels> {156
Bounds::new(point(px(0.), px(top)), size(px(400.), px(bottom - top)))157
}158
159
const VIEWPORT: (f32, f32) = (100., 600.);160
const BAR_ROOM: f32 = SLOT_HEIGHT - TOOLBAR_GAP;161
162
#[test]163
fn stays_above_with_room_below_the_viewport_top() {164
let viewport = span(VIEWPORT.0, VIEWPORT.1);165
let message = span(VIEWPORT.0 + BAR_ROOM, 300.);166
assert_eq!(toolbar_side(message, viewport), ToolbarSide::Above);167
assert_eq!(toolbar_offset(message, Some(viewport)), px(0.));168
}169
170
#[test]171
fn flips_below_when_the_bar_would_cross_the_viewport_top() {172
let viewport = span(VIEWPORT.0, VIEWPORT.1);173
let message = span(VIEWPORT.0 + BAR_ROOM - 1., 300.);174
assert_eq!(toolbar_side(message, viewport), ToolbarSide::Below);175
assert_eq!(176
toolbar_offset(message, Some(viewport)),177
message.size.height + px(SLOT_HEIGHT)178
);179
}180
181
#[test]182
fn sticks_to_the_viewport_top_when_neither_side_fits() {183
let viewport = span(VIEWPORT.0, VIEWPORT.1);184
let message = span(VIEWPORT.0 - 50., VIEWPORT.1 - BAR_ROOM + 1.);185
assert_eq!(toolbar_side(message, viewport), ToolbarSide::ViewportTop);186
let bar_top = message.top() - px(SLOT_HEIGHT) + toolbar_offset(message, Some(viewport));187
assert_eq!(bar_top, viewport.top());188
}189
190
#[test]191
fn stays_above_without_measured_viewport() {192
assert_eq!(toolbar_offset(span(0., 100.), None), px(0.));193
}194
}