Compare commits

...
5 changed files with 242 additions and 4 deletions
+20
View File
@@ -0,0 +1,20 @@
name: Notify Services on Release Change
on:
release:
types:
- published
- unpublished
- created
- edited
- deleted
- prereleased
- released
permissions: {}
jobs:
notify:
uses: storytold/craft-common-actions/.github/workflows/notify-services.yml@main
secrets:
ARTCRAFT_SERVICES_DISPATCH_TOKEN: ${{ secrets.ARTCRAFT_SERVICES_DISPATCH_TOKEN }}
+4 -4
View File
@@ -6281,8 +6281,8 @@ fn cut_and_copy_with_bare_caret_beside_object_change_nothing() {
assert!(s.sel.is_collapsed());
assert!(crate::cmd::objects::object_selection(&s).is_none());
let copy_res = run(&mut s, "edit.copy", json!({}));
assert_eq!(copy_res["text"], "", "copy on bare caret returns empty text");
let copy_res = s.run("edit.copy", &json!({}));
assert!(matches!(copy_res, Err(crate::CmdError::Disabled(_))), "copy on bare caret is disabled");
assert!(s.clipboard.is_none(), "clipboard remains unset");
let cut_res = s.run("edit.cut", &json!({}));
@@ -6297,8 +6297,8 @@ fn cut_and_copy_with_bare_caret_beside_object_change_nothing() {
assert!(s.sel.is_collapsed());
assert!(crate::cmd::objects::object_selection(&s).is_none());
let copy_res = run(&mut s, "edit.copy", json!({}));
assert_eq!(copy_res["text"], "", "copy on bare caret returns empty text");
let copy_res = s.run("edit.copy", &json!({}));
assert!(matches!(copy_res, Err(crate::CmdError::Disabled(_))), "copy on bare caret is disabled");
assert!(s.clipboard.is_none(), "clipboard remains unset");
let cut_res = s.run("edit.cut", &json!({}));
+49
View File
@@ -330,6 +330,25 @@ fn a_desktop_paste_after_mod_shift_v_is_not_swallowed() {
assert_eq!(body(h.state()), "source later");
}
/// #5616: Mod+Shift+C (Copy Formatting), Shift released, Mod still held or released: Mod+C's
/// chord isn't the paste's modifiers, so a subsequent Mod+V paste keeps HTML's formatting (bold).
#[test]
fn an_unrelated_keys_modifiers_do_not_steer_a_later_paste() {
for mod_still_held in [false, true] {
let mut h = alt_frame_app();
offer(&h, bold_flavours("external"));
let chord = Modifiers { shift: true, ..mod_held() };
mods_frame(&mut h, chord, vec![key_event(Key::C, true, chord)]);
let after = if mod_still_held { mod_held() } else { Modifiers::NONE };
mods_frame(&mut h, after, vec![key_event(Key::C, false, after)]);
let ctrl = mod_held();
mods_frame(&mut h, ctrl, vec![key_event(Key::V, true, ctrl)]);
mods_frame(&mut h, Modifiers::NONE, vec![key_event(Key::V, false, Modifiers::NONE)]);
assert_eq!(body(h.state()), "external");
assert!(is_bold(&mut h), "held={mod_still_held}: Mod+V keeps the HTML's bold");
}
}
/// Paste Formatting on a chord the user bound pastes the copied formatting once.
#[test]
fn paste_formatting_on_another_key_pastes_the_copied_formatting() {
@@ -422,6 +441,36 @@ fn mod_v_pastes_rich_only_clipboard_and_preserves_picture_routing() {
assert_eq!(body(h.state()), "", "picture file paste does not fall back to HTML text");
}
/// #819: Alt+Q reaches Search/commands even when the canvas does not hold focus.
#[test]
fn alt_shortcuts_work_without_the_canvas_focused() {
if cfg!(target_os = "macos") {
return;
}
let mut app = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("Text")), Default::default());
app.run("view.focus", json!({})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
app,
);
crate::test_harness::frames(&mut h, 4);
if let Some(focused_id) = h.ctx.memory(|m| m.focused()) {
h.ctx.memory_mut(|m| m.surrender_focus(focused_id));
}
crate::test_harness::frames(&mut h, 1);
assert!(!h.state().canvas.focused(&h.ctx.clone()), "canvas is unfocused");
let alt = egui::Modifiers { alt: true, ..Default::default() };
mods_frame(&mut h, alt, vec![key_event(Key::Q, true, alt)]);
crate::test_harness::frames(&mut h, 2);
use egui_kittest::kittest::Queryable as _;
assert!(h.query_by_role(egui::accesskit::Role::Dialog).is_some(), "Alt+Q opens Search/commands with canvas unfocused");
}
/// Alt held, keypad 0 2 3 3, Alt released: é (й on a Russian system) is typed, the digits
/// aren't, and keytips stay off (#961). Linux sends each digit's text too; Windows may send the
/// composed character.
+51
View File
@@ -2080,6 +2080,57 @@ fn title_and_account_buttons_work() {
assert!(h.query_by_label("User name:").is_some());
}
/// A pointer drag on a pane's resize edge leaves no keyboard focus behind, so Ctrl and
/// F-key shortcuts run right after it, docked or floating (#1756).
#[test]
fn shortcuts_run_after_a_pane_resize() {
use egui::accesskit::Role;
use egui_kittest::kittest::{By, Queryable};
type H = egui_kittest::Harness<'static, WordApp>;
fn key(h: &mut H, key: egui::Key, modifiers: egui::Modifiers) {
h.key_press_modifiers(modifiers, key);
h.step();
}
fn drag(h: &mut H, from: egui::Pos2, by: egui::Vec2) {
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
h.event(egui::Event::PointerMoved(from));
h.event(button(from, true));
h.step();
h.event(egui::Event::PointerMoved(from + by));
h.step();
h.event(button(from + by, false));
h.step();
}
let find_open = |h: &H| h.state().dialog_host.open_dialogs().iter().any(|d| d.key.as_deref() == Some("find"));
let styles_pane =
|h: &H| h.query_all(By::new().role(Role::Group).label("Styles")).map(|n| n.rect()).find(|r| r.height() > 300.0).expect("Styles pane frame");
let mut a = app();
a.run("view.stylesPane", json!({"value": true})).unwrap();
let mut h = harness(a);
h.step();
let pane = styles_pane(&h);
// On the pane's inner edge: drag left by 40 px to widen it.
drag(&mut h, egui::pos2(pane.left() + 1.0, pane.center().y), egui::vec2(-40.0, 0.0));
let width = h.state().ui.styles_pane_width.unwrap_or_default();
assert!((width - 290.0).abs() <= 2.0, "the drag widened the docked pane: {width}");
key(&mut h, egui::Key::H, egui::Modifiers::COMMAND);
assert!(find_open(&h), "Ctrl+H runs after the docked drag");
key(&mut h, egui::Key::Escape, egui::Modifiers::NONE);
assert!(h.state().dialog_host.open_dialogs().is_empty(), "Escape closes Replace");
h.state_mut().run("view.stylesPaneDock", json!({"dock": "float"})).unwrap();
h.step();
let float_pane = styles_pane(&h);
let before = h.state().ui.styles_pane_float;
// Drag the bottom-right corner.
drag(&mut h, float_pane.max - egui::vec2(2.0, 2.0), egui::vec2(30.0, 30.0));
assert_ne!(h.state().ui.styles_pane_float, before, "the drag resized the floating pane");
key(&mut h, egui::Key::H, egui::Modifiers::COMMAND);
assert!(find_open(&h), "Ctrl+H runs after the floating pane's resize");
}
/// #3172: the Paste button is named "Paste": its tooltip adds the key as the platform writes it,
/// so its name no longer carries macOS's "⌘V", which screen readers read on Windows as "Paste (⌘V)".
#[test]
+118
View File
@@ -1,5 +1,7 @@
use craft::font_manager::Catalog;
use craft::font_manager::craft_font_catalog::{Limits, Source};
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Props as _, Show as _};
use egui::Key;
use egui::accesskit::Role;
use egui_kittest::kittest::{NodeT, Queryable};
@@ -104,3 +106,119 @@ fn font_list_sections_skip_their_headings() {
h.run_steps(2);
assert_eq!(current_font(&mut h).as_deref(), Some(first_all.as_str()));
}
fn to_color32(rgba: craft::theme::Rgba) -> egui::Color32 {
egui::Color32::from(craft::theme::Srgba::from(rgba))
}
fn collect_shapes<'a>(shapes: &'a [egui::epaint::ClippedShape], out: &mut Vec<&'a egui::Shape>) {
for clipped in shapes {
fn walk<'a>(shape: &'a egui::Shape, out: &mut Vec<&'a egui::Shape>) {
match shape {
egui::Shape::Vec(children) => {
for child in children {
walk(child, out);
}
}
other => out.push(other),
}
}
walk(&clipped.shape, out);
}
}
fn find_button_fill(shapes: &[egui::epaint::ClippedShape], rect: egui::Rect) -> Option<(egui::Color32, egui::CornerRadius)> {
let mut flattened = Vec::new();
collect_shapes(shapes, &mut flattened);
flattened.into_iter().find_map(|s| match s {
egui::Shape::Rect(r)
if (r.rect.min.x - rect.min.x).abs() <= 1.5
&& (r.rect.max.x - rect.max.x).abs() <= 1.5
&& (r.rect.min.y - rect.min.y).abs() <= 1.5
&& (r.rect.max.y - rect.max.y).abs() <= 1.5
&& r.fill != egui::Color32::TRANSPARENT
&& r.corner_radius != egui::CornerRadius::ZERO =>
{
Some((r.fill, r.corner_radius))
}
_ => None,
})
}
/// #305: drawn buttons must react like standard buttons — resting at idle without a fill plate,
/// fading in through an intermediate fill on pointer hover, settling on the theme's hover state
/// token, darkening/transitioning to the pressed state token while held down, and clearing when
/// unhovered.
#[test]
fn drawn_buttons_fade_in_on_hover_and_darken_while_pressed() {
use egui::accesskit::Role;
let mut h = crate::test_harness::builder().with_size(egui::vec2(200.0, 100.0)).with_step_dt(0.04).build_ui(|ui| {
ui.horizontal(|ui| {
let _ = IconButton::new(crate::icons::id("save")).label("Save").show(ui);
});
});
h.ctx.all_styles_mut(|s| s.animation_time = egui::Style::default().animation_time);
h.step();
let env = craft::ui::runtime::env::Env::of_root(&h.ctx);
let expected_hover = to_color32(env.tokens.color.state.hover);
let expected_pressed = to_color32(env.tokens.color.state.pressed);
let node = h.get_by_role_and_label(Role::Button, "Save");
let rect = node.rect();
assert!(rect.is_positive(), "Save button must have positive rect");
// 1. Idle state: no hover or pressed fill plate
let fill_before = find_button_fill(&h.output().shapes, rect);
assert_eq!(fill_before, None, "Save button must have no hover fill before hover");
// 2. Hover state: fades in through an intermediate fill, then settles on the hover token
node.hover();
h.run_steps(2);
let fill_mid = find_button_fill(&h.output().shapes, rect);
assert!(fill_mid.is_some(), "Save button must paint an intermediate fill while fading in");
let (mid_fill, _) = fill_mid.unwrap();
assert!(
mid_fill != expected_hover && mid_fill.a() > 0 && mid_fill.a() < expected_hover.a(),
"Save button hover should fade in through an intermediate alpha: got {mid_fill:?}, expected settled {expected_hover:?}"
);
h.run_steps(3);
let fill_hovered = find_button_fill(&h.output().shapes, rect);
assert!(fill_hovered.is_some(), "Save button must produce settled hover shape");
let (hover_fill, radius) = fill_hovered.unwrap();
assert_eq!(hover_fill, expected_hover, "Save button settled hover fill must match theme hover token");
assert!(
radius.nw > 0 && radius.nw == radius.ne && radius.nw == radius.sw && radius.nw == radius.se,
"Save button corner radius must be uniformly rounded: {:?}",
radius
);
// 3. Pressed state: pressing pointer button darkens/transitions to theme's pressed state token
h.event(egui::Event::PointerButton { pos: rect.center(), button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE });
h.run_steps(4);
let fill_pressed = find_button_fill(&h.output().shapes, rect);
assert!(fill_pressed.is_some(), "Save button must have fill while pressed");
let (pressed_fill, _) = fill_pressed.unwrap();
assert_eq!(pressed_fill, expected_pressed, "Save button pressed fill must match theme pressed token");
// 4. Release: releasing pointer button transitions back to hover state
h.event(egui::Event::PointerButton {
pos: rect.center(),
button: egui::PointerButton::Primary,
pressed: false,
modifiers: egui::Modifiers::NONE,
});
h.run_steps(4);
let fill_released = find_button_fill(&h.output().shapes, rect);
assert!(fill_released.is_some(), "Save button must remain filled upon release");
let (released_fill, _) = fill_released.unwrap();
assert_eq!(released_fill, expected_hover, "Save button fill after release should return to hover token");
// 5. Unhover: pointer leaving the button clears the fill plate
h.event(egui::Event::PointerMoved(egui::pos2(0.0, 0.0)));
h.run_steps(4);
let fill_after = find_button_fill(&h.output().shapes, rect);
assert_eq!(fill_after, None, "Save button must clear hover fill after unhovering");
}