ElyPDF: a preview overtaken by an edit says so (P-10)
This commit is contained in:
3 files changed
+38
-2
No files matched your search
@@ -397,3 +397,33 @@ fn a_small_picture_on_text_under_a_page_form_still_aims() {
|
||||
click(cx, &view, (140.0, 66.0));
|
||||
assert!(matches!(cx.update(|_, app| view.read(app).aim), Some(Aim::Text { .. })), "the text, not the form around it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_preview_overtaken_by_an_edit_says_so() {
|
||||
use ely_gpui_component::primitives::Severity;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let (viewer, cx, view) = editing(&mut cx, dir.path());
|
||||
// The window's toasts live on its root.
|
||||
let root = cx.update(|window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Pdf, viewer.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
viewer.update(app, |viewer, _| viewer.core.root = root.downgrade());
|
||||
root
|
||||
});
|
||||
click(cx, &view, (80.0, 66.0));
|
||||
type_in(cx, &viewer, "Hi world\nSecond line");
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| {
|
||||
// A new font asks for a preview first.
|
||||
viewer.edit_panel.update(cx, |panel, _| panel.font = "times".into());
|
||||
viewer.write_text(false, cx);
|
||||
// An edit lands before the preview answers.
|
||||
if let Some(view) = viewer.active_view() {
|
||||
view.update(cx, |view, _| view.version += 1);
|
||||
}
|
||||
}));
|
||||
let changed = cx.update(|_, app| Viewer::text(app, "pdf.object.changed", &[]));
|
||||
settle(cx, |app| root.read(app).toasts(app).iter().any(|(text, severity)| *severity == Some(Severity::Warning) && *text == changed));
|
||||
frames(cx);
|
||||
assert!(cx.update(|_, app| viewer.read(app).preview.is_none()), "no stale preview");
|
||||
assert_eq!(cx.update(|_, app| view.read(app).edited), 0, "nothing written");
|
||||
}
|
||||
@@ -71,7 +71,8 @@ impl Viewer {
|
||||
let (asked, viewer) = (writing.clone(), cx.weak_entity());
|
||||
view.update(cx, |view, cx| {
|
||||
let doc = view.doc;
|
||||
view.read(
|
||||
// A stale answer still reaches `previewed`, which says so.
|
||||
view.off(
|
||||
move |worker| worker.put_text(doc, page, &asked, PREVIEW),
|
||||
move |_, answer, cx| {
|
||||
// The viewer edits this view; wait until it is free.
|
||||
@@ -95,6 +96,11 @@ impl Viewer {
|
||||
replacing: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let same = self.tab(tab).is_some_and(|open| open.view.read(cx).version == version);
|
||||
if !same {
|
||||
let text = Self::text(cx, "pdf.object.changed", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
}
|
||||
match answer {
|
||||
Ok(Wrote::Unwritable) => {
|
||||
let note = Self::text(cx, "pdf.text.unwritable", &[]);
|
||||
|
||||
Reference in new issue
Block a user