ElyPDF: a refused OCR text layer reports no success (P-09)
This commit is contained in:
4 files changed
+41
-7
No files matched your search
@@ -165,10 +165,12 @@ impl Viewer {
|
||||
let Some(view) = self.tab(tab).map(|tab| tab.view.clone()).filter(|_| !pages.is_empty()) else {
|
||||
return self.toast(summary, Severity::Info, cx);
|
||||
};
|
||||
self.on_same(&view, run.version, cx, |view, cx| {
|
||||
let laid = self.on_same(&view, run.version, cx, |view, cx| {
|
||||
view.edit("adding recognised text", move |worker, doc| worker.text_layer(doc, &pages, replace), cx)
|
||||
});
|
||||
self.toast(summary, Severity::Success, cx);
|
||||
if laid {
|
||||
self.toast(summary, Severity::Success, cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// The OCR dialog: the ask, then the progress.
|
||||
|
||||
@@ -234,3 +234,33 @@ fn a_cancelled_run_cannot_touch_the_next() {
|
||||
assert!(cx.update(|_, app| viewer.read(app).ocr.is_some()), "the second run goes on");
|
||||
settle(cx, |app| viewer.read(app).ocr.is_none() && view.read(app).edited == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_text_layer_reports_no_success() {
|
||||
use ely_gpui_component::primitives::Severity;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = scanned(dir.path());
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
let view = shown(cx, &viewer);
|
||||
// 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
|
||||
});
|
||||
let tab = cx.update(|_, app| viewer.read(app).core.tabs[0].id);
|
||||
let run = cx.update(|window, app| viewer.update(app, |viewer, cx| {
|
||||
viewer.ask_ocr(window, cx);
|
||||
viewer.start_ocr(cx);
|
||||
viewer.ocr_runs - 1
|
||||
}));
|
||||
// An edit still runs when the text is laid.
|
||||
cx.update(|_, app| view.update(app, |view, _| view.editing = true));
|
||||
let line = ely_pdf_engine::OcrLine { rect: [72.0, 700.0, 300.0, 720.0], text: "Hello".into() };
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.ocr_read((tab, run, 0), Ok(Some(vec![line])), cx)));
|
||||
settle(cx, |app| viewer.read(app).ocr.is_none());
|
||||
let toasts = cx.update(|_, app| root.read(app).toasts(app));
|
||||
assert!(toasts.iter().any(|(_, severity)| *severity == Some(Severity::Warning)), "{toasts:?}");
|
||||
assert!(!toasts.iter().any(|(_, severity)| *severity == Some(Severity::Success)), "{toasts:?}");
|
||||
}
|
||||
@@ -176,25 +176,27 @@ impl Viewer {
|
||||
self.pick(false, cx, move |viewer, path: PathBuf, cx| {
|
||||
viewer.on_same(&view, version, cx, |view, cx| {
|
||||
view.edit("replacing an image", move |worker, doc| worker.replace_image(doc, page, index, &path), cx)
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Runs `step` on `view` if no edit came since `version`.
|
||||
/// Whether `step` ran: no edit came since `version`.
|
||||
pub(crate) fn on_same(
|
||||
&self,
|
||||
view: &gpui::Entity<crate::view::PdfView>,
|
||||
version: u64,
|
||||
cx: &mut Context<Self>,
|
||||
step: impl FnOnce(&mut crate::view::PdfView, &mut Context<crate::view::PdfView>),
|
||||
) {
|
||||
) -> bool {
|
||||
// Landed or queued, an edit since may move the target.
|
||||
let open = self.core.tabs.iter().any(|tab| tab.view == *view);
|
||||
if !open || view.read(cx).version != version || !view.read(cx).settled() {
|
||||
let text = Self::text(cx, "pdf.object.changed", &[]);
|
||||
return self.toast(text, Severity::Warning, cx);
|
||||
self.toast(text, Severity::Warning, cx);
|
||||
return false;
|
||||
}
|
||||
view.update(cx, step);
|
||||
true
|
||||
}
|
||||
|
||||
/// Asks for a picture; it lands mid-page.
|
||||
|
||||
Reference in new issue
Block a user