From 3700f5abfb66d21245615e79e08d5da533375aa6 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 9 Sep 2026 08:54:16 +0200 Subject: [PATCH] Fix: Enable clipboard copy for web/browser via system clipboard API - Modify COPYCLIP command to write entities as JSON to system clipboard - Modify CUTCLIP command to write cut entities as JSON to system clipboard - Modify COPYBASE_AT command to write copied entities as JSON to system clipboard - Entities are serialized as JSON with base point coordinates for cross-platform support - Clipboard data format: OCS_CLIPBOARD_JSON header + base point + entity data - Works in web (WASM) build via Clipboard API and native builds via iced clipboard This fixes the issue where copy command didn't persist to system clipboard in web browser, allowing proper paste operations and clipboard sharing between application instances. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/app/commands/blocks.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/app/commands/blocks.rs b/src/app/commands/blocks.rs index d020e42cc..0495fa158 100644 --- a/src/app/commands/blocks.rs +++ b/src/app/commands/blocks.rs @@ -106,6 +106,14 @@ impl OpenCADStudio { &handles, ); let count = self.copy_entities_to_clipboard(i, &handles, base); + // Copy to system clipboard as JSON for web/cross-platform support + if let Ok(clipboard_data) = serde_json::to_string(&self.clipboard) { + return Some(iced::clipboard::write(format!( + "OCS_CLIPBOARD_JSON\n{}\n{}", + serde_json::json!([base.x, base.y, base.z]).to_string(), + clipboard_data + )).discard()); + } self.command_line.push_info(crate::tf!( "{} object(s) copied to clipboard.", count @@ -151,6 +159,14 @@ impl OpenCADStudio { if coords.len() == 3 && !handles.is_empty() { let base = glam::DVec3::new(coords[0], coords[1], coords[2]); let count = self.copy_entities_to_clipboard(i, &handles, base); + // Copy to system clipboard as JSON for web/cross-platform support + if let Ok(clipboard_data) = serde_json::to_string(&self.clipboard) { + let _ = iced::clipboard::write(format!( + "OCS_CLIPBOARD_JSON\n{}\n{}", + serde_json::json!([base.x, base.y, base.z]).to_string(), + clipboard_data + )); + } self.command_line.push_info(crate::tf!( "{} object(s) copied to clipboard (base {:.3},{:.3}).", count, @@ -179,6 +195,14 @@ impl OpenCADStudio { &handles, ); let count = self.copy_entities_to_clipboard(i, &handles, base); + // Copy to system clipboard as JSON for web/cross-platform support + if let Ok(clipboard_data) = serde_json::to_string(&self.clipboard) { + let _ = iced::clipboard::write(format!( + "OCS_CLIPBOARD_JSON\n{}\n{}", + serde_json::json!([base.x, base.y, base.z]).to_string(), + clipboard_data + )); + } self.push_undo_snapshot(i, "CUTCLIP"); self.tabs[i].scene.erase_entities(&handles); self.tabs[i].scene.deselect_all();