Format Painter: show the copy pointer over the text while armed (#3453) (#3560)

* Format Painter: show the copy pointer over the text while armed (#3453)

The canvas chose the I-beam over text whether or not the Format Painter
held copied formatting, so nothing showed the tool was waiting for a
click. While it is armed, the pointer over the text is now the copy
pointer (egui has no paintbrush), the same choice as the open DeckCraft
fix for the same report (storytold/deckcraft#846). Pictures, table
handles and resize edges keep their own pointers.

* Format Painter: the selection bar keeps its arrow while the painter is armed

Review follow-up: the bar's arrow shows that a click there selects whole
lines, so it outranks the painter's copy pointer (#3453).

* Format Painter pointer test: the selection bar keeps its arrow while armed

Review follow-up (#3453): the test now also hovers the selection bar with
the painter armed, so a precedence regression there fails it.

* Canvas: document show()

Review follow-up (#3453): CodeRabbit's docstring check counts the
function the pointer change sits in.

* #3453: Format Painter pointer test requires the I-beam once the painter is off

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* #3453: Format Painter pointer test expects the hidden pointer where the I-beam is drawn

On Windows the canvas hides the system I-beam and draws its own (#1746), so
the pointer over the text reads None there, not Text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mathieu RancourtandClaude Opus 5.5 authored and GitHub committed 2026-10-23 11:53:10 -04:00
1 parent 2d4f146c78
commit 70b681a9ba
1 file changed
+51 -1
+51 -1
View File
@@ -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]