From 438ae3da7867bfc126d7125b1e4001f3be1c552b Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 23:31:49 -0500 Subject: [PATCH] fw sync: review/pages/draw/text compile: comment selection and status fields, note popup scope, story binds, memoized-view preview trial, trials registered --- .../src/ui/crop/perspective_crop/stories.rs | 4 +- crates/pages/src/ui/sync_views.rs | 2 +- crates/pages/src/ui/text_selection.rs | 5 --- crates/pages/src/ui/view.rs | 2 +- crates/pages/src/ui/view/stories.rs | 2 +- crates/pages/tests/it/thumbnails.rs | 4 +- crates/pages/tests/it/views.rs | 41 ++++++++++++------- crates/review/src/ui/balloons.rs | 2 +- crates/review/src/ui/balloons/stories.rs | 4 +- crates/review/src/ui/thread.rs | 2 +- crates/review/src/ui/thread/note_popup.rs | 2 +- crates/review/tests/it/balloons.rs | 15 +++---- crates/text/tests/it/find_matches.rs | 5 ++- crates/ui-canvas/tests/it/canvas/tool.rs | 2 +- .../tests/it/docking/floating_area.rs | 2 +- 15 files changed, 53 insertions(+), 41 deletions(-) diff --git a/crates/draw/src/ui/crop/perspective_crop/stories.rs b/crates/draw/src/ui/crop/perspective_crop/stories.rs index 553f2b676..d85157540 100644 --- a/crates/draw/src/ui/crop/perspective_crop/stories.rs +++ b/crates/draw/src/ui/crop/perspective_crop/stories.rs @@ -50,9 +50,9 @@ fn skewed_page(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { /// shield dims the frame outside the quad. #[story(PerspectiveCropQuad<'static>, covers = [], drive = Drive::Drag(Grip::part(CORNER.at(0))))] fn bounded_quad(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - let quad = data.value("quad", Some(PAGE)); + let (quad, quad_at) = data.value_at("quad", Some(PAGE)); on_canvas(ui, |ui, at| { - PerspectiveCropQuad::new("Perspective crop", Bind::bound(&mut *quad)) + PerspectiveCropQuad::new("Perspective crop", quad_at.bind(&mut *quad)) .show_grid(false) .shield(CropShield::PERSPECTIVE) .bounds(FRAME) diff --git a/crates/pages/src/ui/sync_views.rs b/crates/pages/src/ui/sync_views.rs index 7528c8a30..cf072af3b 100644 --- a/crates/pages/src/ui/sync_views.rs +++ b/crates/pages/src/ui/sync_views.rs @@ -10,7 +10,7 @@ pub(crate) mod stories; use super::view::{PageViewOutput, PageViewState}; use craft_behavior::Proposal; use craft_ui::canvas::{SplitAt, SplitLayout, SplitViews}; -use craft_ui::contract::{Bind, EditResponse, Outcome, Pad, Props as _, Show as _, ShowContainer as _}; +use craft_ui::contract::{Bind, EditResponse, Outcome, Pad, Show as _, ShowContainer as _}; use craft_ui::display::{Elide, Shade, Text}; use craft_ui::layout_components::Stack; use craft_ui::runtime::env::Label; diff --git a/crates/pages/src/ui/text_selection.rs b/crates/pages/src/ui/text_selection.rs index 344e5bb62..73082bd2e 100644 --- a/crates/pages/src/ui/text_selection.rs +++ b/crates/pages/src/ui/text_selection.rs @@ -189,11 +189,6 @@ fn glyph_rects(text: &dyn PageTextSource, glyphs: &[usize]) -> Vec { runs(glyphs).into_iter().flat_map(|run| text.line_rects(run)).collect() } -/// The glyphs of a run, both ends included. -fn run_range(anchor: usize, head: usize) -> Range { - anchor.min(head)..anchor.max(head).saturating_add(1) -} - /// `glyphs` as ranges of consecutive indices. fn runs(glyphs: &[usize]) -> Vec> { let mut runs: Vec> = Vec::new(); diff --git a/crates/pages/src/ui/view.rs b/crates/pages/src/ui/view.rs index 923056525..c69654608 100644 --- a/crates/pages/src/ui/view.rs +++ b/crates/pages/src/ui/view.rs @@ -1781,7 +1781,7 @@ fn near_pages(placed: &Placed, continuous: bool, visible: &Range, count: } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::clamp_between; use craft_ui::testing::trial; diff --git a/crates/pages/src/ui/view/stories.rs b/crates/pages/src/ui/view/stories.rs index 51b095bee..e83f3ec5b 100644 --- a/crates/pages/src/ui/view/stories.rs +++ b/crates/pages/src/ui/view/stories.rs @@ -141,7 +141,7 @@ fn page_pictures(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { let pages = DemoPages::new(1); let placed = demo_placed(1, Pos2::new(room.min.x + 20.0, room.min.y + 10.0)); let view = CanvasView::new(room, Point::new(f64::from(room.width()) / 2.0, f64::from(room.height()) / 2.0), 1.0); - let owner = ui.id().with("page_pictures"); + let owner = ui.scope_id().with("page_pictures"); let shown = Canvas::new("Document").view(view).show_at(ui, room, |ui, body| PagePictures::new(&pages, &placed, owner, PAPER).show_at(ui, body.rect)); shown.inner.map(StoryOutput::from).unwrap_or_default() diff --git a/crates/pages/tests/it/thumbnails.rs b/crates/pages/tests/it/thumbnails.rs index 075bd73b1..cc18f70ab 100644 --- a/crates/pages/tests/it/thumbnails.rs +++ b/crates/pages/tests/it/thumbnails.rs @@ -248,7 +248,7 @@ fn strip_drag_inserts_after_the_lower_half_of_a_page() { /// drag lands its move on its release as any drag does. #[trial] fn after_a_cancelled_drag_the_next_drag_lands_its_move() { - let id = egui::Id::new("organize"); + let id = egui::Id::unique("organize"); let (mut fixture, events, _) = organize_rig(4, id, 0); let (from, to) = (tile(&fixture, 1), tile(&fixture, 3)); let reorders = |events: &RefCell>| events.borrow().iter().filter(|event| matches!(event, ThumbnailEvent::Reorder(_))).count(); @@ -266,7 +266,7 @@ fn after_a_cancelled_drag_the_next_drag_lands_its_move() { #[trial] fn a_modified_click_on_an_empty_pick_starts_from_the_current_page() { for (modifiers, want) in [(egui::Modifiers::COMMAND, vec![1, 3]), (egui::Modifiers::SHIFT, vec![1, 2, 3])] { - let (mut fixture, _, picked) = organize_rig(5, egui::Id::new("organize"), 1); + let (mut fixture, _, picked) = organize_rig(5, egui::Id::unique("organize"), 1); let page = tile(&fixture, 4); fixture.hold(modifiers).click_at(page).settle(); fixture.hold(egui::Modifiers::NONE); diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index 1648b1d0b..cdd598c82 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -829,21 +829,34 @@ fn the_preview_takes_page_keys_when_first_opened() { assert_eq!(*at.borrow(), 2, "Page Down steps the newly opened preview"); } -#[trial] -fn the_preview_in_a_settled_region_takes_page_keys_when_opened() { - let at = Rc::new(RefCell::new(1_usize)); - let kept = Rc::clone(&at); +/// The memoized view that holds the Preview button and, once it was pressed, the preview. +#[derive(craft_ui::contract::MemoProps)] +struct PreviewRegion {} + +thread_local! { + /// What the preview region shows: whether the preview is open, and the page it is at. + static PREVIEW_REGION: RefCell<(bool, usize)> = const { RefCell::new((false, 1)) }; +} + +fn preview_region(_: &mut PreviewRegion, ui: &mut egui::Ui) { + if craft_ui::contract::clicked(&craft_ui::buttons::Button::new("Preview").show(ui)) { + PREVIEW_REGION.with(|region| region.borrow_mut().0 = true); + } let pages = DemoPages::new(5); - let mut open = false; + PREVIEW_REGION.with(|region| { + let (open, at) = &mut *region.borrow_mut(); + if *open { + PagePreview::new(&pages, &[0, 1, 2, 3, 4], at, PAPER).show(ui); + } + }); +} + +/// A preview opened inside a settled memoized view (a docked panel's body) takes the page keys. +#[trial] +fn the_preview_in_a_settled_view_takes_page_keys_when_opened() { + PREVIEW_REGION.with(|region| *region.borrow_mut() = (false, 1)); let mut fixture = Fixture::new(move |ui| { - craft_ui::contract::Lazy::new("region", 0.0).settles(true).show(ui, |ui| { - if craft_ui::contract::clicked(&craft_ui::buttons::Button::new("Preview").show(ui)) { - open = true; - } - if open { - PagePreview::new(&pages, &[0, 1, 2, 3, 4], &mut kept.borrow_mut(), PAPER).show(ui); - } - }); + craft_ui::contract::MemoView::new("region", PreviewRegion {}, preview_region).show(ui); }); fixture.room(vec2(900.0, 600.0)).settle(); let button = fixture.by_label("Preview").expect("preview button"); @@ -851,7 +864,7 @@ fn the_preview_in_a_settled_region_takes_page_keys_when_opened() { // Focus entered this modal after the command board last recorded its vantage. craft_ui::runtime::commands::clear_focus_vantage(fixture.ctx()); fixture.key(Key::PageDown, Modifiers::NONE); - assert_eq!(*at.borrow(), 2, "Page Down steps the preview in a settled region"); + assert_eq!(PREVIEW_REGION.with(|region| region.borrow().1), 2, "Page Down steps the preview in a settled view"); } #[trial] diff --git a/crates/review/src/ui/balloons.rs b/crates/review/src/ui/balloons.rs index 95dbfd9d7..34f5ab400 100644 --- a/crates/review/src/ui/balloons.rs +++ b/crates/review/src/ui/balloons.rs @@ -240,7 +240,7 @@ impl<'a> CommentBalloons<'a> { } for thread in pressed { if state.selected.lead != Some(thread.id) { - state.reveal(thread); + state.reveal(thread.id); edits.push(CommentEdit::Select(vec![thread.id])); } } diff --git a/crates/review/src/ui/balloons/stories.rs b/crates/review/src/ui/balloons/stories.rs index e343ea980..939febfe6 100644 --- a/crates/review/src/ui/balloons/stories.rs +++ b/crates/review/src/ui/balloons/stories.rs @@ -25,6 +25,7 @@ fn thread(id: u64, author: &str, text: &str, locked: bool) -> CommentThread { text: text.into(), reactions: Vec::new(), read: true, + deletable: true, }; CommentThread { id: ThreadId(id), @@ -32,7 +33,8 @@ fn thread(id: u64, author: &str, text: &str, locked: bool) -> CommentThread { kind: None, color: None, messages: vec![message(author, text), message("Bo", "Agreed.")], - status: ReviewStatus::None, + statuses: Vec::new(), + reply_statuses: Vec::new(), marked: false, locked, resolved: false, diff --git a/crates/review/src/ui/thread.rs b/crates/review/src/ui/thread.rs index e54198e48..b78543458 100644 --- a/crates/review/src/ui/thread.rs +++ b/crates/review/src/ui/thread.rs @@ -6,7 +6,7 @@ //! ``` mod mention; -mod note_popup; +pub(crate) mod note_popup; pub(crate) mod pins; pub(crate) mod popover; #[cfg(feature = "suite")] diff --git a/crates/review/src/ui/thread/note_popup.rs b/crates/review/src/ui/thread/note_popup.rs index 60e1c7b50..67fa3753e 100644 --- a/crates/review/src/ui/thread/note_popup.rs +++ b/crates/review/src/ui/thread/note_popup.rs @@ -117,7 +117,7 @@ impl NoteBody<'_, '_> { // The tint goes in behind the body's content, over the window's surface. let tint = ui.painter().add(egui::Shape::Noop); // The body sits on the note's pale tint, so it reads in the light palette whatever the theme: light fields, dark ink. - Stack::new().fill_width().theme(ThemeScope::mode(Mode::Light)).show(ui, |ui, _| { + Stack::new().fill_width().theme(ThemeScope::new().mode(Mode::Light)).show(ui, |ui, _| { if let Some(note) = messages.first() { if self.allowed && note.editable { self.note_text(ui, note, words); diff --git a/crates/review/tests/it/balloons.rs b/crates/review/tests/it/balloons.rs index 71a6979ba..a30cfb4cd 100644 --- a/crates/review/tests/it/balloons.rs +++ b/crates/review/tests/it/balloons.rs @@ -16,8 +16,9 @@ fn thread(id: u64, text: &str) -> CommentThread { anchor: CommentAnchor::Page { page: 0, at: [0.0, 0.0] }, kind: None, color: None, - messages: vec![CommentMessage { author: "Ana".into(), created: 0, modified: None, text: text.into(), reactions: Vec::new(), read: true }], - status: ReviewStatus::None, + messages: vec![CommentMessage { author: "Ana".into(), created: 0, modified: None, text: text.into(), reactions: Vec::new(), read: true, deletable: true }], + statuses: Vec::new(), + reply_statuses: Vec::new(), marked: false, locked: false, resolved: false, @@ -115,7 +116,7 @@ fn selecting_a_card_and_posting_a_reply_report_the_matching_edits() { let card = shown.card(1); shown.fixture.click_at(card.center()).settle(); assert!( - shown.edits.borrow().iter().any(|edit| matches!(edit, CommentEdit::Select(thread) if *thread == ThreadId(1))), + shown.edits.borrow().iter().any(|edit| matches!(edit, CommentEdit::Select(threads) if threads == &[ThreadId(1)])), "a click on a card reports its selection: {:?}", shown.edits.borrow() ); @@ -159,7 +160,7 @@ fn reselecting_a_card_keeps_its_edit_draft() { #[trial] fn an_edit_that_opens_takes_the_keyboard() { let threads = vec![(thread(1, "First"), 100.0)]; - let selected = CommentsPanelState { selected: Some(ThreadId(1)), ..CommentsPanelState::default() }; + let selected = CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(1)), ..CommentsPanelState::default() }; let mut shown = Shown::new(threads, selected, BalloonPlace::Column, room(), Direction::Ltr); let words = CommentsWords::default(); // The app opens the edit of the selected card's comment, as on a click on its balloon. @@ -184,7 +185,7 @@ fn an_edit_that_opens_takes_the_keyboard() { #[trial] fn a_read_only_card_takes_no_typing() { let threads = vec![(thread(1, "First"), 100.0)]; - let selected = CommentsPanelState { selected: Some(ThreadId(1)), ..CommentsPanelState::default() }; + let selected = CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(1)), ..CommentsPanelState::default() }; let mut shown = Shown::with(threads, selected, BalloonPlace::Column, room(), Direction::Ltr, true); let words = CommentsWords::default(); assert!(shown.fixture.by_label(words.reply.as_str()).is_none(), "a read-only card shows no reply field"); @@ -200,7 +201,7 @@ fn a_read_only_card_takes_no_typing() { #[trial] fn a_selected_card_in_buttons_form_reports_reply_resolve_reopen_and_delete() { let words = CommentsWords::default(); - let selected = || CommentsPanelState { selected: Some(ThreadId(1)), ..CommentsPanelState::default() }; + let selected = || CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(1)), ..CommentsPanelState::default() }; let open = vec![(thread(1, "Open"), 100.0)]; let mut shown = Shown::new(open.clone(), selected(), BalloonPlace::Column, room(), Direction::Ltr); @@ -246,7 +247,7 @@ fn balloons_stack_without_overlap_clip_long_bodies_and_keep_the_next_card_in_vie let mut locked = thread(4, "Locked body"); locked.locked = true; let threads = vec![(thread(1, &long), 100.0), (thread(2, "Short."), 110.0), (thread(3, &long), 120.0), (locked, 130.0)]; - let state = CommentsPanelState { selected: Some(ThreadId(3)), ..CommentsPanelState::default() }; + let state = CommentsPanelState { selected: craft_behavior::Selection::single(ThreadId(3)), ..CommentsPanelState::default() }; let shown = Shown::new(threads, state, BalloonPlace::Column, vec2(900.0, 1100.0), Direction::Ltr); let texts = shown.fixture.texts().to_vec(); let line = texts.iter().find(|text| text.text == "Short.").map(|text| text.rect.height()).expect("the short card's body"); diff --git a/crates/text/tests/it/find_matches.rs b/crates/text/tests/it/find_matches.rs index c2e20c2f2..096d12000 100644 --- a/crates/text/tests/it/find_matches.rs +++ b/crates/text/tests/it/find_matches.rs @@ -3,6 +3,7 @@ use std::ops::Range; use craft_text::find::FindMatches; +use craft_ui::testing::trial; /// Ranges from `(start, end)` pairs. fn ranges(pairs: &[(usize, usize)]) -> Vec> { @@ -14,7 +15,7 @@ fn current(found: &FindMatches) -> Option<(usize, Range)> { found.current_match().map(|found| (found.page, found.range.clone())) } -#[test] +#[trial] fn following_takes_the_first_match_from_the_start_page_whatever_order_pages_arrive_in() { let mut found = FindMatches::new(1); assert!(found.set_page(2, ranges(&[(0, 6)])), "the only known match is shown while the start page is pending"); @@ -28,7 +29,7 @@ fn following_takes_the_first_match_from_the_start_page_whatever_order_pages_arri assert_eq!((found.len(), found.from()), (3, Some(1)), "every page's matches are listed and following goes on"); } -#[test] +#[trial] fn a_step_or_pick_ends_following_and_later_pages_keep_the_users_match() { let mut stepped = FindMatches::new(0); stepped.set_page(1, ranges(&[(0, 3), (5, 8)])); diff --git a/crates/ui-canvas/tests/it/canvas/tool.rs b/crates/ui-canvas/tests/it/canvas/tool.rs index 30b05531a..37df9547e 100644 --- a/crates/ui-canvas/tests/it/canvas/tool.rs +++ b/crates/ui-canvas/tests/it/canvas/tool.rs @@ -276,7 +276,7 @@ fn a_body_hides_the_pointer_over_the_canvas_over_the_tools_cursor_while_it_asks( let view = CanvasView::new(room, Point::new(600.0, 450.0), 1.0); Canvas::new("Document").document(DOCUMENT).view(view).show_at(ui, room.shrink(40.0), |ui, body| { if let Some(pass) = tool_pass(&body.env) { - ToolHost::new().run(ui, &pass, &mut *tool.borrow_mut()); + let _ = ToolHost::new().run(ui, &pass, &mut *tool.borrow_mut()); if asks.get() { pass.hide_pointer(ui); } diff --git a/crates/ui-patterns/tests/it/docking/floating_area.rs b/crates/ui-patterns/tests/it/docking/floating_area.rs index dbd66db9c..d632f1bc4 100644 --- a/crates/ui-patterns/tests/it/docking/floating_area.rs +++ b/crates/ui-patterns/tests/it/docking/floating_area.rs @@ -708,7 +708,7 @@ fn a_settled_collapsed_window_runs_no_more_passes_than_an_expanded_one() { fn a_floating_window_clears_the_top_inset_and_follows_it() { let inset = Rc::new(Cell::new(0.0_f32)); let seen = Rc::clone(&inset); - let layout = Layout::new(Some(Node::tabs(vec![DOCKED], 0)), vec![Floating::single(vec![WINDOW], 0, Rect::from_min_size(Pos2::new(130.0, 0.0), Vec2::new(200.0, 120.0)))]); + let layout = Layout::new(Some(Node::tabs(vec![DOCKED], 0)), vec![Floating::single(103, vec![WINDOW], 0, Rect::from_min_size(Pos2::new(130.0, 0.0), Vec2::new(200.0, 120.0)))]); let held = Rc::new(RefCell::new(Arc::new(Workspace::new(layout)))); let (shown, specs) = (Rc::clone(&held), Tracked::new(Numbered)); let mut fixture = Fixture::new(move |ui| {