diff --git a/crates/op-host-web/src/widget_host/design_md_press.rs b/crates/op-host-web/src/widget_host/design_md_press.rs index dc4a1be75..917472e1b 100644 --- a/crates/op-host-web/src/widget_host/design_md_press.rs +++ b/crates/op-host-web/src/widget_host/design_md_press.rs @@ -74,6 +74,7 @@ impl WidgetHost { // first so a stray remove is undoable. let snap = self.editor_state.snapshot_for_history(); self.editor_state.doc.design_md = None; + self.editor_state.editor_ui.design_md_scroll.offset = 0.0; self.editor_state.history_push_past(snap); } DesignMdHit::Inside => { diff --git a/crates/op-host-web/src/widget_host/design_md_press_tests.rs b/crates/op-host-web/src/widget_host/design_md_press_tests.rs index 1d51194f6..b7fd744ed 100644 --- a/crates/op-host-web/src/widget_host/design_md_press_tests.rs +++ b/crates/op-host-web/src/widget_host/design_md_press_tests.rs @@ -106,3 +106,39 @@ fn design_md_panel_trackpad_pan_scrolls_content_without_panning_canvas() { assert_eq!(host.editor_state.viewport.pan_x, pan_x); assert_eq!(host.editor_state.viewport.pan_y, pan_y); } + +#[test] +fn design_md_remove_press_clears_scroll_offset() { + let mut host = WidgetHost::new(); + let panel_rect = open_long_design_md(&mut host); + let max_scroll = op_editor_ui::widgets::DesignMdPanel::for_editor(&host.editor_state) + .expect("open design md panel"); + let max_scroll = max_scroll.max_scroll(panel_rect); + host.editor_state.editor_ui.design_md_scroll.offset = max_scroll; + let panel = op_editor_ui::widgets::DesignMdPanel::for_editor(&host.editor_state) + .expect("open design md panel"); + + let mut point = None; + let mut y = panel_rect.origin.y; + while y <= panel_rect.origin.y + panel_rect.size.y && point.is_none() { + let mut x = panel_rect.origin.x; + while x <= panel_rect.origin.x + panel_rect.size.x { + let p = op_editor_ui::Point2D::new(x, y); + if matches!( + panel.hit_test(panel_rect, p), + Some(op_editor_ui::widgets::DesignMdHit::Remove) + ) { + point = Some(p); + break; + } + x += 4.0; + } + y += 4.0; + } + let point = point.expect("remove action is hittable"); + + assert!(host.apply_press(point.x, point.y, VIEWPORT_W, VIEWPORT_H)); + + assert!(host.editor_state.doc.design_md.is_none()); + assert_eq!(host.editor_state.editor_ui.design_md_scroll.offset, 0.0); +}