diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 124ff1639..ded130a0e 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1194,7 +1194,7 @@ impl WordApp { // Drawing leaves the caret where it was: following it would pull the view off the ink. if self.session.selects_whole_story() || id == "select.all" { self.canvas.scroll_to_caret = false; - } else if !id.starts_with("view.") && !id.starts_with("document.") && !id.starts_with("format.state") && !id.starts_with("draw.") { + } else if !["ui.", "view.", "document.", "format.state", "draw."].iter().any(|p| id.starts_with(p)) { self.canvas.scroll_to_caret = true; } for req in std::mem::take(&mut self.session.ui_requests) { @@ -6728,6 +6728,17 @@ mod tests { assert!(a.canvas.scroll_to_caret, "typing still brings the caret into view"); } + /// #2054: clicking a ribbon tab while a footer is being edited scrolled the page a little. + #[test] + fn ribbon_tab_click_does_not_follow_the_caret() { + let mut a = typed(); + a.canvas.scroll_to_caret = false; + a.run("ui.tab", json!({"tab": "Design"})).unwrap(); + assert!(!a.canvas.scroll_to_caret, "switching tabs left the view alone"); + a.run("text.insert", json!({"text": "x"})).unwrap(); + assert!(a.canvas.scroll_to_caret, "typing still brings the caret into view"); + } + #[test] fn select_all_does_not_scroll_to_the_end() { let mut a = typed();