-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from stone-lyl/feat-copy-paste
feat: enhance keyboard shortcuts and implement cross-panel copy-paste functionality
- Loading branch information
Showing
4 changed files
with
69 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SEdge, SNode } from '../../../SerializedReactFlow'; | ||
|
||
export const writeToClipboard = ({ | ||
selectedNodes, | ||
selectedEdges, | ||
}: { | ||
selectedNodes: SNode[]; | ||
selectedEdges: SEdge[]; | ||
}) => { | ||
// Write to system clipboard | ||
navigator.clipboard.writeText( | ||
JSON.stringify({ | ||
nodes: selectedNodes, | ||
edges: selectedEdges, | ||
}), | ||
); | ||
} | ||
|
||
export const readFromClipboard = async(): Promise<{ nodes: SNode[]; edges: SEdge[] }> => { | ||
let nodes: SNode[] = []; | ||
let edges: SEdge[] = []; | ||
try { | ||
// Read from system clipboard | ||
const text = await navigator.clipboard.readText(); | ||
nodes = JSON.parse(text).nodes ?? []; | ||
edges = JSON.parse(text).edges ?? []; | ||
} catch(e) { | ||
console.warn('Error reading from clipboard', e); | ||
} | ||
return { nodes, edges }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters