From 057d3258fb736b4122cdf651fb715409e7c1eed9 Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 09:37:15 -0700 Subject: [PATCH 1/6] fix(xtask): fail the standalone i18n audit on untranslated IDs (#700) cargo xtask i18n-audit now counts untranslated locale entries as problems, so the nightly warning job goes orange. cargo xtask ci keeps reporting them without failing. Co-Authored-By: Claude Opus 5.5 --- xtask/src/i18n_audit.rs | 51 ++++++++++++++++++++++++++++++++++++++++- xtask/src/main.rs | 10 ++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/xtask/src/i18n_audit.rs b/xtask/src/i18n_audit.rs index 5c632880f..7c0d9444b 100644 --- a/xtask/src/i18n_audit.rs +++ b/xtask/src/i18n_audit.rs @@ -508,7 +508,19 @@ fn collect_rust_files(root: &Path) -> Result, String> { Ok(files) } +/// The standalone audit (`cargo xtask i18n-audit`): untranslated locale entries count as +/// problems, so the nightly warning job fails when a locale falls behind English. pub(crate) fn run(root: &Path) -> Result<(), String> { + audit(root, true) +} + +/// The audit as run by `cargo xtask ci`: source and catalog problems fail, untranslated +/// locale entries are only reported, so an incomplete translation never blocks a change. +pub(crate) fn run_for_ci(root: &Path) -> Result<(), String> { + audit(root, false) +} + +fn audit(root: &Path, strict_translations: bool) -> Result<(), String> { let catalogs = load_catalogs(root).map_err(|problems| problems.join("\n"))?; let mut problems = validate_catalogs(&catalogs); let english_ids: BTreeSet = catalogs.english.keys().cloned().collect(); @@ -545,7 +557,11 @@ pub(crate) fn run(root: &Path) -> Result<(), String> { let actual_plurals = catalogs.locale_plurals.get(code); let missing_plural = catalogs.english_plurals.iter().filter(|source| actual_plurals.is_none_or(|actual| !actual.contains(*source))).count(); if missing > 0 || missing_plural > 0 { - println!("i18n-audit: {code}: {missing} untranslated IDs, {missing_plural} untranslated plural forms (English fallback)"); + let note = format!("{code}: {missing} untranslated IDs, {missing_plural} untranslated plural forms (English fallback)"); + println!("i18n-audit: {note}"); + if strict_translations { + problems.push(note); + } } } println!("i18n-audit: checked {} Rust files, {} English IDs, {} source findings", files.len(), catalogs.english.len(), findings); @@ -620,4 +636,37 @@ mod tests { let source = "#[cfg(test)] mod tests { fn draw(ui: &mut Ui) { ui.label(\"test-only text\"); } }"; assert!(scan_source("sample.rs", source, &BTreeSet::new()).is_empty()); } + + fn audit_fixture(name: &str, german: &str) -> PathBuf { + let root = std::env::temp_dir().join(format!("notecraft-i18n-{name}-{}", std::process::id())); + let _ = fs::remove_dir_all(&root); + fs::create_dir_all(root.join("i18n")).unwrap(); + fs::write(root.join("i18n/en.tsv"), "@id\tui.save\tSave\n@id\tui.open\tOpen\n").unwrap(); + fs::write(root.join("i18n/en-XA.tsv"), "@id\tui.save\t$$$Save@@@\n@id\tui.open\t$$$Open@@@\n").unwrap(); + fs::write(root.join("i18n/ar-XB.tsv"), "@id\tui.save\t[[RLI]]$$$Save@@@[[PDI]]\n@id\tui.open\t[[RLI]]$$$Open@@@[[PDI]]\n").unwrap(); + fs::write(root.join("i18n/de.tsv"), german).unwrap(); + root + } + + #[test] + fn missing_translations_fail_the_standalone_audit() { + let root = audit_fixture("missing", "@id\tui.save\tSpeichern\n"); + let error = run(&root).expect_err("untranslated IDs must make i18n-audit exit non-zero"); + assert!(error.contains("de") && error.contains("1 untranslated"), "{error}"); + let _ = fs::remove_dir_all(&root); + } + + #[test] + fn missing_translations_stay_a_note_in_the_ci_gate() { + let root = audit_fixture("ci", "@id\tui.save\tSpeichern\n"); + assert!(run_for_ci(&root).is_ok()); + let _ = fs::remove_dir_all(&root); + } + + #[test] + fn complete_translations_pass_the_standalone_audit() { + let root = audit_fixture("complete", "@id\tui.save\tSpeichern\n@id\tui.open\tÖffnen\n"); + assert!(run(&root).is_ok()); + let _ = fs::remove_dir_all(&root); + } } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3286f05d1..f247e8534 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -12,7 +12,7 @@ //! text check text files: no byte order mark in source, manifests or Markdown, and plain //! punctuation (no em or en dashes, no curly quotes) in Markdown, per .agents/TONE.md; //! add `--fix` to rewrite those issues -//! i18n-audit check UI string IDs, hard-coded text, and locale catalog coverage +//! i18n-audit check UI string IDs, hard-coded text, and locale catalog coverage (fails on untranslated IDs; ci only reports them) //! screenshots regenerate docs/images from the real window with the headless runner //! coverage measure coverage, compare platform baselines, or check the 80% line coverage floor; //! `--update` writes this run as the new baseline @@ -530,7 +530,13 @@ fn run_ci(root: &Path) -> Result<(), String> { let mut recorder = devx_timing::Recorder::new(root, "ci"); for task in ["fmt", "clippy", "test", "i18n-audit", "layers", "assets", "docs", "text", "demo-check"] { println!("\n== {task} =="); - let result = if task == "test" { run_test(root, &mut recorder) } else { recorder.measure(task, || run_task(root, task, &[])) }; + let result = match task { + "test" => run_test(root, &mut recorder), + // Untranslated locale entries are reported but do not block the local gate; the + // standalone `cargo xtask i18n-audit` (the nightly warning job) fails on them. + "i18n-audit" => recorder.measure(task, || i18n_audit::run_for_ci(root)), + _ => recorder.measure(task, || run_task(root, task, &[])), + }; if let Err(error) = result { recorder.finish(false); return Err(format!("{task}: {error}")); From 7d2de5d3e2c2474e97e817ed0dcd06d5de0829c0 Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 09:41:08 -0700 Subject: [PATCH 2/6] fix(import): keep picture sizes and stop kept boxes overlapping (#709) Content::Picture now carries PictureWidth/PictureHeight wherever the picture sits, so a picture inside an outline is written at the size OneNote showed it rather than its pixel size. On pages laid out box by box, a box moves down below an overlapping box above it that has grown past OneNote's position; boxes side by side keep their places. Co-Authored-By: Claude Opus 5.5 --- crates/import/src/convert.rs | 98 ++++++++++++++++++++++++++++++++++-- crates/onenote/src/one.rs | 17 ++++++- crates/onenote/src/store.rs | 18 +++++++ 3 files changed, 127 insertions(+), 6 deletions(-) diff --git a/crates/import/src/convert.rs b/crates/import/src/convert.rs index 8226b1648..9fa2a5ef0 100644 --- a/crates/import/src/convert.rs +++ b/crates/import/src/convert.rs @@ -83,11 +83,30 @@ const BOX_WIDTH: f32 = 13.0 * PER_HALF_INCH; const BOX_LEFT: f32 = PER_HALF_INCH; const LINE_HEIGHT: f32 = 24.0; +/// How tall a block stands in a box of this width: a picture at its size, fitted to the box +/// when it is wider, and anything else as one line. +fn block_height(block: &Block, box_width: f32) -> f32 { + match block { + Block::Image { width, height: Some(h), .. } => { + let fit = width.filter(|w| *w > box_width && *w > 0.0).map_or(1.0, |w| box_width / w); + h * fit + } + _ => LINE_HEIGHT, + } +} + impl Ctx<'_, '_> { /// Converts a page box by box, so each lands where it was and the ink stays on it. + /// + /// A box keeps OneNote's place unless a box above it, overlapping it across the page, has + /// grown past that place: NoteCraft's boxes carry a header and padding OneNote's do not, + /// so boxes OneNote stacked edge to edge would otherwise overlap. Such a box moves down + /// just below the one above. fn placed(&mut self, page: &Page, first_row_header: bool) { let mut contents = page.blocks.iter(); - let mut boxes = Vec::new(); + let mut boxes: Vec = Vec::new(); + // Each placed box's left, right and estimated bottom, to push later boxes down. + let mut extents: Vec<(f32, f32, f32, f32)> = Vec::new(); let mut below = PER_HALF_INCH; for place in &page.places { let before = self.out.blocks.len(); @@ -103,9 +122,17 @@ impl Ctx<'_, '_> { (*width, *height) = (Some(w), Some(h)); } let x = place.x.map_or(BOX_LEFT, |x| x * PER_HALF_INCH); - let y = place.y.map_or(below, |y| y * PER_HALF_INCH); let width = size.map(|s| s.0).or_else(|| place.width.map(|w| w * PER_HALF_INCH)).unwrap_or(BOX_WIDTH); - below = y + size.map_or(made as f32 * LINE_HEIGHT, |s| s.1) + LINE_HEIGHT; + let mut y = place.y.map_or(below, |y| y * PER_HALF_INCH); + for &(left, right, top, bottom) in &extents { + if top <= y && y < bottom && left < x + width && x < right { + y = bottom; + } + } + let content: f32 = self.out.blocks.get(before..).unwrap_or(&[]).iter().map(|b| block_height(b, width)).sum(); + let bottom = y + content + LINE_HEIGHT; + below = bottom; + extents.push((x, x + width, y, bottom)); boxes.push(Container::new(x, y, width, made)); } self.out.boxes = Some(boxes); @@ -135,7 +162,13 @@ impl Ctx<'_, '_> { self.numbers.clear(); if let Some(span) = self.attachment(content) { let block = match span.image.clone() { - Some(src) => Block::Image { alt: span.text, src, width: None, height: None, emoji: Vec::new() }, + Some(src) => { + let size = match content { + Content::Picture { size, .. } => size.map(|(w, h)| (w * PER_HALF_INCH, h * PER_HALF_INCH)), + _ => None, + }; + Block::Image { alt: span.text, src, width: size.map(|s| s.0), height: size.map(|s| s.1), emoji: Vec::new() } + } None => Block::Paragraph(vec![span], Vec::new()), }; self.out.blocks.push(block); @@ -202,7 +235,7 @@ impl Ctx<'_, '_> { /// A picture as an image span, or a file as a link span. `None` when its bytes are gone. fn attachment(&mut self, content: &Content) -> Option { match content { - Content::Picture { name, alt, file, ext } => { + Content::Picture { name, alt, file, ext, .. } => { let Some(bytes) = file.as_deref().and_then(|r| self.file_data.read(r)) else { self.out.loss.missing_data += 1; return None; @@ -489,6 +522,7 @@ mod tests { alt: String::new(), file: Some("{00000000-0000-0000-0000-000000000000}".into()), ext: String::new(), + size: None, }], ..Page::default() }; @@ -522,4 +556,58 @@ mod tests { assert_eq!(boxes.first().map(|b| (b.x, b.y, b.width, b.blocks)), Some((96.0, 240.0, 480.0, 1))); assert_eq!(boxes.get(1).map(|b| (b.x, b.blocks)), Some((48.0, 2))); } + + #[test] + fn a_scaled_picture_inside_an_outline_keeps_its_size_and_pushes_the_box_below_down() { + use notecraft_onenote::testing::OneNote; + use notecraft_onenote::{Ink, InkPoint, InkStroke, Place}; + let png = include_bytes!("../tests/fixtures/synthetic-pixel.png"); + let mut one = OneNote::new(); + let shots = [OneNote::picture("a.png", "", "png", png).sized(8.0, 4.5), OneNote::picture("b.png", "", "png", png).sized(8.0, 4.5)]; + one.page_with_attachments("Shots", 1, &[], &shots); + let data = one.finish(); + let store = notecraft_onenote::read(&data).expect("a synthetic section"); + let mut page = notecraft_onenote::section(&store).pages.into_iter().next().expect("a page"); + assert_eq!(page.blocks.len(), 2, "{:?}", page.blocks); + // Two boxes OneNote stacked edge to edge: the second starts one half-inch below the + // first, but the first holds a picture four and a half half-inches tall. + page.places = vec![ + Place { x: Some(1.0), y: Some(1.0), width: Some(10.0), picture: None, blocks: 1 }, + Place { x: Some(1.0), y: Some(2.0), width: Some(10.0), picture: None, blocks: 1 }, + ]; + page.ink = Ink { + strokes: vec![InkStroke { points: vec![InkPoint { x: 1.0, y: 1.0, pressure: None }], colour: None, width: 0.1, highlighter: false }], + ..Ink::default() + }; + let out = convert_page(&store, &data, &page, false, &mut |name: &str, _: &[u8]| Some(format!("assets/{name}"))); + let sizes: Vec<_> = + out.blocks.iter().filter_map(|b| if let Block::Image { width, height, .. } = b { Some((*width, *height)) } else { None }).collect(); + assert_eq!(sizes, [(Some(8.0 * PER_HALF_INCH), Some(4.5 * PER_HALF_INCH)); 2], "the picture keeps OneNote's displayed size"); + let boxes = out.boxes.expect("boxes"); + let (first, second) = (&boxes[0], &boxes[1]); + assert!(second.y >= first.y + 4.5 * PER_HALF_INCH, "the box below moves down past the picture: {} then {}", first.y, second.y); + } + + #[test] + fn boxes_side_by_side_keep_their_own_places() { + use notecraft_onenote::{Ink, InkPoint, InkStroke, Place}; + let line = |t: &str| Content::Text { runs: vec![Run { text: t.into(), ..Run::default() }], list: None, depth: 0 }; + let lines: Vec = (0..6).map(|n| line(&format!("line {n}"))).collect(); + let page = Page { + title: "t".into(), + level: 1, + blocks: lines, + places: vec![ + Place { x: Some(1.0), y: Some(1.0), width: Some(5.0), picture: None, blocks: 5 }, + Place { x: Some(8.0), y: Some(1.0), width: Some(5.0), picture: None, blocks: 1 }, + ], + ink: Ink { + strokes: vec![InkStroke { points: vec![InkPoint { x: 1.0, y: 1.0, pressure: None }], colour: None, width: 0.1, highlighter: false }], + ..Ink::default() + }, + }; + let out = convert_page(&empty_store(), &[], &page, false, &mut |_, _| None); + let boxes = out.boxes.expect("boxes"); + assert_eq!(boxes.iter().map(|b| b.y).collect::>(), [PER_HALF_INCH, PER_HALF_INCH], "a box beside another is not pushed down"); + } } diff --git a/crates/onenote/src/one.rs b/crates/onenote/src/one.rs index 8fb29a7b8..3479915d0 100644 --- a/crates/onenote/src/one.rs +++ b/crates/onenote/src/one.rs @@ -121,7 +121,8 @@ pub enum Content { /// Text, with its runs and, if it is a list item, what kind of list. Text { runs: Vec, list: Option, depth: usize }, /// A picture. `file` names the data in the store ([MS-ONESTORE] file data reference). - Picture { name: String, alt: String, file: Option, ext: String }, + /// `size` is the size the page shows it at, in half-inches, wherever the picture sits. + Picture { name: String, alt: String, file: Option, ext: String, size: Option<(f32, f32)> }, /// A file someone put on the page. File { name: String, file: Option, ext: String }, /// A table of cells, each cell a list of lines. @@ -336,6 +337,7 @@ fn content(space: &ObjectSpace, id: CompactId, depth: usize, indent: usize, list alt: props.text(IMAGE_ALT_TEXT).unwrap_or_default(), file, ext: ext.unwrap_or_default(), + size: ink::float(props, PICTURE_WIDTH).zip(ink::float(props, PICTURE_HEIGHT)).filter(|(w, h)| *w > 0.0 && *h > 0.0), }) } EMBEDDED_FILE_NODE => { @@ -531,4 +533,17 @@ mod tests { let store = crate::store::read(&good).expect("read"); assert!(!section(&store).pages.is_empty()); } + + #[test] + fn a_picture_inside_an_outline_keeps_the_size_the_page_shows_it_at() { + let mut one = OneNote::new(); + one.page_with_attachments("Shots", 1, &[], &[OneNote::picture("shot.png", "", "png", b"png bytes").sized(8.0, 4.5)]); + let store = crate::store::read(&one.finish()).expect("read"); + let page = section(&store).pages.into_iter().next().expect("a page"); + let size = page.blocks.iter().find_map(|b| match b { + Content::Picture { size, .. } => Some(*size), + _ => None, + }); + assert_eq!(size, Some(Some((8.0, 4.5))), "{:?}", page.blocks); + } } diff --git a/crates/onenote/src/store.rs b/crates/onenote/src/store.rs index 94c06de5c..2ffd46a6f 100644 --- a/crates/onenote/src/store.rs +++ b/crates/onenote/src/store.rs @@ -1190,6 +1190,17 @@ pub mod build { extension: String, bytes: Option>, reference: Option, + /// The size OneNote shows a picture at, in half-inches (PictureWidth, PictureHeight). + size: Option<(f32, f32)>, + } + + impl Attachment { + /// Gives a picture the size OneNote shows it at, in half-inches, as a page scaled + /// for a high-DPI display stores it. + pub fn sized(mut self, width: f32, height: f32) -> Attachment { + self.size = Some((width, height)); + self + } } #[derive(Clone)] @@ -1298,6 +1309,7 @@ pub mod build { extension: extension.to_string(), bytes: Some(bytes.to_vec()), reference: None, + size: None, } } @@ -1310,6 +1322,7 @@ pub mod build { extension: extension.to_string(), bytes: None, reference: None, + size: None, } } @@ -1328,6 +1341,7 @@ pub mod build { extension: extension.to_string(), bytes: Some(bytes.to_vec()), reference: None, + size: None, } } @@ -1415,6 +1429,10 @@ pub mod build { AttachmentKind::Picture => { content.text(0x1C00_1DD7, &attachment.name); content.text(0x1C00_1E58, &attachment.alt); + if let Some((width, height)) = attachment.size { + content.u32(0x1400_34CD, width.to_bits()); // PictureWidth + content.u32(0x1400_34CE, height.to_bits()); // PictureHeight + } content.object(0x2000_1C3F, container_oid); decls.push(Decl { oid: content_oid, jcid: 0x0006_0011, props: content.finish() }); } From d23e0415448bab7090b5c8b7b2c2028695a04b0c Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 09:57:18 -0700 Subject: [PATCH 3/6] feat(ink): show a Delete button beside held ink (#715) Ink picked up with Lasso Select or Select now offers a Delete ink button just below (or above) its box, on a layer over the page, so a finger, pen or mouse can delete the selection without a keyboard. Delete and Backspace still work; the button uses the same delete, so Undo and Redo treat it alike. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/inkpad.rs | 54 ++++++++++++++++++++++-- crates/ui-egui/tests/ui.rs | 79 ++++++++++++++++++++++++++++++++++++ i18n/ar-XB.tsv | 2 + i18n/en-XA.tsv | 2 + i18n/en.tsv | 2 + i18n/nl.tsv | 2 + 6 files changed, 137 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/inkpad.rs b/crates/ui-egui/src/inkpad.rs index d8f0a4e6f..2854a9bca 100644 --- a/crates/ui-egui/src/inkpad.rs +++ b/crates/ui-egui/src/inkpad.rs @@ -714,17 +714,55 @@ fn on_page_layer(ctx: &egui::Context, p: egui::Pos2) -> bool { ctx.layer_id_at(p).is_none_or(|layer| layer.order < egui::Order::Foreground) } +/// The Delete button shown beside held ink (issue #715), so a finger, a pen or a mouse can throw +/// the selection away without a keyboard. It sits just under the held box, or above it when the +/// box reaches the bottom of the view, on a layer over the page so a press on it reaches it and +/// not the words, the ink or the lasso underneath. Gives whether it was clicked and where it is. +fn held_delete_button(ui: &Ui, held_box: egui::Rect, body: egui::Rect, t: &Tokens) -> (bool, egui::Rect) { + const GAP: f32 = 6.0; + const HEIGHT: f32 = 30.0; + let view = body.intersect(ui.clip_rect()); + let below = held_box.max.y + GAP + HEIGHT <= view.max.y; + let (pivot, y) = if below { (egui::Align2::LEFT_TOP, held_box.max.y + GAP) } else { (egui::Align2::LEFT_BOTTOM, held_box.min.y - GAP) }; + let x = held_box.min.x.clamp(view.min.x, (view.max.x - 120.0).max(view.min.x)); + let shown = egui::Area::new(egui::Id::new("ink-held-delete")).order(egui::Order::Foreground).pivot(pivot).fixed_pos(egui::pos2(x, y)).show( + ui.ctx(), + |ui| { + egui::Frame::NONE + .fill(t.panel) + .stroke(egui::Stroke::new(1.0, t.container_border)) + .corner_radius(6.0) + .inner_margin(egui::Margin::same(2)) + .show(ui, |ui| { + ui.add(egui::Button::new(crate::tl_id!("ui.delete_ink")).min_size(vec2(0.0, HEIGHT - 4.0))) + .on_hover_text(crate::tl_id!("ui.delete_ink_tip")) + }) + }, + ); + (shown.inner.inner.clicked(), shown.response.rect) +} + /// Held ink in the ordinary pointer (a selection box picked it up): a drag inside its box moves /// it, one on a corner stretches it, Delete throws it away and Escape lets go. Only the box /// takes the pointer, so the words and boxes around it are as they always are. -fn held_in_write(ui: &mut Ui, body: egui::Rect, origin: egui::Pos2, pad: &mut Pad, zoom: f32, modal_owns_keys: bool) -> bool { +fn held_in_write(ui: &mut Ui, body: egui::Rect, origin: egui::Pos2, pad: &mut Pad, zoom: f32, modal_owns_keys: bool, t: &Tokens) -> bool { let (Some(b), Some(held_box)) = (pick::bounds(&pad.drawing, &pad.held), held_box(pad, origin, zoom)) else { pad.let_go(); ui.data_mut(|d| d.remove::(held_area_id())); return false; }; let area = held_box.expand(HANDLE / 2.0).intersect(body); - ui.data_mut(|d| d.insert_temp(held_area_id(), area)); + // The Delete beside the box counts as part of it: a press there must not let go of the ink + // before the click lands (issue #715). Not while the ink is being moved or stretched. + if pad.grabbed.is_none() { + let (clicked, button) = held_delete_button(ui, held_box, body, t); + ui.data_mut(|d| d.insert_temp(held_area_id(), area.union(button))); + if clicked { + return pad.delete_held(); + } + } else { + ui.data_mut(|d| d.insert_temp(held_area_id(), area)); + } let resp = ui.interact(area, ui.id().with("ink-held"), Sense::drag()); let here = ui.ctx().pointer_interact_pos().unwrap_or(egui::Pos2::ZERO); if resp.hovered() || resp.dragged() { @@ -962,7 +1000,7 @@ pub fn show( if pad.held.is_empty() { ui.data_mut(|d| d.remove::(held_area_id())); } else { - changed |= held_in_write(ui, body, origin, pad, zoom, modal_owns_keys); + changed |= held_in_write(ui, body, origin, pad, zoom, modal_owns_keys, t); } pad.dirty |= changed; pad.touched |= changed; @@ -1130,6 +1168,13 @@ pub fn show( // Write and Pick were answered above, with the page. Pointer::Write | Pointer::Pick | Pointer::Pan | Pointer::Laser | Pointer::Eyedropper(_) => {} } + // Ink the lasso holds offers Delete beside it too, for a finger or a mouse (issue #715). + if pad.loop_now.is_empty() + && let Some(held) = held_box(pad, origin, zoom) + && held_delete_button(ui, held, body, t).0 + { + changed |= pad.delete_held(); + } // Delete throws away whatever is held, unless the keyboard belongs to a dialog. if !modal_owns_keys && !pad.held.is_empty() && ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace)) { changed |= pad.delete_held(); @@ -2170,11 +2215,12 @@ mod tests { pad.hold_touching((0.0, 0.0, 100.0, 80.0)); let ctx = egui::Context::default(); let body = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(200.0, 200.0)); + let tokens = crate::theme::Tokens::for_theme(crate::theme::Theme { mode: crate::theme::Mode::Light, accent: crate::theme::Accent::Default }); let escape = egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; for (modal, held) in [(true, 1), (false, 0)] { let input = egui::RawInput { screen_rect: Some(body), events: vec![escape.clone()], ..Default::default() }; let mut out = ctx.run_ui(input, |ui| { - held_in_write(ui, body, body.min, &mut pad, 1.0, modal); + held_in_write(ui, body, body.min, &mut pad, 1.0, modal, &tokens); }); out.textures_delta.clear(); assert_eq!(pad.holding(), held); diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs index fc9f5244c..ec9c3e61f 100644 --- a/crates/ui-egui/tests/ui.rs +++ b/crates/ui-egui/tests/ui.rs @@ -23425,3 +23425,82 @@ fn lasso_delete_of_ink_is_undone_and_redone() { assert_eq!(ink(&mut h)["strokes"].as_u64(), Some(1), "redo takes it away again"); assert_eq!(render_strokes(&mut h), upper_only, "redo leaves the same rendered stroke as Delete"); } + +/// Issue #715: ink picked up with Lasso Select or Select offers a visible Delete beside it, so a +/// touch or mouse user without a keyboard can throw it away. A real click on it (press and release +/// over it, as a finger or a mouse gives) takes only the held strokes, and Undo and Redo treat it +/// as the edit Delete is. +#[test] +fn held_ink_offers_a_visible_delete_that_undo_reverses() { + let (_t, mut app, s) = sample_app("ui-held-ink-delete-button"); + app.open_path(&s.md_page.to_string_lossy()); + let mut h = harness(app, LIGHT); + settle(&mut h); + h.get_by_label("Draw").click(); + h.run(); + h.get_by_label("Pen black").click(); + h.run(); + + let body = h.state().page_rect().expect("the page"); + let draw = |h: &mut Harness<'_, NoteCraftApp>, x: f32, y: f32| { + ask(h, "ui.press", json!({"x": x, "y": y})).expect("down"); + pump(h); + for step in 1..=4 { + ask(h, "ui.move", json!({"x": x + step as f32 * 20.0, "y": y})).expect("move"); + pump(h); + } + ask(h, "ui.release", json!({"x": x + 80.0, "y": y})).expect("up"); + pump(h); + }; + draw(&mut h, body.min.x + 40.0, body.min.y + 120.0); + draw(&mut h, body.min.x + 40.0, body.min.y + 260.0); + let ink = |h: &mut Harness<'_, NoteCraftApp>| ask(h, "ui.inspect", json!({})).expect("inspect")["ink"].clone(); + for _ in 0..20 { + settle(&mut h); + if ink(&mut h)["strokes"].as_u64() == Some(2) { + break; + } + } + assert_eq!(ink(&mut h)["strokes"].as_u64(), Some(2), "two strokes on the page"); + assert!(h.query_by_label("Delete ink").is_none(), "nothing is held, so there is nothing to delete"); + + // Lasso round the lower stroke only. + h.get_by_label("Lasso Select").click(); + pump(&mut h); + let (lx, ly) = (body.min.x + 20.0, body.min.y + 230.0); + ask(&mut h, "ui.press", json!({"x": lx, "y": ly})).expect("down"); + pump(&mut h); + for (dx, dy) in [(180.0, 0.0), (180.0, 70.0), (0.0, 70.0), (0.0, 2.0)] { + ask(&mut h, "ui.move", json!({"x": lx + dx, "y": ly + dy})).expect("move"); + pump(&mut h); + } + ask(&mut h, "ui.release", json!({"x": lx, "y": ly + 2.0})).expect("up"); + settle(&mut h); + assert_eq!(ink(&mut h)["holding"].as_u64(), Some(1), "the lasso took the lower stroke"); + + let at = h.get_by_label("Delete ink").rect().center(); + ask(&mut h, "ui.click", json!({"x": at.x, "y": at.y})).expect("click Delete"); + settle(&mut h); + let after = ink(&mut h); + assert_eq!(after["strokes"].as_u64(), Some(1), "Delete removed only the held stroke: {after}"); + assert_eq!(after["holding"].as_u64(), Some(0), "and nothing is held"); + assert!(h.query_by_label("Delete ink").is_none(), "the button goes with the selection"); + + ask(&mut h, "ui.undo", json!({})).expect("undo"); + settle(&mut h); + assert_eq!(ink(&mut h)["strokes"].as_u64(), Some(2), "undo puts the deleted stroke back"); + ask(&mut h, "ui.redo", json!({})).expect("redo"); + settle(&mut h); + assert_eq!(ink(&mut h)["strokes"].as_u64(), Some(1), "redo takes it away again"); + + // The same button is there for ink held in Select, the ordinary pointer's ink selection. + h.get_by_label("Select").click(); + pump(&mut h); + ask(&mut h, "ui.click", json!({"x": body.min.x + 80.0, "y": body.min.y + 120.0})).expect("pick"); + settle(&mut h); + assert_eq!(ink(&mut h)["holding"].as_u64(), Some(1), "the upper stroke is held"); + let at = h.get_by_label("Delete ink").rect().center(); + ask(&mut h, "ui.click", json!({"x": at.x, "y": at.y})).expect("click Delete"); + settle(&mut h); + assert_eq!(ink(&mut h)["strokes"].as_u64(), Some(0), "the last stroke went too"); +} diff --git a/i18n/ar-XB.tsv b/i18n/ar-XB.tsv index 419fc14ee..3b97c1db6 100644 --- a/i18n/ar-XB.tsv +++ b/i18n/ar-XB.tsv @@ -317,6 +317,8 @@ @id ui.delete_columns_2 [[RLI]]$$$Delete@@@[[PDI]]\n[[RLI]]$$$Columns@@@[[PDI]] @id ui.delete_ellipsis [[RLI]]$$$Delete...@@@[[PDI]] @id ui.delete_file [[RLI]]$$$Delete file@@@[[PDI]] +@id ui.delete_ink [[RLI]]$$$Delete ink@@@[[PDI]] +@id ui.delete_ink_tip [[RLI]]$$$Delete the selected ink@@@[[PDI]] @id ui.delete_notebook [[RLI]]$$$Delete notebook@@@[[PDI]] @id ui.delete_notebook_2 [[RLI]]$$$Delete notebook...@@@[[PDI]] @id ui.delete_notebook_title_and_everything_inside_it [[RLI]]$$$Delete notebook "{title}" and everything inside it?@@@[[PDI]] diff --git a/i18n/en-XA.tsv b/i18n/en-XA.tsv index be2a820ed..2d4c4090c 100644 --- a/i18n/en-XA.tsv +++ b/i18n/en-XA.tsv @@ -317,6 +317,8 @@ @id ui.delete_columns_2 $$$Delete@@@\n$$$Columns@@@ @id ui.delete_ellipsis $$$Delete...@@@ @id ui.delete_file $$$Delete file@@@ +@id ui.delete_ink $$$Delete ink@@@ +@id ui.delete_ink_tip $$$Delete the selected ink@@@ @id ui.delete_notebook $$$Delete notebook@@@ @id ui.delete_notebook_2 $$$Delete notebook...@@@ @id ui.delete_notebook_title_and_everything_inside_it $$$Delete notebook "{title}" and everything inside it?@@@ diff --git a/i18n/en.tsv b/i18n/en.tsv index c0b7c7a4d..c9aa63c2b 100644 --- a/i18n/en.tsv +++ b/i18n/en.tsv @@ -317,6 +317,8 @@ @id ui.delete_columns_2 Delete\nColumns @id ui.delete_ellipsis Delete... @id ui.delete_file Delete file +@id ui.delete_ink Delete ink +@id ui.delete_ink_tip Delete the selected ink @id ui.delete_notebook Delete notebook @id ui.delete_notebook_2 Delete notebook... @id ui.delete_notebook_title_and_everything_inside_it Delete notebook "{title}" and everything inside it? diff --git a/i18n/nl.tsv b/i18n/nl.tsv index e76fff90c..8a1e6be35 100644 --- a/i18n/nl.tsv +++ b/i18n/nl.tsv @@ -317,6 +317,8 @@ @id ui.delete_columns_2 Kolommen\nverwijderen @id ui.delete_ellipsis Verwijderen… @id ui.delete_file Bestand verwijderen +@id ui.delete_ink Inkt verwijderen +@id ui.delete_ink_tip De geselecteerde inkt verwijderen @id ui.delete_notebook Notitieblok verwijderen @id ui.delete_notebook_2 Notitieblok verwijderen… @id ui.delete_notebook_title_and_everything_inside_it Notitieblok "{title}" en alles erin verwijderen? From f3852ccb6317da5f6d1db9202e0b8ce01609ee4e Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 10:01:18 -0700 Subject: [PATCH 4/6] fix(page): stop sideways panning past the page's alignment edge (#726) A finger, pen or middle drag could pan a left-to-right page right past its left edge into space where only ink could go. The canvas now stops at that edge (the right edge for a right-to-left page), unless ink already reaches past it; the other way it stays endless. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/app.rs | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 02372013b..8c6971d1b 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -14539,6 +14539,24 @@ impl NoteCraftApp { if top < 0.0 { (-top + INK_ABOVE_ROOM) * zoom } else { 0.0 } } + /// How far, in screen points, the sideways pan may take the view past the edge the open page + /// lines up on (issue #726): the left edge of a left-to-right page, the right edge of a + /// right-to-left one. Nothing, unless ink or a box already reaches past that edge, in which + /// case as far as it with a little room beyond. Gives whether the page is right to left too. + fn room_past_page_edge(&self) -> (bool, f32) { + #[allow(clippy::cast_precision_loss)] + let zoom = self.zoom_percent as f32 / 100.0; + let rtl = self.editor.as_ref().is_some_and(|ed| ed.page_dir == Some(notecraft_model::Dir::Rtl)); + if rtl { + let (Some(ed), Some((_, right)), Some(view)) = (self.editor.as_ref(), self.page_hspan, self.page_view) else { return (true, 0.0) }; + let past = right - (ed.origin.x + view.width()); + (true, if past > 0.5 { past + INK_ABOVE_ROOM * zoom } else { 0.0 }) + } else { + let left = self.pad.as_ref().and_then(crate::inkpad::Pad::bounds).map_or(0.0, |[x0, _, _, _]| x0); + (false, if left < 0.0 { (-left + INK_ABOVE_ROOM) * zoom } else { 0.0 }) + } + } + fn wheel_canvas_pan_delta(delta: egui::Vec2, modifiers: Modifiers, canvas_pan_enabled: bool) -> egui::Vec2 { if modifiers.ctrl { return egui::Vec2::ZERO; @@ -14679,6 +14697,12 @@ impl NoteCraftApp { if self.canvas_pan.y > top { self.canvas_pan.y = top; } + // Sideways the page lines up on one edge, where typing starts: the left for a + // left-to-right page, the right for a right-to-left one. Panned past it, a finger or a + // pen reached space where only ink could go (issue #726). The other way the canvas is + // endless, as down the page. + let (rtl, room) = self.room_past_page_edge(); + self.canvas_pan.x = if rtl { self.canvas_pan.x.max(-room) } else { self.canvas_pan.x.min(room) }; } else { self.canvas_drag = None; } @@ -21808,6 +21832,68 @@ mod canvas_pan_tests { settle(&mut h); assert_eq!(h.state().canvas_pan, pan, "a page that did not open did not move this one"); } + + /// Two fingers on the touchpad, moved `dx` points sideways (positive: the page moves right). + fn swipe_sideways(h: &mut H, dx: f32) { + let over = h.state().page_view.expect("the page is shown").center(); + h.event(egui::Event::PointerMoved(over)); + h.step(); + for _ in 0..20 { + h.event(egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: vec2(dx / 20.0, 0.0), + phase: egui::TouchPhase::Move, + modifiers: egui::Modifiers::NONE, + source: egui::MouseWheelSource::Trackpad, + }); + h.step(); + } + settle(h); + } + + /// Issue #726: a left-to-right page lines up on its left edge, where typing starts, so a + /// finger or a pen cannot pan the page right past that edge into space where only ink could + /// go. To the right, where there is room to draw, the canvas is still endless. + #[test] + fn a_left_to_right_page_cannot_be_panned_past_its_left_edge() { + let (_t, _sample, mut h) = drawing("pan-left-edge"); + swipe_sideways(&mut h, 3000.0); + assert!(h.state().canvas_pan.x <= 0.5, "no pan left of the page's edge: {:?}", h.state().canvas_pan); + swipe_sideways(&mut h, -3000.0); + assert!(h.state().canvas_pan.x < -2000.0, "the canvas still pans to the right: {:?}", h.state().canvas_pan); + swipe_sideways(&mut h, 8000.0); + assert!(h.state().canvas_pan.x.abs() < 0.5, "back to the edge and no further: {:?}", h.state().canvas_pan); + } + + /// Issue #726, the other way round: a right-to-left page lines up on its right edge, so it + /// cannot be panned left past that edge, and the room to draw is to its left. + #[test] + fn a_right_to_left_page_cannot_be_panned_past_its_right_edge() { + let (_t, _sample, mut h) = drawing("pan-right-edge"); + h.state_mut().editor.as_mut().expect("editor").page_dir = Some(notecraft_model::Dir::Rtl); + settle(&mut h); + swipe_sideways(&mut h, -3000.0); + assert!(h.state().canvas_pan.x >= -0.5, "no pan right of the page's edge: {:?}", h.state().canvas_pan); + swipe_sideways(&mut h, 3000.0); + assert!(h.state().canvas_pan.x > 2000.0, "the canvas still pans to the left: {:?}", h.state().canvas_pan); + } + + /// Ink already drawn left of a left-to-right page can still be reached. + #[test] + fn ink_left_of_the_page_can_still_be_panned_to() { + let (_t, _sample, mut h) = drawing("pan-to-ink-left"); + { + let pad = h.state_mut().pad.as_mut().expect("a pad for the page"); + let mut stroke = notecraft_ink::Stroke::new(notecraft_ink::Tool::Pen, notecraft_ink::Rgb(0, 0, 0), 2.0); + stroke.add(notecraft_ink::Dab::new(-400.0, 100.0, 1.0)); + stroke.add(notecraft_ink::Dab::new(-380.0, 140.0, 1.0)); + pad.drawing.add(stroke); + } + settle(&mut h); + swipe_sideways(&mut h, 8000.0); + let pan = h.state().canvas_pan.x; + assert!(pan > 350.0 && pan < 500.0, "left as far as the ink beside the page, and no further: {pan}"); + } } #[cfg(test)] From de28e0e2a2096050974b1f175641e016f5c1588d Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 10:08:10 -0700 Subject: [PATCH 5/6] fix(input): pass touchpad wheel lines to egui as points (#710) A Windows precision touchpad sends wheel events in fractions of a line and adds its own momentum after the fingers lift. egui smoothed those as a mouse wheel's, per frame, so uneven frames made fast scrolling rise and fall in waves. The desktop raw input hook now turns fractional line events into points of the same length; whole mouse-wheel notches and Ctrl+wheel zoom keep their unit. Co-Authored-By: Claude Opus 5.5 --- apps/notecraft/src/main.rs | 4 +++ crates/ui-egui/src/fling.rs | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/apps/notecraft/src/main.rs b/apps/notecraft/src/main.rs index 4acafe375..8bf1c627d 100644 --- a/apps/notecraft/src/main.rs +++ b/apps/notecraft/src/main.rs @@ -37,6 +37,10 @@ impl eframe::App for Shell { log::debug!("raw keyboard paste captured before egui clipboard handling (text only: {plain})"); self.windows.queue_keyboard_paste(raw_input.viewport_id, plain); } + // A precision touchpad's fractional wheel lines reach the page as points, so egui does + // not smooth the system's own momentum into waves of speed (issue #710). + let line = ctx.options(|o| o.input_options.line_scroll_speed); + notecraft_ui_egui::fling::touchpad_lines_to_points(&mut raw_input.events, line); // A finger on the page pans it, and a palm under a pen goes nowhere (issues #667, #670). self.windows.route_touches(ctx, raw_input); raw_input.events.extend(self.windows.take_events(raw_input.viewport_id)); diff --git a/crates/ui-egui/src/fling.rs b/crates/ui-egui/src/fling.rs index 18228bbfd..a673aa1b5 100644 --- a/crates/ui-egui/src/fling.rs +++ b/crates/ui-egui/src/fling.rs @@ -87,10 +87,67 @@ impl Fling { } } +/// Turns a precision touchpad's wheel events into point deltas before egui reads them (issue +/// #710). A Windows precision touchpad reports ordinary wheel events in fractions of a line, with +/// no phase, and keeps sending them after the fingers lift as its own momentum. egui smooths +/// line events as a mouse wheel's, paying them out by a fraction of the backlog each frame, so +/// uneven frames (pictures decoding as they come into view) turned that momentum into waves of +/// speed. As points of the same length they reach the page as they come and follow the system's +/// own momentum. A real mouse wheel's whole notches stay lines, and keep egui's smoothing. +/// `line` is how many points a line is (egui's `line_scroll_speed`). +pub fn touchpad_lines_to_points(events: &mut [egui::Event], line: f32) { + for event in events { + if let egui::Event::MouseWheel { unit, delta, modifiers, .. } = event + && *unit == egui::MouseWheelUnit::Line + && !modifiers.ctrl + && !modifiers.command + && (delta.x.fract() != 0.0 || delta.y.fract() != 0.0) + { + *unit = egui::MouseWheelUnit::Point; + *delta *= line; + } + } +} + #[cfg(test)] mod tests { use super::*; + fn wheel(unit: egui::MouseWheelUnit, delta: Vec2) -> egui::Event { + egui::Event::MouseWheel { + unit, + delta, + phase: egui::TouchPhase::Move, + modifiers: egui::Modifiers::NONE, + source: egui::MouseWheelSource::Trackpad, + } + } + + #[test] + fn a_touchpad_s_fractional_lines_reach_the_page_as_points() { + let mut events = vec![wheel(egui::MouseWheelUnit::Line, Vec2::new(0.0, -0.35)), wheel(egui::MouseWheelUnit::Line, Vec2::new(0.25, 0.0))]; + touchpad_lines_to_points(&mut events, 40.0); + assert_eq!(events, vec![wheel(egui::MouseWheelUnit::Point, Vec2::new(0.0, -14.0)), wheel(egui::MouseWheelUnit::Point, Vec2::new(10.0, 0.0))]); + } + + #[test] + fn a_mouse_wheel_s_whole_notches_stay_lines_and_other_events_are_untouched() { + let notch = wheel(egui::MouseWheelUnit::Line, Vec2::new(0.0, -1.0)); + let points = wheel(egui::MouseWheelUnit::Point, Vec2::new(0.0, -3.5)); + let page = wheel(egui::MouseWheelUnit::Page, Vec2::new(0.0, 0.5)); + let zoom = egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Line, + delta: Vec2::new(0.0, 0.3), + phase: egui::TouchPhase::Move, + modifiers: egui::Modifiers::CTRL, + source: egui::MouseWheelSource::Trackpad, + }; + let key = egui::Event::Text("a".into()); + let mut events = vec![notch.clone(), points.clone(), page.clone(), zoom.clone(), key.clone()]; + touchpad_lines_to_points(&mut events, 40.0); + assert_eq!(events, vec![notch, points, page, zoom, key], "a Ctrl+wheel zoom keeps its unit too"); + } + /// Swipes `per_frame` points a frame for `frames` frames at 60 a second, then lifts. fn swipe(f: &mut Fling, per_frame: Vec2, frames: usize) -> f64 { let mut now = 0.0; From aa9d9fff970f03315a60fc44f02217b22453532f Mon Sep 17 00:00:00 2001 From: DWAA1660 Date: Sat, 5 Dec 2026 10:26:28 -0700 Subject: [PATCH 6/6] test(page): middle drag pans into open canvas right of the words (#726) The test panned right past the page's left edge and drew there, which issue #726 now prevents. It pans left instead and draws in the open canvas beside the words. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/tests/ui.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs index ec9c3e61f..c09961380 100644 --- a/crates/ui-egui/tests/ui.rs +++ b/crates/ui-egui/tests/ui.rs @@ -641,11 +641,12 @@ fn middle_drag_pans_the_canvas_for_html_and_cmgfm_pages() { ask(&mut h, "ui.press", json!({"x": x, "y": y, "button": "middle"})).expect("start pan"); pump(&mut h); - // Right, past the page's left edge, and up, into the page: the canvas does not pan - // above the page's top, which is where it starts. - ask(&mut h, "ui.move", json!({"x": x + 80.0, "y": y - 60.0})).expect("move canvas"); + // Left, into the open canvas beside the words, and up, into the page: the canvas does not + // pan above the page's top, which is where it starts, nor right past the page's left + // edge, where the page lines up (issue #726). + ask(&mut h, "ui.move", json!({"x": x - 80.0, "y": y - 60.0})).expect("move canvas"); pump(&mut h); - ask(&mut h, "ui.release", json!({"x": x + 80.0, "y": y - 60.0, "button": "middle"})).expect("finish pan"); + ask(&mut h, "ui.release", json!({"x": x - 80.0, "y": y - 60.0, "button": "middle"})).expect("finish pan"); settle(&mut h); let after = ask(&mut h, "ui.inspect", json!({})).expect("inspect canvas after pan"); @@ -654,7 +655,7 @@ fn middle_drag_pans_the_canvas_for_html_and_cmgfm_pages() { assert_ne!(after_offset[1].as_f64(), Some(oy), "vertical pan moves the {label} canvas"); let after_origin = after.pointer("/page/origin").and_then(Value::as_array).expect("page origin after pan"); assert!( - after_origin[0].as_f64().unwrap_or_default() > before_origin[0].as_f64().unwrap_or_default() + after_origin[0].as_f64().unwrap_or_default() < before_origin[0].as_f64().unwrap_or_default() && after_origin[1].as_f64().unwrap_or_default() < before_origin[1].as_f64().unwrap_or_default(), "middle drag moves page content with the {label} canvas: before={before_origin:?}, after={after_origin:?}" ); @@ -664,8 +665,10 @@ fn middle_drag_pans_the_canvas_for_html_and_cmgfm_pages() { h.get_by_label("Pen red").click(); settle(&mut h); + // Open canvas to the right of the words, where the pan took the view. let origin = after.pointer("/page/origin").and_then(Value::as_array).expect("page origin after pan"); - let (start_x, y) = (origin[0].as_f64().unwrap_or(0.0) - 15.0, origin[1].as_f64().unwrap_or(0.0) + 220.0); + let view = h.state().page_rect().expect("the page"); + let (start_x, y) = (f64::from(view.max.x) - 200.0, origin[1].as_f64().unwrap_or(0.0) + 220.0); let end_x = start_x + 80.0; ask(&mut h, "ui.press", json!({"x": start_x, "y": y})).expect("draw in open canvas space"); pump(&mut h); @@ -690,7 +693,6 @@ fn middle_drag_pans_the_canvas_for_html_and_cmgfm_pages() { }) .count(); assert!(red_canvas_pixels > 5, "the outside-page stroke is visible in the canvas for {label}: {red_canvas_pixels} red pixels; {svg}"); - assert!(svg.contains("viewBox=\"-"), "ink outside the former page bounds is framed in the SVG: {svg}"); ask(&mut h, "ui.open", json!({"path": path.to_string_lossy()})).expect("reload page and its ink"); settle(&mut h); let reloaded = ask(&mut h, "ui.inspect", json!({})).expect("inspect reloaded ink");