diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 618f1c454b..b9726898d9 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -920,6 +920,8 @@ fn drawing_grid_step(spacing: f32, scale: f32) -> f32 { step } +/// Draw the document canvas in the space `ui` has left, one frame: the pages, caret, selection +/// and rulers, with the mouse editing and the pointer shape over them. pub fn show(app: &mut WordApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); let full = ui.available_rect_before_wrap(); @@ -1832,7 +1834,15 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) { let in_bar = app.session.sel.focus.story == StoryRef::Body && (app.canvas.unit_drag.as_ref().is_some_and(|d| d.unit == "line") || latest.and_then(|p| page_at(&rects, &layout, geo.scale, p)).is_some_and(|(pg, x, y)| layout.selection_bar_at(pg, x, y).is_some())); - let fallback = if in_bar { egui::CursorIcon::Default } else { egui::CursorIcon::Text }; + // An armed Format Painter shows over the text, as Word's brush does; egui has no brush, + // so the copy pointer stands in (#3453). The selection bar keeps its arrow. + let fallback = if in_bar { + egui::CursorIcon::Default + } else if app.session.painter.is_some() { + egui::CursorIcon::Copy + } else { + egui::CursorIcon::Text + }; ui.ctx().set_cursor_icon(over_object.unwrap_or(fallback)); } crate::table_resize::cursor(app, ui, &resp, &layout, &rects, geo.scale); @@ -4322,6 +4332,46 @@ mod tests { assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default); } + /// #3453: while the Format Painter is armed the pointer over the text says so, and it goes + /// back once the painter is off. The selection bar keeps its arrow while it is armed. + #[test] + fn an_armed_format_painter_changes_the_pointer() { + let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Default::default()); + a.run("text.insert", json!({"text": "Paint this formatting"})).unwrap(); + a.run("view.commentsPane", json!({"value": false})).unwrap(); + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.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, + ); + for _ in 0..6 { + h.step(); + } + let c = h.state_mut().session.layout().caret(&Pos::body(0, 6)).expect("caret"); + let over_text = page_to_screen(h.state_mut(), c.page, c.x, c.top + c.height / 2.0).expect("on screen"); + let over_bar = page_to_screen(h.state_mut(), c.page, 30.0, c.top + c.height / 2.0).expect("on screen"); + let pointer_after = |h: &mut egui_kittest::Harness<'_, WordApp>, cmd: Option<&str>| { + if let Some(cmd) = cmd { + h.state_mut().run(cmd, json!({})).unwrap(); + } + h.event(egui::Event::PointerMoved(over_text)); + h.step(); + h.output().platform_output.cursor_icon + }; + // Where the I-beam is drawn (Windows, #1746) the system pointer over the text is hidden. + let ibeam = if h.state().canvas.drawn_ibeam { egui::CursorIcon::None } else { egui::CursorIcon::Text }; + assert_eq!(pointer_after(&mut h, None), ibeam, "no painter yet"); + assert_eq!(pointer_after(&mut h, Some("edit.formatPainter")), egui::CursorIcon::Copy, "armed"); + assert_eq!(pointer_after(&mut h, Some("edit.formatPainter")), ibeam, "turned off"); + h.state_mut().run("edit.formatPainter", json!({})).unwrap(); + h.event(egui::Event::PointerMoved(over_bar)); + h.step(); + assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "the selection bar keeps its arrow"); + } + /// #1085: a selected balloon's buttons work (pressing them is not a click on the page that /// leaves the balloon): a new comment with no text resolves and deletes from its balloon. #[test]