Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/ui-egui/src/ribbon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use notecraft_model::{PageFormat, Tag};
/// shows a tab for what is selected.
pub const TABS: [&str; 5] = ["Home", "Insert", "Draw", "History", "View"];
pub const SOURCE_TAB: &str = "Source";
pub const FONT_SIZES: [u8; 14] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 28, 36, 48, 72];
pub const FONT_SIZES: [u8; 16] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72];
/// Shown only while the caret is in a table, the way Office shows a tab for the thing in
/// hand. It goes when the caret leaves, and the ribbon falls back to Home.
pub const TABLE_TAB: &str = "Table";
Expand Down Expand Up @@ -846,7 +846,7 @@ fn home_tab(ui: &mut Ui, view: &View<'_>, t: &Tokens, acts: &mut Vec<Act>) {
let size_label = view.font_size.unwrap_or_else(|| crate::tl_id!("ui.font_size"));
let size_menu = ui.menu_button(size_label, |ui| {
for size in FONT_SIZES {
if ui.button(format!("{size} pt")).clicked() {
if ui.button(format!("{size}")).clicked() {
acts.push(Act::FontSize(size));
ui.close();
}
Expand Down Expand Up @@ -3027,4 +3027,11 @@ mod tests {
assert_ne!(Act::Block("h1"), Act::Insert("h1"));
assert_eq!(Act::Tab("Insert".into()), Act::Tab("Insert".to_string()));
}

/// SUP-009: the font size list is OneNote's whole sizes (the page format stores whole
/// numbers, so 9.5 and 10.5 wait for a format change).
#[test]
fn the_font_size_list_is_onenotes_whole_sizes() {
assert_eq!(FONT_SIZES.as_slice(), [8u8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72].as_slice());
}
}
34 changes: 17 additions & 17 deletions crates/ui-egui/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5830,7 +5830,7 @@ fn font_size_does_not_change_the_wrong_text_for_a_cross_paragraph_selection() {
let before = h.state().body().unwrap_or_default().to_string();
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
assert_eq!(h.state().body().unwrap_or_default(), before, "unsupported cross-paragraph selection must not change an unrelated caret");
let inspection = ask(&mut h, "ui.inspect", json!({})).expect("inspect");
Expand Down Expand Up @@ -6160,7 +6160,7 @@ fn font_selectors_show_selection_values_and_mixed_state_in_both_formats() {
assert_eq!(h.get_by_label("Font Size").value().as_deref(), Some("Mixed"));
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("24 pt").click();
h.get_by_label("24").click();
settle(&mut h);
assert_eq!(h.get_by_label("Font Size").value().as_deref(), Some("24 pt"));
assert_eq!(h.get_by_label("Font Family").value().as_deref(), Some("Mixed"));
Expand All @@ -6181,7 +6181,7 @@ fn font_selectors_show_pending_size_without_editing_the_page() {
let before = h.state().body().unwrap_or_default().to_string();
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
assert_eq!(h.get_by_label("Font Size").value().as_deref(), Some("18 pt"));
assert_eq!(h.state().body().unwrap_or_default(), before);
Expand Down Expand Up @@ -6449,7 +6449,7 @@ fn font_size_replaces_only_the_partial_selection_inside_an_existing_size() {
}
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("24 pt").click();
h.get_by_label("24").click();
settle(&mut h);
let body = h.state().body().unwrap_or_default();
let (blocks, _) = notecraft_formats::boxes::read(notecraft_model::PageFormat::Cmgfm, body);
Expand Down Expand Up @@ -6477,7 +6477,7 @@ fn font_size_replaces_mixed_sizes_in_a_partial_selection() {
pump(&mut h);
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("24 pt").click();
h.get_by_label("24").click();
settle(&mut h);
let body = h.state().body().unwrap_or_default();
let (blocks, _) = notecraft_formats::boxes::read(notecraft_model::PageFormat::Cmgfm, body);
Expand Down Expand Up @@ -6549,7 +6549,7 @@ fn pending_marks_combine_with_size_for_unicode_typing_in_both_formats() {
settle(&mut h);
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
assert_eq!(h.get_by_label("Font Size").value().as_deref(), Some("18 pt"), "the pending size is shown");
assert_eq!(h.state().body().unwrap_or_default(), before);
Expand Down Expand Up @@ -6668,7 +6668,7 @@ fn selected_container_font_size_is_undoable_and_leaves_other_boxes_alone() {
let before = h.state().body().unwrap_or_default().to_string();
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
assert_eq!(h.get_by_label("Font Size").value().as_deref(), Some("18 pt"), "the selected container reports its size");
let after = h.state().body().unwrap_or_default().to_string();
Expand Down Expand Up @@ -6836,7 +6836,7 @@ fn font_size_without_selection_formats_new_text() {
let original = h.state().body().unwrap_or_default().to_string();
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
assert_eq!(h.state().body().unwrap_or_default(), original, "choosing a size alone does not change the page");
let history = ask(&mut h, "ui.inspect", json!({})).expect("inspect")["page"]["history"].clone();
Expand Down Expand Up @@ -6875,7 +6875,7 @@ fn pending_font_size_is_cleared_when_caret_moves() {
ask(&mut h, "ui.caret", json!({"block": 1})).expect("caret");
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
ask(&mut h, "ui.key", json!({"key": "ArrowLeft"})).expect("move caret");
settle(&mut h);
Expand All @@ -6895,7 +6895,7 @@ fn pending_font_size_applies_to_unicode_typing() {
ask(&mut h, "ui.caret", json!({"block": 1})).expect("caret");
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
ask(&mut h, "ui.text", json!({"text": "مرحبا"})).expect("type unicode");
settle(&mut h);
Expand All @@ -6914,13 +6914,13 @@ fn pending_font_size_can_change_in_a_typing_run() {
ask(&mut h, "ui.caret", json!({"block": 1})).expect("caret");
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
ask(&mut h, "ui.text", json!({"text": "first"})).expect("first size");
settle(&mut h);
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("24 pt").click();
h.get_by_label("24").click();
settle(&mut h);
ask(&mut h, "ui.text", json!({"text": "second"})).expect("second size");
settle(&mut h);
Expand Down Expand Up @@ -6948,7 +6948,7 @@ fn font_size_applies_to_selected_text_and_survives_reopen_in_both_formats() {

h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);

let body = h.state().body().unwrap_or_default().to_string();
Expand Down Expand Up @@ -6978,7 +6978,7 @@ fn font_size_undo_and_redo_preserve_page_content_in_both_formats() {

h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
settle(&mut h);
let formatted = h.state().body().unwrap_or_default().to_string();
assert!(formatted.contains("<span style=\"font-size: 18pt\">"), "the size was applied: {formatted}");
Expand All @@ -7000,7 +7000,7 @@ fn font_size_undo_and_redo_preserve_page_content_in_both_formats() {
pump(&mut h);
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("24 pt").click();
h.get_by_label("24").click();
settle(&mut h);
let resized = h.state().body().unwrap_or_default().to_string();
assert!(resized.contains("font-size: 24pt"), "the second size was applied for {path}: {resized}");
Expand Down Expand Up @@ -7028,7 +7028,7 @@ fn font_size_undo_and_redo_preserve_page_content_in_both_formats() {
pump(&mut h);
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("24 pt").click();
h.get_by_label("24").click();
settle(&mut h);
assert_eq!(ask(&mut h, "ui.inspect", json!({})).expect("inspect")["page"]["history"], history, "same size is not an edit");
ask(&mut h, "ui.undo", json!({})).expect("undo through the user action");
Expand Down Expand Up @@ -7063,7 +7063,7 @@ fn font_size_history_stays_separate_from_typing() {
pump(&mut h);
h.get_by_label("Font Size").click();
h.run();
h.get_by_label("18 pt").click();
h.get_by_label("18").click();
h.run();
let formatted = h.state().body().unwrap_or_default().to_string();
assert!(formatted.contains("font-size: 18pt"), "the size was applied: {formatted}");
Expand Down
Loading