fix(web): reset design md scroll on remove
This commit is contained in:
parent
5c5c6ec39d
commit
8fc313046f
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue