M8: Copy link to page in the page context menu (#2379)

This commit is contained in:
Aathish committed 2026-11-16 23:52:24 +05:30
1 parent 4548d6c009
commit 0322e2a2c8
4 files changed
+76

No files matched your search

+4
View File
@@ -118,3 +118,7 @@ real_name = "Ashok Ram"
[people.GiovanniBot]
sync_github_name = true
[people.Aathish-D]
real_name = "Aathish Duraiswamy"
sync_github_name = true
+1
View File
@@ -360,6 +360,7 @@ name = "English"
"Copy fill" = "Copy fill"
"Copy for AI" = "Copy for AI"
"Copy link" = "Copy link"
"Copy link to page" = "Copy link to page"
"Copy stroke" = "Copy stroke"
"Copy the {label}" = "Copy the {label}"
"Copy {value}" = "Copy {value}"
@@ -4,11 +4,14 @@
//! list (dragging pages, dividers). Rows the documentation is silent on say so and pin today's
//! behaviour. What the gestures do to the document is in the engine's `panels_behaviour_tests`.
use std::sync::{Arc, Mutex};
use egui::{Event, Id, Modifiers, Pos2};
use figcraft_doc::NodeId;
use figcraft_engine::Session;
use serde_json::json;
use crate::Services;
use crate::layers_drag_tests::Ui;
fn id(v: serde_json::Value) -> NodeId {
@@ -687,6 +690,68 @@ fn the_page_menu_sets_the_opening_page_and_not_on_dividers() {
assert!(u.app.ui.last_error.is_none(), "{:?}", u.app.ui.last_error);
}
/// Right-clicks `at` in the pages list and returns the menu's "Copy link to page" item, if shown.
fn copy_link_item(u: &mut Ui, at: Pos2) -> Option<Pos2> {
u.frame(vec![
Event::PointerMoved(at),
Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE },
]);
u.frame(vec![Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }]);
let shapes: Vec<egui::Shape> = u.frame_output(vec![]).shapes.into_iter().map(|c| c.shape).collect();
crate::live_tests::has_text(&shapes, "Copy link to page").then(|| crate::live_tests::text_center(&shapes, "Copy link to page"))
}
/// The pages list's menu offers "Copy link to page" on a page and not on a divider, and using it
/// copies the page's node link to the clipboard and shows a toast without moving the viewer's page (#2379).
#[test]
fn the_page_menu_copies_link_to_page_and_not_on_dividers() {
let mut s = Session::new();
let p1 = s.page().unwrap();
let p2 = id(s.execute("page.add", &json!({})).unwrap());
let div = id(s.execute("page.add", &json!({"name": "-"})).unwrap());
s.execute("page.move", &json!({"id": div, "index": 1})).unwrap();
s.execute("page.select", &json!({"id": p1})).unwrap();
let mut u = Ui::new(s);
let copied = Arc::new(Mutex::new(Vec::new()));
struct Clip(Arc<Mutex<Vec<String>>>);
impl Services for Clip {
fn clipboard_set_text(&mut self, s: &str) {
self.0.lock().unwrap().push(s.to_string());
}
}
u.app.services = Box::new(Clip(copied.clone()));
let (r1, r2) = (page_row(&mut u, p1, p2), page_row(&mut u, p2, p1));
let mid = Pos2::new(r1.x, (r1.y + r2.y) / 2.0);
u.app.session.execute("page.select", &json!({"id": p1})).unwrap();
u.frame(vec![]);
// A divider has no "Copy link to page" menu item.
assert_eq!(copy_link_item(&mut u, mid), None, "a divider has no such item");
u.frame(vec![Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }]);
for _ in 0..5 {
u.frame(vec![]);
}
// A normal page has "Copy link to page".
let item = copy_link_item(&mut u, r2).expect("a page has the item (and its menu is open)");
u.frame(vec![Event::PointerMoved(item)]);
u.button(item, true);
u.button(item, false);
for _ in 0..3 {
u.frame(vec![]);
}
// Checks:
// 1. Link format is `figcraft://node/<p2_id>`
assert_eq!(*copied.lock().unwrap(), vec![format!("figcraft://node/{}", p2.0)]);
// 2. Toast "Link copied" is shown
assert_eq!(u.app.ui.toast.as_ref().map(|t| t.0.as_str()), Some("Link copied"));
// 3. Document opening page and viewer's current page are unaffected
assert_ne!(u.app.session.doc().unwrap().current_page, Some(p2));
assert_eq!(u.app.session.page().unwrap(), p1);
assert!(u.app.ui.last_error.is_none(), "{:?}", u.app.ui.last_error);
}
/// The y of the line between the pages and the layers, above the layers' row at `layer` (found by
/// the resize cursor it shows when hovered).
fn pages_edge_at(u: &mut Ui, layer: f32) -> f32 {
+6
View File
@@ -333,6 +333,12 @@ fn pages(app: &mut FigApp, ui: &mut Ui) {
}
ui.close();
}
// Copy link to page (#2379); a divider can't be linked.
if !divider && ui.button(tr("Copy link to page")).clicked() {
app.clipboard_set_text(&format!("figcraft://node/{}", id.0));
app.toast(tr("Link copied"));
ui.close();
}
// The page the file opens on, for everyone (#1817); a divider can't be one.
if !divider && ui.button(tr("Set as opening page")).clicked() {
if !crate::menus::dev_mode_refuses(app, "page.setOpening") {