mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-02 10:47:02 -06:00
Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2f7c65e9c | ||
|
|
678e813ec4 | ||
|
|
1f682738fd | ||
|
|
647e726179 | ||
|
|
6b8f63e207 | ||
|
|
2b30b235d8 | ||
|
|
423c58523d | ||
|
|
e076e47529 | ||
|
|
f87e9cd6ba | ||
|
|
3820b9b206 | ||
|
|
605df8c165 | ||
|
|
0f30f776bb | ||
|
|
3de53ecf4e | ||
|
|
5945ca3cae | ||
|
|
91a52f278c | ||
|
|
80c5151ab3 | ||
|
|
b4b41e038d | ||
|
|
6637fb7bbf | ||
|
|
4a4b37c255 | ||
|
|
d729387c8c | ||
|
|
bdf3c54189 | ||
|
|
958dd78ceb | ||
|
|
8be58e3a21 | ||
|
|
488f75b6e0 | ||
|
|
dd3d3040ac | ||
|
|
03da178335 | ||
|
|
b1958ac483 |
Generated
+21
-21
@@ -118,9 +118,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.9.4"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1"
|
||||
checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
"cpubits",
|
||||
@@ -3045,9 +3045,9 @@ checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.44"
|
||||
version = "0.8.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89253175e704ab869b04f9db224d38630e0211a53841a79181deae0889e169f5"
|
||||
checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"core_detect",
|
||||
@@ -4837,9 +4837,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.35"
|
||||
version = "0.4.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
||||
|
||||
[[package]]
|
||||
name = "lru-slab"
|
||||
@@ -6460,9 +6460,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.13.2"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
|
||||
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -6472,9 +6472,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.19"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
|
||||
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -6483,9 +6483,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.12"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "renderdoc-sys"
|
||||
@@ -7862,9 +7862,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.21+spec-1.1.0"
|
||||
version = "0.25.15+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88497dab46de5bf343ec66b05c251e48c6213f3e9170c70a70a823f7abe886a4"
|
||||
checksum = "1340ea94a5856333492c9064b02c778b191dd2c853778d9609debdcdfea3a614"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde_core",
|
||||
@@ -8075,9 +8075,9 @@ checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-script"
|
||||
version = "0.5.9"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa04c955db05429d464c74d495c1ee677e1866e783a4c3747f9c0cef7756cabf"
|
||||
checksum = "383ad40bb927465ec0ce7720e033cb4ca06912855fc35db31b5755d0de75b1ee"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
@@ -9513,11 +9513,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wuff"
|
||||
version = "0.2.10"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6a992b57b3d1ee972b2e3fd9225e44793104d49818836dd812d5459187712dd"
|
||||
checksum = "200a7b806377b65f1ff9a985874332f15357c87e5dd7855f35f06dade95b8b3d"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.1",
|
||||
"brotli-decompressor 5.0.3",
|
||||
"bytes",
|
||||
"flate2",
|
||||
]
|
||||
@@ -9865,9 +9865,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.9.2"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
|
||||
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
|
||||
dependencies = [
|
||||
"zeroize_derive",
|
||||
]
|
||||
|
||||
@@ -745,6 +745,15 @@ fn main() -> eframe::Result {
|
||||
}
|
||||
let spool = Spool::new(host.jobs_shared().clone());
|
||||
let mut app = WordApp::new(session, services(spool.clone(), intake, nightly)).with_host(host).with_settings(settings.clone());
|
||||
// Drawn by the processor (WARP, llvmpipe; #2221), animations that follow the system stop.
|
||||
if let Some(state) = &cc.wgpu_render_state {
|
||||
let info = state.adapter.get_info();
|
||||
let software = info.device_type == eframe::wgpu::DeviceType::Cpu;
|
||||
if software {
|
||||
log::warn!("graphics: drawing in software on {} ({:?}): animations that follow the system are off", info.name, info.backend);
|
||||
}
|
||||
app.set_software_drawing(software);
|
||||
}
|
||||
// PLAN: writer note 9 puts `with_settings` after `with_control`; it comes first here because
|
||||
// the region check below reads the saved region the settings apply.
|
||||
if std::env::var("WORDCRAFT_FILE_DIALOG").is_ok_and(|v| v.trim().eq_ignore_ascii_case("builtin")) {
|
||||
|
||||
@@ -9806,6 +9806,9 @@ fn insert_icon_places_a_picture_of_the_requested_size_that_saves_and_recolours()
|
||||
#[test]
|
||||
fn markup_pdf_takes_the_track_changes_option_colours() {
|
||||
let mut s = Session::new(wordcraft_doc::Document::from_text("Governed by Kansas law."));
|
||||
// A fixed creation date: without one each PDF is stamped with the current time, and the
|
||||
// exports compared below differ when a clock second ticks over between them.
|
||||
s.doc.core.created = "2026-01-01T00:00:00Z".into();
|
||||
s.run("review.trackChanges", &json!({"value": true})).unwrap();
|
||||
s.run("select.text", &json!({"text": "Kansas"})).unwrap();
|
||||
s.run("text.insert", &json!({"text": "Missouri"})).unwrap();
|
||||
|
||||
@@ -120,6 +120,7 @@ impl WordApp {
|
||||
control: None,
|
||||
capture_token: 0,
|
||||
native_scale: 1.0,
|
||||
software_drawing: false,
|
||||
auto_scale_limit: f32::INFINITY,
|
||||
legacy_interface_size: None,
|
||||
applied_editing: None,
|
||||
@@ -214,11 +215,18 @@ impl WordApp {
|
||||
.wheel_speed(WheelSpeed::new(line, point))
|
||||
.alt_code_pages(AltCodePages::new(ansi, oem))
|
||||
.set(ComponentSet::Productivity);
|
||||
env.motion = self.ui.animations.motion();
|
||||
env.motion = self.ui.animations.motion_drawn(self.software_drawing);
|
||||
env.sizes = std::sync::Arc::clone(&APP_SIZES);
|
||||
env
|
||||
}
|
||||
|
||||
/// The window is drawn by the processor (`on`), as the desktop app finds once it knows the
|
||||
/// graphics adapter. Animations that follow the system then stop: the caret blinks without
|
||||
/// fading or gliding, and nothing fades, slides or spins. On in File › Options still animates.
|
||||
pub fn set_software_drawing(&mut self, on: bool) {
|
||||
self.software_drawing = on;
|
||||
}
|
||||
|
||||
/// What this frame's mode and motion choices resolve to: the system's answer replaces `System`.
|
||||
/// Before the first frame there is no context to ask, and the system reports nothing.
|
||||
pub(crate) fn resolved_root(&self) -> ResolvedRoot {
|
||||
|
||||
@@ -2605,3 +2605,115 @@ fn the_caret_blinks_only_while_the_window_is_active() {
|
||||
h.app_frame();
|
||||
assert!(next_frame(&h) <= blink, "active again, the caret blinks again");
|
||||
}
|
||||
|
||||
/// #5602: clicking a picture that is partly off the window's edge, or taller than a small
|
||||
/// window, selects it without scrolling the view (the selection used to be followed like a
|
||||
/// caret).
|
||||
#[test]
|
||||
fn clicking_a_picture_in_a_small_window_does_not_scroll_the_view() {
|
||||
for width in [160, 700] {
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
for i in 0..70 {
|
||||
a.run("text.insert", json!({"text": format!("Line {i} of the body text")})).unwrap();
|
||||
a.run("text.newParagraph", json!({})).unwrap();
|
||||
}
|
||||
a.run("view.commentsPane", json!({"value": false})).unwrap();
|
||||
a.run("caret.docStart", json!({})).unwrap();
|
||||
let img = image::RgbaImage::from_pixel(40, 20, image::Rgba([200, 30, 30, 255]));
|
||||
let png = wordcraft_geom::picture::encode_format(&image::DynamicImage::ImageRgba8(img).clone(), image::ImageFormat::Png).unwrap();
|
||||
a.run("insert.picture", json!({"data": wordcraft_engine::cmd::insert::base64_encode(&png), "width": width})).unwrap();
|
||||
let pos = wordcraft_engine::cmd::objects::selected(&a.session).unwrap().0;
|
||||
a.session.sel = wordcraft_engine::Selection::caret(Pos::body(3, 0));
|
||||
let mut h = crate::test_harness::builder().with_size(egui::vec2(900.0, 420.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
steps(&mut h, 6);
|
||||
let rect = h.state_mut().session.layout().object(&pos, 0).expect("the picture is laid out").rect;
|
||||
let corner = |h: &mut H, x: f32, y: f32| page_to_screen(h.state_mut(), 0, x, y).expect("the picture is on screen");
|
||||
let view = h.state().canvas.view_rect().expect("the canvas has been shown");
|
||||
// Scroll until the picture's top edge is above the window's: part of it is out of view.
|
||||
let top = corner(&mut h, rect.x, rect.y).y;
|
||||
h.state_mut().canvas.view.offset.1 += f64::from(top - view.top()) + 40.0;
|
||||
steps(&mut h, 6);
|
||||
let before = h.state().canvas.view.offset;
|
||||
let (min, max) = (corner(&mut h, rect.x, rect.y), corner(&mut h, rect.x + rect.w, rect.y + rect.h));
|
||||
let shown = egui::Rect::from_min_max(min, max);
|
||||
assert!(shown.top() < view.top(), "{width}: the picture starts above the window: {shown:?} {view:?}");
|
||||
let at = pos2(shown.center().x, shown.center().y.clamp(view.top() + 10.0, view.bottom() - 10.0));
|
||||
assert!(shown.contains(at), "{width}: the click lands on the picture {shown:?} {view:?}");
|
||||
h.event(egui::Event::PointerMoved(at));
|
||||
h.app_frame();
|
||||
for pressed in [true, false] {
|
||||
h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() });
|
||||
h.app_frame();
|
||||
}
|
||||
steps(&mut h, 10);
|
||||
assert_eq!(wordcraft_engine::cmd::objects::selected(&h.state().session).map(|o| o.0), Some(pos), "{width}: the picture is selected");
|
||||
assert_eq!(h.state().canvas.view.offset, before, "{width}: the view stayed where it was");
|
||||
}
|
||||
}
|
||||
|
||||
/// #5602: Shift-clicking a picture that is partly above the window's top edge adds it to the
|
||||
/// selection without scrolling the view back to the picture selected first.
|
||||
#[test]
|
||||
fn shift_clicking_a_picture_does_not_scroll_the_view() {
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default());
|
||||
let img = image::RgbaImage::from_pixel(40, 20, image::Rgba([200, 30, 30, 255]));
|
||||
let png = wordcraft_geom::picture::encode_format(&image::DynamicImage::ImageRgba8(img).clone(), image::ImageFormat::Png).unwrap();
|
||||
let data = wordcraft_engine::cmd::insert::base64_encode(&png);
|
||||
a.run("insert.picture", json!({"data": data, "width": 160})).unwrap();
|
||||
let first = wordcraft_engine::cmd::objects::selected(&a.session).unwrap().0;
|
||||
// The inserted picture is selected: a caret after it, or typing would replace it.
|
||||
a.run("caret.docEnd", json!({})).unwrap();
|
||||
for i in 0..10 {
|
||||
a.run("text.insert", json!({"text": format!("Line {i} of the body text")})).unwrap();
|
||||
a.run("text.newParagraph", json!({})).unwrap();
|
||||
}
|
||||
a.run("insert.picture", json!({"data": data, "width": 160})).unwrap();
|
||||
let second = wordcraft_engine::cmd::objects::selected(&a.session).unwrap().0;
|
||||
assert_ne!(first, second);
|
||||
a.run("view.commentsPane", json!({"value": false})).unwrap();
|
||||
let end = Pos { off: first.off + wordcraft_doc::para::OBJ.len_utf8(), ..first.clone() };
|
||||
a.run("select.range", json!({"anchor": first, "focus": end})).unwrap();
|
||||
let mut h = crate::test_harness::builder().with_size(egui::vec2(900.0, 420.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
steps(&mut h, 6);
|
||||
let rect = h.state_mut().session.layout().object(&second, 0).expect("the second picture is laid out").rect;
|
||||
let corner = |h: &mut H, x: f32, y: f32| page_to_screen(h.state_mut(), 0, x, y).expect("the picture is on screen");
|
||||
let view = h.state().canvas.view_rect().expect("the canvas has been shown");
|
||||
// Scroll until the second picture's top edge is above the window's: part of it is out of view.
|
||||
let top = corner(&mut h, rect.x, rect.y).y;
|
||||
h.state_mut().canvas.view.offset.1 += f64::from(top - view.top()) + 20.0;
|
||||
steps(&mut h, 6);
|
||||
let before = h.state().canvas.view.offset;
|
||||
let shown = egui::Rect::from_min_max(corner(&mut h, rect.x, rect.y), corner(&mut h, rect.x + rect.w, rect.y + rect.h));
|
||||
assert!(shown.top() < view.top(), "the picture starts above the window: {shown:?} {view:?}");
|
||||
let at = pos2(shown.center().x, shown.center().y.clamp(view.top() + 10.0, view.bottom() - 10.0));
|
||||
assert!(shown.contains(at), "the click lands on the picture {shown:?} {view:?}");
|
||||
assert_eq!(
|
||||
wordcraft_engine::cmd::objects::picked_objects(&h.state().session),
|
||||
vec![first.clone()],
|
||||
"the first picture is selected before the click: {:?}",
|
||||
h.state().session.sel
|
||||
);
|
||||
h.event(egui::Event::PointerMoved(at));
|
||||
h.app_frame();
|
||||
let press = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::SHIFT };
|
||||
h.event_modifiers(press, egui::Modifiers::SHIFT);
|
||||
h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() });
|
||||
steps(&mut h, 10);
|
||||
let picked = wordcraft_engine::cmd::objects::picked_objects(&h.state().session);
|
||||
assert!(picked.contains(&first) && picked.contains(&second), "both pictures are selected: {picked:?} {:?} at {at:?}", h.state().session.sel);
|
||||
assert_eq!(h.state().canvas.view.offset, before, "the view stayed where it was");
|
||||
}
|
||||
|
||||
@@ -73,8 +73,15 @@ fn note_global_names() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Text egui itself draws over the app in debug builds, such as its warning that `request_discard`
|
||||
/// was called several frames in a row. The app does not draw it, so it is not interface text.
|
||||
fn egui_debug_text(text: &str) -> bool {
|
||||
text.starts_with("egui PERF WARNING:")
|
||||
}
|
||||
|
||||
fn texts(shape: &egui::Shape, out: &mut Vec<String>) {
|
||||
match shape {
|
||||
egui::Shape::Text(t) if egui_debug_text(t.galley.text()) => {}
|
||||
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)),
|
||||
_ => {}
|
||||
@@ -341,6 +348,34 @@ fn math_placeholders_are_exact_math_input_only() {
|
||||
assert!(!set.contains("Translate"), "ordinary interface wording is not exempt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn egui_debug_warnings_are_not_interface_text() {
|
||||
// A discard in every pass makes egui draw its PERF WARNING from the fourth frame on.
|
||||
let ctx = egui::Context::default();
|
||||
let mut shapes = Vec::new();
|
||||
for _ in 0..5 {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| ui.ctx().request_discard("test"));
|
||||
out.textures_delta.clear();
|
||||
shapes = out.shapes;
|
||||
}
|
||||
let raw: Vec<String> = shapes
|
||||
.iter()
|
||||
.filter_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) => Some(t.galley.text().to_string()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
// egui draws the warning only in builds with `debug_assertions`.
|
||||
if cfg!(debug_assertions) {
|
||||
assert!(raw.iter().any(|t| t.starts_with("egui PERF WARNING:")), "egui draws its warning: {raw:?}");
|
||||
}
|
||||
let mut drawn = Vec::new();
|
||||
for s in &shapes {
|
||||
texts(&s.shape, &mut drawn);
|
||||
}
|
||||
assert!(drawn.is_empty(), "the audit reads no egui debug text: {drawn:?}");
|
||||
}
|
||||
|
||||
/// Runtime data is exempt (links, the clock's dates and times), wording is not (#7463), and
|
||||
/// Check for Updates never reaches the network.
|
||||
#[test]
|
||||
@@ -743,6 +778,7 @@ fn disabled_reasons() -> std::collections::BTreeSet<String> {
|
||||
fn frame_at(ctx: &egui::Context, app: &mut WordApp, width: f32) -> Vec<(String, f32)> {
|
||||
fn collect(shape: &egui::Shape, out: &mut Vec<(String, f32)>) {
|
||||
match shape {
|
||||
egui::Shape::Text(t) if egui_debug_text(t.galley.text()) => {}
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.pos.x)),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)),
|
||||
_ => {}
|
||||
|
||||
@@ -527,7 +527,14 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
|
||||
let ctx = ui.ctx().clone();
|
||||
// Alt during an object drag is part of the drag (Alt moves an object freely), not a keytip tap.
|
||||
// PLAN: `CanvasState::object_gesture` is canvas-w9's (cv.A10).
|
||||
let enabled = app.ui.keytips_enabled && app.canvas.object_gesture().is_none();
|
||||
let mut enabled = app.ui.keytips_enabled && app.canvas.object_gesture().is_none();
|
||||
|
||||
let backstage_key = egui::Id::unique(("wc_backstage_keytips_active", app.windows.shown()));
|
||||
let was_backstage_keytips: bool = ctx.data(|d| d.get_temp(backstage_key)).unwrap_or(false);
|
||||
if was_backstage_keytips && !app.ui.backstage {
|
||||
// #4981: the Backstage closed while its badges show (the back chevron, a mouse Save) ends them.
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
// A tab the ribbon shows has an element id this pass; one in the overflow menu has none and gets no badge.
|
||||
// PLAN: assumed `RibbonOutput::tab_ids: Vec<(T, egui::Id)>` (ribbon-w3, S-L361).
|
||||
@@ -579,6 +586,7 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
|
||||
app.keytip_cache = Some(cache);
|
||||
// PLAN: `WordApp::keytips_active` is app-hub's (rb.A11).
|
||||
app.keytips_active = out.active;
|
||||
ctx.data_mut(|d| d.insert_temp(backstage_key, app.ui.backstage && out.active));
|
||||
if let Some(tab) = out.tab.as_deref().and_then(tab_of_badge) {
|
||||
let _ = app.run("ui.tab", serde_json::json!({ "tab": tab }));
|
||||
}
|
||||
|
||||
@@ -582,3 +582,32 @@ fn keytips_update_controls_when_switching_tabs() {
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(bold(&mut h), "Home keytip badge {bold_badge} runs format.bold after switching back from Insert");
|
||||
}
|
||||
|
||||
/// #4981: the Backstage closed while its badges show (the back chevron, a mouse Save)
|
||||
/// ends them. The next letter is typed, and never picks a page with the Backstage gone: C used
|
||||
/// to close the document and S to save it.
|
||||
#[test]
|
||||
fn closing_the_backstage_ends_its_keytips() {
|
||||
let mut h = harness(app());
|
||||
let key = |key| key_event(key, true, egui::Modifiers::NONE);
|
||||
h.input_mut().events.push(key(egui::Key::F10));
|
||||
crate::test_harness::frame(&mut h);
|
||||
assert!(h.state().keytips_active, "F10 activates keytips");
|
||||
h.input_mut().events.extend([key(egui::Key::F), egui::Event::Text("f".into())]);
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
assert!(h.state().ui.backstage, "F opens Backstage");
|
||||
assert!(h.state().keytips_active, "keytips active in Backstage");
|
||||
|
||||
// What the back chevron does.
|
||||
h.state_mut().ui.backstage = false;
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().canvas.focus_page(&ctx);
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
assert!(!h.state().keytips_active, "the badges end with the Backstage");
|
||||
h.input_mut().events.extend([key(egui::Key::C), egui::Event::Text("c".into())]);
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
assert!(!h.state().keytips_active);
|
||||
assert!(h.state().has_document(), "C does not close the document");
|
||||
assert!(!h.state().ui.backstage);
|
||||
assert_eq!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body).trim(), "c", "C is typed");
|
||||
}
|
||||
|
||||
@@ -458,6 +458,11 @@ pub struct WordApp {
|
||||
/// The display scale (native pixels per point) seen in the last frame, 1.0 before the first;
|
||||
/// `ui.interfaceSize` reports the size Auto draws at with it.
|
||||
native_scale: f32,
|
||||
/// The window is drawn by the processor, not a graphics card (WARP on Windows, llvmpipe on
|
||||
/// Linux; #2221): the desktop app sets it once it knows the adapter. Every animated frame is
|
||||
/// then the whole window drawn in software, so animations that follow the system stop
|
||||
/// ([`WordApp::set_software_drawing`]).
|
||||
software_drawing: bool,
|
||||
/// The most pixels per point Auto may draw at on this screen ([`theme::auto_scale_limit`], #4030).
|
||||
auto_scale_limit: f32,
|
||||
/// A pre-#822 interface size (percent on top of the display scale) waiting for the first frame
|
||||
|
||||
@@ -564,7 +564,7 @@ impl ObjectGesture {
|
||||
|| (mods.cmd && mods.shift && wordcraft_engine::cmd::objects::picked_objects(&app.session).contains(&object.pos()));
|
||||
let shift_only = mods.shift && !mods.cmd;
|
||||
if adding && selected(app).is_some() && (shift_only || !again) {
|
||||
let _ = app.run("select.addObject", json!({"pos": object.pos()}));
|
||||
let _ = app.run_keep_view("select.addObject", json!({"pos": object.pos()}));
|
||||
return Some(Self::inert());
|
||||
}
|
||||
// While editing a header/footer, a click on its Behind Text picture where no header/footer
|
||||
@@ -582,7 +582,8 @@ impl ObjectGesture {
|
||||
}
|
||||
let pos = object.pos();
|
||||
let end = Pos { off: pos.off + OBJ.len_utf8(), ..pos.clone() };
|
||||
let _ = app.run("select.range", json!({"anchor": pos, "focus": end}));
|
||||
// Under the pointer, so in view: the selection is not followed like a caret (#5602).
|
||||
let _ = app.run_keep_view("select.range", json!({"anchor": pos, "focus": end}));
|
||||
// A header/footer picture repeats on every page: select the copy clicked, as `select_at` does.
|
||||
app.session.page_hint = object.page;
|
||||
if selected(app).is_none() {
|
||||
@@ -604,7 +605,7 @@ impl ObjectGesture {
|
||||
if self.pending_behind {
|
||||
let pos = object.pos();
|
||||
let end = Pos { off: pos.off + OBJ.len_utf8(), ..pos.clone() };
|
||||
let _ = app.run("select.range", json!({"anchor": pos, "focus": end}));
|
||||
let _ = app.run_keep_view("select.range", json!({"anchor": pos, "focus": end}));
|
||||
// The text click path has been tracking the pointer until it became a drag.
|
||||
app.canvas.cancel_text_drag();
|
||||
self.pending_behind = false;
|
||||
@@ -758,8 +759,8 @@ fn press_member(app: &mut WordApp, layout: &DocLayout, body: &PageBody, at: Pos2
|
||||
}
|
||||
let pos = object.pos();
|
||||
let end = Pos { off: pos.off + OBJ.len_utf8(), ..pos.clone() };
|
||||
let _ = app.run("select.range", json!({"anchor": pos, "focus": end}));
|
||||
if app.run("select.member", json!({"index": index})).is_err() {
|
||||
let _ = app.run_keep_view("select.range", json!({"anchor": pos, "focus": end}));
|
||||
if app.run_keep_view("select.member", json!({"index": index})).is_err() {
|
||||
return Some(ObjectGesture::inert());
|
||||
}
|
||||
ObjectGesture::start(body, object, at)
|
||||
@@ -911,7 +912,10 @@ pub fn select_at(app: &mut WordApp, layout: &DocLayout, body: &PageBody, at: Pos
|
||||
// Already selected (alone or among several picked for Group): keep the selection.
|
||||
if !wordcraft_engine::cmd::objects::picked_objects(&app.session).contains(&pos) {
|
||||
let end = Pos { off: pos.off + OBJ.len_utf8(), ..pos.clone() };
|
||||
let _ = app.run("select.range", json!({"anchor": pos, "focus": end}));
|
||||
// The object is under the pointer, so it is in view: following the new selection would
|
||||
// scroll a picture taller than the window, or one partly off its edge, as it is clicked
|
||||
// (#5602).
|
||||
let _ = app.run_keep_view("select.range", json!({"anchor": pos, "focus": end}));
|
||||
}
|
||||
// A header/footer picture repeats on every page: its frame belongs on the page clicked, not
|
||||
// the one last edited.
|
||||
|
||||
@@ -221,6 +221,20 @@ fn animation_effects_is_an_accessibility_option() {
|
||||
assert_eq!(system_help(&h), None, "only said while the system is followed");
|
||||
}
|
||||
|
||||
/// #2221: a window drawn by the processor stops the animations that follow the system; On still plays.
|
||||
#[test]
|
||||
fn software_drawing_stops_animations_that_follow_the_system() {
|
||||
use crate::theme::Animations;
|
||||
use craft::behavior::MotionMode;
|
||||
let mut a = app();
|
||||
assert_eq!(a.ui.animations, Animations::System);
|
||||
assert_ne!(a.resolved_root().motion, MotionMode::Off, "a graphics card animates");
|
||||
a.set_software_drawing(true);
|
||||
assert_eq!(a.resolved_root().motion, MotionMode::Off);
|
||||
a.ui.animations = Animations::On;
|
||||
assert_eq!(a.resolved_root().motion, MotionMode::Full, "the person's own choice stands");
|
||||
}
|
||||
|
||||
/// #838: in a Polish region lengths read `2,54 cm` (the region's unit and decimal comma).
|
||||
#[test]
|
||||
fn length_fields_follow_the_region() {
|
||||
|
||||
@@ -351,7 +351,7 @@ pub(super) fn home(row: &mut RibbonRow<'_>, app: &mut WordApp) {
|
||||
Divider::horizontal().show(ui);
|
||||
MenuItem::command(CommandRef::new("list.define")).label(tl!("Define New Multilevel List…").to_string()).show(ui);
|
||||
Divider::horizontal().show(ui);
|
||||
for lv in 0..5u64 {
|
||||
for lv in 0..9u64 {
|
||||
MenuItem::command(CommandRef::with_params("para.listLevel", json!({"level": lv})))
|
||||
.label(format!("Change to Level {}", lv + 1))
|
||||
.show(ui);
|
||||
|
||||
@@ -391,6 +391,34 @@ fn find_shortcut_focuses_find_what() {
|
||||
assert!(fields["find"].as_str().unwrap_or_default().ends_with("abc"), "typing went into Find what: {fields:?}");
|
||||
}
|
||||
|
||||
/// #1610: opening a hyperlink must direct typing and paste into its address.
|
||||
#[test]
|
||||
fn hyperlink_shortcut_focuses_address_and_preserves_document() {
|
||||
let mut a = app();
|
||||
a.run("text.insert", json!({"text": "Keep this text"})).unwrap();
|
||||
a.run("select.text", json!({"text": "Keep this text"})).unwrap();
|
||||
let mut h = harness(a);
|
||||
h.run_steps(2);
|
||||
|
||||
for (event, expected) in [
|
||||
(egui::Event::Paste("https://example.com".into()), "https://example.com"),
|
||||
(egui::Event::Text("https://example.org".into()), "https://example.org"),
|
||||
] {
|
||||
press(&mut h, egui::Key::K, egui::Modifiers::COMMAND);
|
||||
assert!(h.state().dialog_host.open_dialogs().iter().any(|d| d.key.as_deref() == Some("link")), "Link dialog open");
|
||||
h.event(event);
|
||||
h.run_steps(2);
|
||||
let address = h.get_by_label("Address:").value().unwrap_or_default();
|
||||
assert_eq!(address, expected, "input replaces the initial address");
|
||||
let display = h.get_by_label("Text to display:").value().unwrap_or_default();
|
||||
assert_eq!(display, "Keep this text");
|
||||
assert_eq!(body_text(h.state()), "Keep this text");
|
||||
press(&mut h, egui::Key::Escape, egui::Modifiers::NONE);
|
||||
assert!(h.state().dialog_host.open_dialogs().is_empty(), "Cancel closes the dialog");
|
||||
assert_eq!(h.state().session.selected_text(), "Keep this text", "Cancel preserves selection");
|
||||
}
|
||||
}
|
||||
|
||||
/// The key of the dialog a command opened, read off its reply.
|
||||
fn pending_of(reply: &Value) -> Option<&str> {
|
||||
reply.get("pending").and_then(Value::as_str)
|
||||
|
||||
@@ -231,6 +231,12 @@ impl Animations {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Self::motion`] for a window drawn by the processor when `software`: `System` is then no
|
||||
/// motion at all, since every animated frame is the whole window drawn in software (#2221).
|
||||
pub fn motion_drawn(self, software: bool) -> MotionChoice {
|
||||
if software && self == Animations::System { MotionChoice::Off } else { self.motion() }
|
||||
}
|
||||
|
||||
/// The runtime's motion choice: `System` is the OS's reduced-motion answer, else full motion.
|
||||
pub fn motion(self) -> MotionChoice {
|
||||
match self {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::font_manager::Catalog;
|
||||
use craft::font_manager::craft_font_catalog::{Limits, Source};
|
||||
use craft::font_manager::craft_font_catalog::{FontEnv, Limits, Os, Source};
|
||||
use craft::font_manager::picker::FontPickerSettings;
|
||||
use craft::ui::buttons::IconButton;
|
||||
use craft::ui::contract::{Props as _, Show as _};
|
||||
use egui::Key;
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _};
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use egui::{Key, vec2};
|
||||
use egui_kittest::kittest::{By, NodeT, Queryable};
|
||||
use serde_json::{Value, json};
|
||||
use wordcraft_engine::Session;
|
||||
|
||||
@@ -222,3 +226,78 @@ fn drawn_buttons_fade_in_on_hover_and_darken_while_pressed() {
|
||||
let fill_after = find_button_fill(&h.output().shapes, rect);
|
||||
assert_eq!(fill_after, None, "Save button must clear hover fill after unhovering");
|
||||
}
|
||||
|
||||
/// #7317: typing in WordCraft's `font_picker` updates the popup list on the same frame as the
|
||||
/// keystroke, shows the Recently Used Fonts section again when cleared, and narrows immediately
|
||||
/// on subsequent typing.
|
||||
#[test]
|
||||
fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
|
||||
let env = FontEnv { os: Os::None, ..Default::default() };
|
||||
let catalog = Arc::new(Catalog::new(env).with_font_service(false));
|
||||
catalog.set_app_dirs(vec![Path::new(env!("CARGO_MANIFEST_DIR")).join("../../assets/fonts")]);
|
||||
catalog.rescan();
|
||||
assert!(catalog.families().iter().any(|f| f == "Inter"), "fixed catalog loaded assets/fonts");
|
||||
|
||||
let mut settings = FontPickerSettings::default();
|
||||
settings.recent = vec!["Source Serif 4".to_string()];
|
||||
let mut family = String::new();
|
||||
|
||||
let mut h = crate::test_harness::builder().with_size(vec2(400.0, 900.0)).build_ui(move |ui| {
|
||||
let _ = super::font_picker("Font", Bind::bound(&mut family), &catalog, Bind::bound(&mut settings), &[], None).show(ui);
|
||||
});
|
||||
h.run_steps(2);
|
||||
|
||||
h.get(By::new().role(Role::TextInput)).click();
|
||||
h.run_steps(2);
|
||||
|
||||
let erase = || {
|
||||
vec![
|
||||
egui::Event::Key { key: Key::Backspace, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE },
|
||||
egui::Event::Key { key: Key::Backspace, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE },
|
||||
]
|
||||
};
|
||||
let send = |h: &mut egui_kittest::Harness<'static, ()>, events: Vec<egui::Event>| {
|
||||
for ev in events {
|
||||
h.event(ev);
|
||||
}
|
||||
h.step();
|
||||
};
|
||||
|
||||
let frames: [(Vec<egui::Event>, &[&str], &[&str]); 7] = [
|
||||
// Typing an unmatched query clears the list; one Backspace restores recents + all fonts on that frame.
|
||||
(vec![egui::Event::Text("x".into())], &[], &["Source Serif 4", "Inter", "JetBrains Mono"]),
|
||||
(erase(), &["Source Serif 4", "Inter", "JetBrains Mono"], &[]),
|
||||
// Typing narrows immediately on the keystroke frame and excludes non-matching families.
|
||||
(vec![egui::Event::Text("jet".into())], &["JetBrains Mono"], &["Inter", "Source Serif 4"]),
|
||||
(erase(), &["JetBrains Mono"], &["Inter"]),
|
||||
(erase(), &["JetBrains Mono"], &["Inter"]),
|
||||
(erase(), &["Source Serif 4", "Inter", "JetBrains Mono"], &[]),
|
||||
(vec![egui::Event::Text("int".into())], &["Inter"], &["JetBrains Mono"]),
|
||||
];
|
||||
|
||||
fn collect_texts(shape: &egui::Shape, out: &mut Vec<String>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(children) => {
|
||||
for child in children {
|
||||
collect_texts(child, out);
|
||||
}
|
||||
}
|
||||
egui::Shape::Text(text) => out.push(text.galley.text().to_owned()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
for (n, (events, expected, excluded)) in frames.into_iter().enumerate() {
|
||||
send(&mut h, events);
|
||||
let mut texts = Vec::new();
|
||||
for clipped in &h.output().shapes {
|
||||
collect_texts(&clipped.shape, &mut texts);
|
||||
}
|
||||
for label in expected {
|
||||
assert!(texts.iter().any(|t| t == label), "keystroke {n}: expected {label:?} to be drawn on the frame, got texts: {texts:?}");
|
||||
}
|
||||
for label in excluded {
|
||||
assert!(texts.iter().all(|t| t != label), "keystroke {n}: expected {label:?} to be filtered out on the frame, got texts: {texts:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ impl WordApp {
|
||||
ime_origin: _,
|
||||
user_origin: _,
|
||||
native_scale: _,
|
||||
software_drawing: _,
|
||||
auto_scale_limit: _,
|
||||
legacy_interface_size: _,
|
||||
applied_editing: _,
|
||||
|
||||
@@ -211,8 +211,13 @@ pub fn poll(app: &mut WordApp, ctx: &egui::Context) {
|
||||
}
|
||||
match r {
|
||||
Ok(o) => {
|
||||
let first_err = o.errors.first().cloned();
|
||||
app.zotero.last = Some(json!({"command": name, "completed": o.completed, "calls": o.calls, "errors": o.errors}));
|
||||
app.status(if o.completed { tl!("Zotero: done") } else { tl!("Zotero: cancelled") });
|
||||
if let Some(err) = first_err {
|
||||
app.status(format!("{}: {err}", tl!("Zotero")));
|
||||
} else {
|
||||
app.status(if o.completed { tl!("Zotero: done") } else { tl!("Zotero: cancelled") });
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
app.zotero.last = Some(json!({"command": name, "error": e}));
|
||||
@@ -386,4 +391,26 @@ mod tests {
|
||||
let last = status["last"].clone();
|
||||
assert!(last["error"].as_str().is_some_and(|e| !e.is_empty()), "{last}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_bridge_call_surfaces_error_in_status() {
|
||||
let (addr, server) = fake_zotero(vec![
|
||||
json!(["Application_getActiveDocument", [3]]),
|
||||
json!(["Field_setText", [1, 999, "text", false]]),
|
||||
json!(["Document_complete", [1]]),
|
||||
]);
|
||||
let mut app = WordApp::new(Session::new(Document::from_text("Hello")), Services::default());
|
||||
app.zotero.options.addr = addr;
|
||||
let ctx = egui::Context::default();
|
||||
app.run("ui.zotero.addEditBibliography", json!({})).unwrap();
|
||||
pump(&mut app, &ctx, |a| a.zotero.busy.is_none());
|
||||
server.join().unwrap();
|
||||
let last = app.run("ui.zotero.status", json!({})).unwrap()["last"].clone();
|
||||
assert_eq!(last["errors"].as_array().map(Vec::len), Some(1));
|
||||
assert!(
|
||||
app.status.as_ref().is_some_and(|s| s.text.contains("no field with id 999")),
|
||||
"status was {:?}",
|
||||
app.status.as_ref().map(|s| &s.text)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,3 +630,35 @@ fn citation_at_document_end_stays_closed() {
|
||||
let back = wordcraft_engine::io::open_bytes("probe.docx", &bytes).unwrap();
|
||||
assert_eq!(back.field_ranges(StoryRef::Body).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn note_style_bibliography_populates_after_switching_citations_to_footnotes() {
|
||||
let mut z = Z::new("Claim one.\n\nBibliography:\n", 9);
|
||||
z.begin();
|
||||
let cite = z.cite(0, "(Doe 2020)");
|
||||
z.ok("Document_complete", json!([1]));
|
||||
|
||||
// Switch to a notes-and-bibliography style (e.g. Chicago 18th): citation moves to a footnote.
|
||||
z.begin();
|
||||
z.ok("Document_convert", json!([1, [cite], ["ReferenceMark"], [1], 1]));
|
||||
z.ok("Document_complete", json!([1]));
|
||||
assert_eq!(note_count(&z.s.doc, wordcraft_doc::PartKind::Footnote), 1);
|
||||
|
||||
// Place the caret at the end of the body and insert the bibliography.
|
||||
let last_path = z.s.doc.para_paths(StoryRef::Body).pop().unwrap();
|
||||
z.s.sel = Selection::caret(Pos::new(StoryRef::Body, last_path, 0));
|
||||
z.begin();
|
||||
let r = z.ok("Document_insertField", json!([1, "ReferenceMark", 0]));
|
||||
let bib_id = r[0].as_u64().unwrap();
|
||||
z.ok("Field_setCode", json!([1, bib_id, "TEMP"]));
|
||||
assert!(!z.ok("Field_getText", json!([1, bib_id])).as_str().unwrap().is_empty());
|
||||
z.ok("Field_setCode", json!([1, bib_id, BIBL]));
|
||||
z.ok("Document_setBibliographyStyle", json!([1, -720, 720, 240, 240, [], 0]));
|
||||
z.ok("Field_setText", json!([1, bib_id, r"{\rtf Doe, John. {\i Title}. 2020.\par}", true]));
|
||||
z.ok("Document_complete", json!([1]));
|
||||
|
||||
assert!(z.text().contains("Doe, John. Title. 2020."), "body was {:?}", z.text());
|
||||
let f = z.ok("Document_getFields", json!([1, "ReferenceMark"]));
|
||||
assert_eq!(f[0], json!([cite, bib_id]));
|
||||
assert_eq!(f[2], json!([1, 0]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user