Skip to content

Commit 390a0d5

Browse files
committed
fix: move canvas context menu to content layer so right-click works
The context menu was on the background area (Order::Background) but the content layer (Order::Middle) intercepted right-clicks first. Moved to the content layer's background rect with Sense::click() so right-click on empty canvas now correctly shows "Copy Link to Position".
1 parent c4bd6c5 commit 390a0d5

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

src/app.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -667,33 +667,6 @@ impl eframe::App for VoidApp {
667667
}
668668
}
669669

670-
// Canvas context menu — Copy Link with coordinates + zoom
671-
bg_resp.context_menu(|ui| {
672-
if ui.button("Copy Link to Position").clicked() {
673-
// Use the pointer position where the right-click happened
674-
let canvas_pos = ui
675-
.input(|i| i.pointer.hover_pos())
676-
.map(|pos| self.viewport.screen_to_canvas(pos, canvas_rect))
677-
.unwrap_or_else(|| {
678-
// Fallback: center of the visible canvas
679-
self.viewport.visible_canvas_rect(canvas_rect).center()
680-
});
681-
let ws_id = self.ws().id;
682-
let z = self.viewport.zoom;
683-
let url = format!(
684-
"void://open/{ws_id}/@{:.0},{:.0},{:.2}",
685-
canvas_pos.x, canvas_pos.y, z
686-
);
687-
if let Ok(mut clipboard) = arboard::Clipboard::new() {
688-
let _ = clipboard.set_text(&url);
689-
}
690-
let time = ui.input(|i| i.time);
691-
self.toast =
692-
Some(Toast::new("Position link copied to clipboard", 2.0, time));
693-
ui.close_menu();
694-
}
695-
});
696-
697670
// Status bar: zoom level + pointer canvas coordinates (bottom-left)
698671
let zoom_pct = format!("{:.0}%", self.viewport.zoom * 100.0);
699672
let pointer_info = if let Some(pos) = ui.input(|i| i.pointer.hover_pos()) {
@@ -730,7 +703,7 @@ impl eframe::App for VoidApp {
730703
.show(ctx, |ui| {
731704
ctx.set_transform_layer(ui.layer_id(), transform);
732705
ui.set_clip_rect(clip);
733-
ui.allocate_rect(clip, egui::Sense::hover());
706+
let canvas_bg_resp = ui.allocate_rect(clip, egui::Sense::click());
734707

735708
let mut order: Vec<usize> = (0..self.ws().panels.len()).collect();
736709
order.sort_by_key(|&i| self.ws().panels[i].z_index());
@@ -898,6 +871,33 @@ impl eframe::App for VoidApp {
898871
}
899872
}
900873

874+
// Canvas context menu — Copy Link with coordinates + zoom
875+
// Placed in the content layer (Order::Middle) so it receives right-clicks
876+
// that the background layer (Order::Background) would miss.
877+
canvas_bg_resp.context_menu(|ui| {
878+
if ui.button("Copy Link to Position").clicked() {
879+
let canvas_pos = ui
880+
.input(|i| i.pointer.hover_pos())
881+
.map(|pos| self.viewport.screen_to_canvas(pos, canvas_rect))
882+
.unwrap_or_else(|| {
883+
self.viewport.visible_canvas_rect(canvas_rect).center()
884+
});
885+
let ws_id = self.ws().id;
886+
let z = self.viewport.zoom;
887+
let url = format!(
888+
"void://open/{ws_id}/@{:.0},{:.0},{:.2}",
889+
canvas_pos.x, canvas_pos.y, z
890+
);
891+
if let Ok(mut clipboard) = arboard::Clipboard::new() {
892+
let _ = clipboard.set_text(&url);
893+
}
894+
let time = ui.input(|i| i.time);
895+
self.toast =
896+
Some(Toast::new("Position link copied to clipboard", 2.0, time));
897+
ui.close_menu();
898+
}
899+
});
900+
901901
// Draw snap guides
902902
let painter = ui.painter();
903903
let guide_stroke =

0 commit comments

Comments
 (0)