Fix editor tests
This commit is contained in:
parent
94293b3bf9
commit
a32ad3f907
2 changed files with 38 additions and 32 deletions
|
@ -3404,14 +3404,16 @@ mod tests {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let state = cx
|
let state = cx
|
||||||
.update_window(window.into(), |_, cx| {
|
.update_window(window.into(), |view, cx| {
|
||||||
element.compute_layout(
|
cx.with_view_id(view.entity_id(), |cx| {
|
||||||
Bounds {
|
element.compute_layout(
|
||||||
origin: point(px(500.), px(500.)),
|
Bounds {
|
||||||
size: size(px(500.), px(500.)),
|
origin: point(px(500.), px(500.)),
|
||||||
},
|
size: size(px(500.), px(500.)),
|
||||||
cx,
|
},
|
||||||
)
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -3496,14 +3498,16 @@ mod tests {
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = cx
|
let state = cx
|
||||||
.update_window(window.into(), |_, cx| {
|
.update_window(window.into(), |view, cx| {
|
||||||
element.compute_layout(
|
cx.with_view_id(view.entity_id(), |cx| {
|
||||||
Bounds {
|
element.compute_layout(
|
||||||
origin: point(px(500.), px(500.)),
|
Bounds {
|
||||||
size: size(px(500.), px(500.)),
|
origin: point(px(500.), px(500.)),
|
||||||
},
|
size: size(px(500.), px(500.)),
|
||||||
cx,
|
},
|
||||||
)
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(state.selections.len(), 1);
|
assert_eq!(state.selections.len(), 1);
|
||||||
|
@ -3558,14 +3562,16 @@ mod tests {
|
||||||
|
|
||||||
let mut element = EditorElement::new(&editor, style);
|
let mut element = EditorElement::new(&editor, style);
|
||||||
let state = cx
|
let state = cx
|
||||||
.update_window(window.into(), |_, cx| {
|
.update_window(window.into(), |view, cx| {
|
||||||
element.compute_layout(
|
cx.with_view_id(view.entity_id(), |cx| {
|
||||||
Bounds {
|
element.compute_layout(
|
||||||
origin: point(px(500.), px(500.)),
|
Bounds {
|
||||||
size: size(px(500.), px(500.)),
|
origin: point(px(500.), px(500.)),
|
||||||
},
|
size: size(px(500.), px(500.)),
|
||||||
cx,
|
},
|
||||||
)
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let size = state.position_map.size;
|
let size = state.position_map.size;
|
||||||
|
@ -3582,8 +3588,8 @@ mod tests {
|
||||||
|
|
||||||
// Don't panic.
|
// Don't panic.
|
||||||
let bounds = Bounds::<Pixels>::new(Default::default(), size);
|
let bounds = Bounds::<Pixels>::new(Default::default(), size);
|
||||||
cx.update_window(window.into(), |_, cx| {
|
cx.update_window(window.into(), |view, cx| {
|
||||||
element.paint(bounds, &mut (), cx);
|
cx.paint_view(view.entity_id(), |cx| element.paint(bounds, &mut (), cx))
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2004,11 +2004,9 @@ impl<'a> WindowContext<'a> {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn with_view_id<R>(
|
/// Invoke the given function with the given view id present on the view stack.
|
||||||
&mut self,
|
/// This is a fairly low-level method used to layout views.
|
||||||
view_id: EntityId,
|
pub fn with_view_id<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
|
||||||
f: impl FnOnce(&mut Self) -> R,
|
|
||||||
) -> R {
|
|
||||||
let text_system = self.text_system().clone();
|
let text_system = self.text_system().clone();
|
||||||
text_system.with_view(view_id, || {
|
text_system.with_view(view_id, || {
|
||||||
self.window.next_frame.view_stack.push(view_id);
|
self.window.next_frame.view_stack.push(view_id);
|
||||||
|
@ -2018,7 +2016,9 @@ impl<'a> WindowContext<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn paint_view<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
|
/// Invoke the given function with the given view id present on the view stack.
|
||||||
|
/// This is a fairly low-level method used to paint views.
|
||||||
|
pub fn paint_view<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
|
||||||
self.with_view_id(view_id, |cx| {
|
self.with_view_id(view_id, |cx| {
|
||||||
cx.window
|
cx.window
|
||||||
.next_frame
|
.next_frame
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue