PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Wait for the text layer in text_selection_action_icons
skylar taylor-barrick3f18a53d511d
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 2b3366e9c..bef745197 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -1464,6 +1464,12 @@ impl DocView {self.texts.get(&page).cloned()}+ /// Whether `page`'s text layer has arrived from the renderer. Selecting text, the I-beam and+ /// find matches on a page all wait for it (tests and automation).+ pub fn has_page_text(&self, page: usize) -> bool {+ self.texts.contains_key(&page)+ }+pub(crate) fn clear_selection(&mut self) {self.selection = None;}diff --git a/crates/ui-egui/tests/editing.rs b/crates/ui-egui/tests/editing.rsindex 6efab8114..cb7d4a0ec 100644--- a/crates/ui-egui/tests/editing.rs+++ b/crates/ui-egui/tests/editing.rs@@ -3052,7 +3052,9 @@ fn tiny_image_crop_handle_drag_does_not_panic() {#[test]fn text_selection_action_icons() {let mut h = harness(1, |_| {});- h.run_steps(4);+ // Dragging selects only once the page's text layer is in, and it comes from the render pool+ // in the background: under load a fixed number of frames was sometimes not enough.+ support::wait_until(&mut h, "page 1's text layer", |app| app.views[0].has_page_text(0));let r = h.state().views[0].page_screen_rect(0).expect("on screen");let p0 = egui::pos2(r.left() + 40.0 / 200.0 * r.width(), r.top() + (300.0 - 158.0) / 300.0 * r.height());let p1 = egui::pos2(r.left() + 100.0 / 200.0 * r.width(), r.top() + (300.0 - 158.0) / 300.0 * r.height());