diff --git a/editor/src/messages/input_mapper/input_mappings.rs b/editor/src/messages/input_mapper/input_mappings.rs index 02dafca170..2970326d91 100644 --- a/editor/src/messages/input_mapper/input_mappings.rs +++ b/editor/src/messages/input_mapper/input_mappings.rs @@ -210,6 +210,9 @@ pub fn input_mappings() -> Mapping { entry!(KeyDown(Backspace); modifiers=[Accel], action_dispatch=PathToolMessage::DeleteAndBreakPath), entry!(KeyDown(Delete); modifiers=[Shift], action_dispatch=PathToolMessage::BreakPath), entry!(KeyDown(Backspace); modifiers=[Shift], action_dispatch=PathToolMessage::BreakPath), + entry!(KeyDown(KeyX); modifiers=[Accel], action_dispatch=PathToolMessage::Cut { clipboard: Clipboard::Device }), + entry!(KeyDown(KeyC); modifiers=[Accel], action_dispatch=PathToolMessage::Copy { clipboard: Clipboard::Device }), + entry!(KeyDown(KeyD); modifiers=[Accel], action_dispatch=PathToolMessage::Duplicate), entry!(KeyDownNoRepeat(Tab); action_dispatch=PathToolMessage::SwapSelectedHandles), entry!(KeyDown(MouseLeft); action_dispatch=PathToolMessage::MouseDown { extend_selection: Shift, lasso_select: Control, handle_drag_from_anchor: Alt, drag_restore_handle: Control, molding_in_segment_edit: KeyA }), entry!(KeyDown(MouseRight); action_dispatch=PathToolMessage::RightClick), diff --git a/editor/src/messages/portfolio/portfolio_message.rs b/editor/src/messages/portfolio/portfolio_message.rs index 4fb756fc4a..153ad6c039 100644 --- a/editor/src/messages/portfolio/portfolio_message.rs +++ b/editor/src/messages/portfolio/portfolio_message.rs @@ -88,6 +88,9 @@ pub enum PortfolioMessage { PasteSerializedData { data: String, }, + PasteSerializedVector { + data: String, + }, CenterPastedLayers { layers: Vec, }, diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index daa81274a3..20043e23d3 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -3,7 +3,7 @@ use super::document::utility_types::network_interface; use super::spreadsheet::SpreadsheetMessageHandler; use super::utility_types::{PanelType, PersistentData}; use crate::application::generate_uuid; -use crate::consts::DEFAULT_DOCUMENT_NAME; +use crate::consts::{DEFAULT_DOCUMENT_NAME, DEFAULT_STROKE_WIDTH}; use crate::messages::animation::TimingInformation; use crate::messages::debug::utility_types::MessageLoggingVerbosity; use crate::messages::dialog::simple_dialogs; @@ -12,18 +12,23 @@ use crate::messages::layout::utility_types::widget_prelude::*; use crate::messages::portfolio::document::DocumentMessageContext; use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn; use crate::messages::portfolio::document::node_graph::document_node_definitions; +use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type; use crate::messages::portfolio::document::utility_types::clipboards::{Clipboard, CopyBufferEntry, INTERNAL_CLIPBOARD_COUNT}; use crate::messages::portfolio::document::utility_types::network_interface::OutputConnector; use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes; use crate::messages::portfolio::document_migration::*; use crate::messages::preferences::SelectionMode; use crate::messages::prelude::*; +use crate::messages::tool::common_functionality::graph_modification_utils; use crate::messages::tool::utility_types::{HintData, HintGroup, ToolType}; use crate::node_graph_executor::{ExportConfig, NodeGraphExecutor}; +use bezier_rs::BezierHandles; use glam::{DAffine2, DVec2}; use graph_craft::document::NodeId; +use graphene_std::Color; use graphene_std::renderer::Quad; use graphene_std::text::Font; +use graphene_std::vector::{HandleId, PointId, SegmentId, VectorData, VectorModificationType}; use std::vec; #[derive(ExtractField)] @@ -546,6 +551,90 @@ impl MessageHandler> for Portfolio } } } + // Custom paste implementation for path tool + PortfolioMessage::PasteSerializedVector { data } => { + // If using path tool then send the operation to path tool + if *current_tool == ToolType::Path { + responses.add(PathToolMessage::Paste { data }); + } + // If not using path tool, create new layers and add paths into those + else if let Some(document) = self.active_document() { + if let Ok(data) = serde_json::from_str::>(&data) { + let mut layers = Vec::new(); + for (_layer, new_vector, transform) in data { + let node_type = resolve_document_node_type("Path").expect("Path node does not exist"); + let nodes = vec![(NodeId(0), node_type.default_node_template())]; + + let parent = document.new_layer_parent(false); + + let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses); + layers.push(layer); + + // Adding the transform back into the layer + responses.add(GraphOperationMessage::TransformSet { + layer, + transform, + transform_in: TransformIn::Local, + skip_rerender: false, + }); + + // Add default fill and stroke to the layer + let fill_color = Color::WHITE; + let stroke_color = Color::BLACK; + + let fill = graphene_std::vector::style::Fill::solid(fill_color.to_gamma_srgb()); + responses.add(GraphOperationMessage::FillSet { layer, fill }); + + let stroke = graphene_std::vector::style::Stroke::new(Some(stroke_color.to_gamma_srgb()), DEFAULT_STROKE_WIDTH); + responses.add(GraphOperationMessage::StrokeSet { layer, stroke }); + + // Create new point ids and add those into the existing vector data + let mut points_map = HashMap::new(); + for (point, position) in new_vector.point_domain.iter() { + let new_point_id = PointId::generate(); + points_map.insert(point, new_point_id); + let modification_type = VectorModificationType::InsertPoint { id: new_point_id, position }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + + // Create new segment ids and add the segments into the existing vector data + let mut segments_map = HashMap::new(); + for (segment_id, bezier, start, end) in new_vector.segment_bezier_iter() { + let new_segment_id = SegmentId::generate(); + + segments_map.insert(segment_id, new_segment_id); + + let handles = match bezier.handles { + BezierHandles::Linear => [None, None], + BezierHandles::Quadratic { handle } => [Some(handle - bezier.start), None], + BezierHandles::Cubic { handle_start, handle_end } => [Some(handle_start - bezier.start), Some(handle_end - bezier.end)], + }; + + let points = [points_map[&start], points_map[&end]]; + let modification_type = VectorModificationType::InsertSegment { id: new_segment_id, points, handles }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + + // Set G1 continuity + for handles in new_vector.colinear_manipulators { + let to_new_handle = |handle: HandleId| -> HandleId { + HandleId { + ty: handle.ty, + segment: segments_map[&handle.segment], + } + }; + let new_handles = [to_new_handle(handles[0]), to_new_handle(handles[1])]; + let modification_type = VectorModificationType::SetG1Continuous { handles: new_handles, enabled: true }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + } + + responses.add(NodeGraphMessage::RunDocumentGraph); + responses.add(Message::StartBuffer); + responses.add(PortfolioMessage::CenterPastedLayers { layers }); + } + } + } PortfolioMessage::CenterPastedLayers { layers } => { if let Some(document) = self.active_document_mut() { let viewport_bounds_quad_pixels = Quad::from_box([DVec2::ZERO, ipp.viewport_bounds.size()]); diff --git a/editor/src/messages/tool/common_functionality/shape_editor.rs b/editor/src/messages/tool/common_functionality/shape_editor.rs index f98e50f079..3d913674bd 100644 --- a/editor/src/messages/tool/common_functionality/shape_editor.rs +++ b/editor/src/messages/tool/common_functionality/shape_editor.rs @@ -56,6 +56,9 @@ pub struct SelectedLayerState { } impl SelectedLayerState { + pub fn is_empty(&self) -> bool { + self.selected_points.is_empty() && self.selected_segments.is_empty() + } pub fn selected_points(&self) -> impl Iterator + '_ { self.selected_points.iter().copied() } diff --git a/editor/src/messages/tool/tool_messages/path_tool.rs b/editor/src/messages/tool/tool_messages/path_tool.rs index a8b10afaa9..b851fcead6 100644 --- a/editor/src/messages/tool/tool_messages/path_tool.rs +++ b/editor/src/messages/tool/tool_messages/path_tool.rs @@ -1,16 +1,20 @@ use super::select_tool::extend_lasso; use super::tool_prelude::*; use crate::consts::{ - COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GRAY, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, DOUBLE_CLICK_MILLISECONDS, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, DRAG_THRESHOLD, DRILL_THROUGH_THRESHOLD, - HANDLE_ROTATE_SNAP_ANGLE, SEGMENT_INSERTION_DISTANCE, SEGMENT_OVERLAY_SIZE, SELECTION_THRESHOLD, SELECTION_TOLERANCE, + COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GRAY, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, DEFAULT_STROKE_WIDTH, DOUBLE_CLICK_MILLISECONDS, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, DRAG_THRESHOLD, + DRILL_THROUGH_THRESHOLD, HANDLE_ROTATE_SNAP_ANGLE, SEGMENT_INSERTION_DISTANCE, SEGMENT_OVERLAY_SIZE, SELECTION_THRESHOLD, SELECTION_TOLERANCE, }; +use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn; +use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type; use crate::messages::portfolio::document::overlays::utility_functions::{path_overlays, selected_segments}; use crate::messages::portfolio::document::overlays::utility_types::{DrawHandles, OverlayContext}; +use crate::messages::portfolio::document::utility_types::clipboards::Clipboard; use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier}; use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface; use crate::messages::portfolio::document::utility_types::transformation::Axis; use crate::messages::preferences::SelectionMode; use crate::messages::tool::common_functionality::auto_panning::AutoPanning; +use crate::messages::tool::common_functionality::graph_modification_utils; use crate::messages::tool::common_functionality::pivot::{PivotGizmo, PivotGizmoType, PivotToolSource, pin_pivot_widget, pivot_gizmo_type_widget, pivot_reference_point_widget}; use crate::messages::tool::common_functionality::shape_editor::{ ClosestSegment, ManipulatorAngle, OpposingHandleLengths, SelectedLayerState, SelectedPointsInfo, SelectionChange, SelectionShape, SelectionShapeType, ShapeState, @@ -18,8 +22,10 @@ use crate::messages::tool::common_functionality::shape_editor::{ use crate::messages::tool::common_functionality::snapping::{SnapCache, SnapCandidatePoint, SnapConstraint, SnapData, SnapManager}; use crate::messages::tool::common_functionality::utility_functions::{calculate_segment_angle, find_two_param_best_approximate}; use bezier_rs::{Bezier, BezierHandles, TValue}; +use graphene_std::Color; use graphene_std::renderer::Quad; use graphene_std::transform::ReferencePoint; +use graphene_std::uuid::NodeId; use graphene_std::vector::click_target::ClickTargetType; use graphene_std::vector::{HandleExt, HandleId, NoHashBuilder, SegmentId, VectorData}; use graphene_std::vector::{ManipulatorPointId, PointId, VectorModificationType}; @@ -117,6 +123,17 @@ pub enum PathToolMessage { UpdateSelectedPointsStatus { overlay_context: OverlayContext, }, + Copy { + clipboard: Clipboard, + }, + Cut { + clipboard: Clipboard, + }, + DeleteSelected, + Paste { + data: String, + }, + Duplicate, } #[derive(PartialEq, Eq, Hash, Copy, Clone, Debug, Default, serde::Serialize, serde::Deserialize, specta::Type)] @@ -388,6 +405,11 @@ impl<'a> MessageHandler> for Path DeleteAndBreakPath, ClosePath, PointerMove, + Copy, + Cut, + DeleteSelected, + Paste, + Duplicate ), PathToolFsmState::Dragging(_) => actions!(PathToolMessageDiscriminant; Escape, @@ -399,6 +421,11 @@ impl<'a> MessageHandler> for Path BreakPath, DeleteAndBreakPath, SwapSelectedHandles, + Copy, + Cut, + DeleteSelected, + Paste, + Duplicate ), PathToolFsmState::Drawing { .. } => actions!(PathToolMessageDiscriminant; DoubleClick, @@ -2237,6 +2264,280 @@ impl Fsm for PathToolFsmState { shape_editor.delete_point_and_break_path(document, responses); PathToolFsmState::Ready } + (_, PathToolMessage::Copy { clipboard }) => { + // TODO: Add support for selected segments + + let mut buffer = Vec::new(); + + for (&layer, layer_selection_state) in &shape_editor.selected_shape_state { + if layer_selection_state.is_empty() { + continue; + } + + let Some(old_vector_data) = document.network_interface.compute_modified_vector(layer) else { + continue; + }; + + // Also get the transform node that is applied on the layer if it exists + let transform = document.metadata().transform_to_document(layer); + + let mut new_vector_data = VectorData::default(); + + let mut selected_points_by_segment = HashSet::new(); + old_vector_data + .segment_bezier_iter() + .filter(|(segment, _, _, _)| layer_selection_state.is_segment_selected(*segment)) + .for_each(|(_, _, start, end)| { + selected_points_by_segment.insert(start); + selected_points_by_segment.insert(end); + }); + + // Add all the selected points + for (point, position) in old_vector_data.point_domain.iter() { + if layer_selection_state.is_point_selected(ManipulatorPointId::Anchor(point)) || selected_points_by_segment.contains(&point) { + new_vector_data.point_domain.push(point, position); + } + } + + let find_index = |id: PointId| { + new_vector_data + .point_domain + .iter() + .enumerate() + .find(|(_, (point_id, _))| *point_id == id) + .expect("Point does not exist in point domain") + .0 + }; + + // Add segments which have selected ends + for ((segment_id, bezier, start, end), stroke) in old_vector_data.segment_bezier_iter().zip(old_vector_data.segment_domain.stroke().iter()) { + let both_ends_selected = layer_selection_state.is_point_selected(ManipulatorPointId::Anchor(start)) && layer_selection_state.is_point_selected(ManipulatorPointId::Anchor(end)); + let segment_selected = layer_selection_state.is_segment_selected(segment_id); + if both_ends_selected || segment_selected { + let start_index = find_index(start); + let end_index = find_index(end); + new_vector_data.segment_domain.push(segment_id, start_index, end_index, bezier.handles, *stroke); + } + } + + for handles in old_vector_data.colinear_manipulators { + if new_vector_data.segment_domain.ids().contains(&handles[0].segment) && new_vector_data.segment_domain.ids().contains(&handles[1].segment) { + new_vector_data.colinear_manipulators.push(handles); + } + } + + buffer.push((layer, new_vector_data, transform)); + } + + if clipboard == Clipboard::Device { + let mut copy_text = String::from("graphite/vector: "); + copy_text += &serde_json::to_string(&buffer).expect("Could not serialize paste"); + + responses.add(FrontendMessage::TriggerTextCopy { copy_text }); + } else { + //TODO: Add implementation for internal clipboard + } + + PathToolFsmState::Ready + } + (_, PathToolMessage::Cut { clipboard }) => { + responses.add(PathToolMessage::Copy { clipboard }); + // Delete the selected points/ segments + responses.add(PathToolMessage::DeleteSelected); + + PathToolFsmState::Ready + } + (_, PathToolMessage::DeleteSelected) => { + //Delete the selected points and segments + shape_editor.delete_point_and_break_path(document, responses); + shape_editor.delete_selected_segments(document, responses); + + PathToolFsmState::Ready + } + (_, PathToolMessage::Duplicate) => { + responses.add(DocumentMessage::AddTransaction); + + // Copy the existing selected geometry and paste it in the existing layers + for (layer, layer_selection_state) in shape_editor.selected_shape_state.clone() { + if layer_selection_state.is_empty() { + continue; + } + + let Some(old_vector_data) = document.network_interface.compute_modified_vector(layer) else { + continue; + }; + + // Add all the selected points + let mut selected_points_by_segment = HashSet::new(); + old_vector_data + .segment_bezier_iter() + .filter(|(segment, _, _, _)| layer_selection_state.is_segment_selected(*segment)) + .for_each(|(_, _, start, end)| { + selected_points_by_segment.insert(start); + selected_points_by_segment.insert(end); + }); + let mut points_map = HashMap::new(); + for (point, position) in old_vector_data.point_domain.iter() { + //TODO: Either the point is selected or it is an endpoint of a selected segment + + if layer_selection_state.is_point_selected(ManipulatorPointId::Anchor(point)) || selected_points_by_segment.contains(&point) { + // insert the same point with new id + let new_id = PointId::generate(); + points_map.insert(point, new_id); + let modification_type = VectorModificationType::InsertPoint { id: new_id, position }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + } + + let mut segments_map = HashMap::new(); + for (segment_id, bezier, start, end) in old_vector_data.segment_bezier_iter() { + let both_ends_selected = layer_selection_state.is_point_selected(ManipulatorPointId::Anchor(start)) && layer_selection_state.is_point_selected(ManipulatorPointId::Anchor(end)); + let segment_selected = layer_selection_state.is_segment_selected(segment_id); + if both_ends_selected || segment_selected { + let new_id = SegmentId::generate(); + segments_map.insert(segment_id, new_id); + + let handles = match bezier.handles { + BezierHandles::Linear => [None, None], + BezierHandles::Quadratic { handle } => [Some(handle - bezier.start), None], + BezierHandles::Cubic { handle_start, handle_end } => [Some(handle_start - bezier.start), Some(handle_end - bezier.end)], + }; + + let points = [points_map[&start], points_map[&end]]; + let modification_type = VectorModificationType::InsertSegment { id: new_id, points, handles }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + } + + for handles in old_vector_data.colinear_manipulators { + let to_new_handle = |handle: HandleId| -> HandleId { + HandleId { + ty: handle.ty, + segment: segments_map[&handle.segment], + } + }; + + if segments_map.contains_key(&handles[0].segment) && segments_map.contains_key(&handles[1].segment) { + let new_handles = [to_new_handle(handles[0]), to_new_handle(handles[1])]; + let modification_type = VectorModificationType::SetG1Continuous { handles: new_handles, enabled: true }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + } + + shape_editor.deselect_all_points(); + shape_editor.deselect_all_segments(); + + // Set selection to newly inserted points and segments + let state = shape_editor.selected_shape_state.get_mut(&layer).expect("No state for layer"); + if tool_options.path_editing_mode.point_editing_mode { + points_map.values().for_each(|point| state.select_point(ManipulatorPointId::Anchor(*point))); + } + if tool_options.path_editing_mode.segment_editing_mode { + segments_map.values().for_each(|segment| state.select_segment(*segment)); + } + } + + PathToolFsmState::Ready + } + (_, PathToolMessage::Paste { data }) => { + // Deserialize the data + if let Ok(data) = serde_json::from_str::>(&data) { + shape_editor.deselect_all_points(); + responses.add(DocumentMessage::AddTransaction); + let mut new_layers = Vec::new(); + for (layer, new_vector, transform) in data { + // If layer is not selected then create a new selected layer + let layer = if shape_editor.selected_shape_state.contains_key(&layer) { + layer + } else { + let node_type = resolve_document_node_type("Path").expect("Path node does not exist"); + let nodes = vec![(NodeId(0), node_type.default_node_template())]; + + let parent = document.new_layer_parent(false); + + let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses); + + let fill_color = Color::WHITE; + let stroke_color = Color::BLACK; + + let fill = graphene_std::vector::style::Fill::solid(fill_color.to_gamma_srgb()); + responses.add(GraphOperationMessage::FillSet { layer, fill }); + + let stroke = graphene_std::vector::style::Stroke::new(Some(stroke_color.to_gamma_srgb()), DEFAULT_STROKE_WIDTH); + responses.add(GraphOperationMessage::StrokeSet { layer, stroke }); + new_layers.push(layer); + + responses.add(GraphOperationMessage::TransformSet { + layer, + transform, + transform_in: TransformIn::Local, + skip_rerender: false, + }); + layer + }; + // Create new point ids and add those into the existing vector data + let mut points_map = HashMap::new(); + for (point, position) in new_vector.point_domain.iter() { + let new_point_id = PointId::generate(); + points_map.insert(point, new_point_id); + let modification_type = VectorModificationType::InsertPoint { id: new_point_id, position }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + + // Create new segment ids and add the segments into the existing vector data + let mut segments_map = HashMap::new(); + for (segment_id, bezier, start, end) in new_vector.segment_bezier_iter() { + let new_segment_id = SegmentId::generate(); + + segments_map.insert(segment_id, new_segment_id); + + let handles = match bezier.handles { + BezierHandles::Linear => [None, None], + BezierHandles::Quadratic { handle } => [Some(handle - bezier.start), None], + BezierHandles::Cubic { handle_start, handle_end } => [Some(handle_start - bezier.start), Some(handle_end - bezier.end)], + }; + + let points = [points_map[&start], points_map[&end]]; + let modification_type = VectorModificationType::InsertSegment { id: new_segment_id, points, handles }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + + // Set G1 continuity + for handles in new_vector.colinear_manipulators { + let to_new_handle = |handle: HandleId| -> HandleId { + HandleId { + ty: handle.ty, + segment: segments_map[&handle.segment], + } + }; + let new_handles = [to_new_handle(handles[0]), to_new_handle(handles[1])]; + let modification_type = VectorModificationType::SetG1Continuous { handles: new_handles, enabled: true }; + responses.add(GraphOperationMessage::Vector { layer, modification_type }); + } + + if !shape_editor.selected_shape_state.contains_key(&layer) { + shape_editor.selected_shape_state.insert(layer, SelectedLayerState::default()); + } + + // Set selection to newly inserted points + let state = shape_editor.selected_shape_state.get_mut(&layer).expect("No state for layer"); + // points_map.values().for_each(|point| state.select_point(ManipulatorPointId::Anchor(*point))); + if tool_options.path_editing_mode.point_editing_mode { + points_map.values().for_each(|point| state.select_point(ManipulatorPointId::Anchor(*point))); + } + if tool_options.path_editing_mode.segment_editing_mode { + segments_map.values().for_each(|segment| state.select_segment(*segment)); + } + } + + if !new_layers.is_empty() { + responses.add(Message::StartBuffer); + responses.add(PortfolioMessage::CenterPastedLayers { layers: new_layers }); + } + } + + PathToolFsmState::Ready + } (_, PathToolMessage::DoubleClick { extend_selection, shrink_selection }) => { // Double-clicked on a point (flip smooth/sharp behavior) let nearest_point = shape_editor.find_nearest_point_indices(&document.network_interface, input.mouse.position, SELECTION_THRESHOLD); diff --git a/frontend/src/io-managers/input.ts b/frontend/src/io-managers/input.ts index bb7b035ceb..c77137a04d 100644 --- a/frontend/src/io-managers/input.ts +++ b/frontend/src/io-managers/input.ts @@ -307,6 +307,8 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli editor.handle.pasteSerializedData(text.substring(16, text.length)); } else if (text.startsWith("graphite/nodes: ")) { editor.handle.pasteSerializedNodes(text.substring(16, text.length)); + } else if (text.startsWith("graphite/vector: ")) { + editor.handle.pasteSerializedVector(text.substring(17, text.length)); } }); } diff --git a/frontend/wasm/src/editor_api.rs b/frontend/wasm/src/editor_api.rs index c8056e4efc..89fc0e7185 100644 --- a/frontend/wasm/src/editor_api.rs +++ b/frontend/wasm/src/editor_api.rs @@ -506,6 +506,13 @@ impl EditorHandle { self.dispatch(message); } + /// Paste vector data into a new layer from a serialized json representation + #[wasm_bindgen(js_name = pasteSerializedVector)] + pub fn paste_serialized_vector(&self, data: String) { + let message = PortfolioMessage::PasteSerializedVector { data }; + self.dispatch(message); + } + #[wasm_bindgen(js_name = clipLayer)] pub fn clip_layer(&self, id: u64) { let id = NodeId(id); diff --git a/node-graph/gcore/src/vector/vector_data/attributes.rs b/node-graph/gcore/src/vector/vector_data/attributes.rs index ea4460c78c..559e963d76 100644 --- a/node-graph/gcore/src/vector/vector_data/attributes.rs +++ b/node-graph/gcore/src/vector/vector_data/attributes.rs @@ -304,7 +304,7 @@ impl SegmentDomain { &self.stroke } - pub(crate) fn push(&mut self, id: SegmentId, start: usize, end: usize, handles: BezierHandles, stroke: StrokeId) { + pub fn push(&mut self, id: SegmentId, start: usize, end: usize, handles: BezierHandles, stroke: StrokeId) { debug_assert!(!self.id.contains(&id), "Tried to push an existing point to a point domain"); self.id.push(id);