Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/ui-egui/src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ pub(crate) fn show_block_zoomed(
let rect = egui::Rect::from_min_max(start, egui::pos2(start.x + ui.available_width().max(1.0), end.y.max(start.y + 1.0)));
let response = ui.interact(rect, id, egui::Sense::click());
if let Some(kind) = object_kind(block) {
// Read every response flag before `data_mut`: `clicked` and
// `double_clicked` take the context lock that `data_mut` holds.
let clicked = response.clicked();
let double_clicked = response.double_clicked();
let pointer = response.interact_pointer_pos();
ui.data_mut(|data| {
let mut hits = data.get_temp::<Vec<(usize, egui::Rect, String)>>(object_hits_id()).unwrap_or_default();
Expand All @@ -670,7 +673,7 @@ pub(crate) fn show_block_zoomed(
if clicked {
data.insert_temp(object_clicked_id(), (i, kind.to_string()));
}
if response.double_clicked() {
if double_clicked {
data.insert_temp(object_double_clicked_id(), (i, kind.to_string()));
}
});
Expand Down
26 changes: 26 additions & 0 deletions crates/ui-egui/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3705,6 +3705,32 @@ fn double_clicking_an_attachment_card_opens_it() {
assert!(h.query_all_by_label_contains("Open attachment").count() >= 1, "double click opened the attachment prompt: {}", look_at(&mut h));
}

/// Issue #15: a click beside a formula, diagram or picture lands on its row's own
/// response. Reading that response's click state inside `data_mut` took the context lock twice
/// and froze the window (a debug build panics after 10s).
#[test]
fn clicking_beside_a_formula_does_not_deadlock() {
let (_t, mut app, s) = sample_app("ui-object-row-click");
let md = s.md_page.to_string_lossy().to_string();
app.open_path(&md);
let mut h = harness(app, LIGHT);
settle(&mut h);
ask(&mut h, "engine.execute", json!({"command": "page.save", "params": {"path": md.clone(), "body": "Some words.\n\n$$\nx^2\n$$\n"}}))
.expect("write a page with a formula");
ask(&mut h, "engine.execute", json!({"command": "page.containers", "params": {"path": md.clone(), "boxes": "0,0,700,2"}}))
.expect("arrange the page in a wide box");
ask(&mut h, "ui.open", json!({"path": md})).expect("open the formula page");
settle(&mut h);
let origin = look_at(&mut h).pointer("/page/origin").and_then(Value::as_array).cloned().unwrap_or_default();
let ox = origin.first().and_then(Value::as_f64).unwrap_or(0.0);
let oy = origin.get(1).and_then(Value::as_f64).unwrap_or(0.0);
for count in [1, 2] {
ask(&mut h, "ui.click", json!({"x": ox + 680.0, "y": oy + 60.0, "count": count})).expect("click beside the formula");
settle(&mut h);
}
assert_eq!(look_at(&mut h).pointer("/page/blocks").and_then(Value::as_u64), Some(2), "the page still draws its formula");
}

#[test]
fn delete_and_backspace_remove_a_selected_picture() {
for key in ["Delete", "Backspace"] {
Expand Down
Loading