|
@@ -560,44 +560,20 @@ export class App extends React.Component<any, AppState> {
|
560
|
560
|
if (
|
561
|
561
|
// if no ClipboardEvent supplied, assume we're pasting via contextMenu
|
562
|
562
|
// thus these checks don't make sense
|
563
|
|
- !event ||
|
564
|
|
- (elementUnderCursor instanceof HTMLCanvasElement &&
|
565
|
|
- !isWritableElement(target))
|
|
563
|
+ event &&
|
|
564
|
+ (!(elementUnderCursor instanceof HTMLCanvasElement) ||
|
|
565
|
+ isWritableElement(target))
|
566
|
566
|
) {
|
567
|
|
- const data = await getClipboardContent(event);
|
568
|
|
- if (data.elements) {
|
569
|
|
- this.addElementsFromPaste(data.elements);
|
570
|
|
- } else if (data.text) {
|
571
|
|
- const { x, y } = viewportCoordsToSceneCoords(
|
572
|
|
- { clientX: cursorX, clientY: cursorY },
|
573
|
|
- this.state,
|
574
|
|
- this.canvas,
|
575
|
|
- window.devicePixelRatio,
|
576
|
|
- );
|
577
|
|
-
|
578
|
|
- const element = newTextElement({
|
579
|
|
- x: x,
|
580
|
|
- y: y,
|
581
|
|
- strokeColor: this.state.currentItemStrokeColor,
|
582
|
|
- backgroundColor: this.state.currentItemBackgroundColor,
|
583
|
|
- fillStyle: this.state.currentItemFillStyle,
|
584
|
|
- strokeWidth: this.state.currentItemStrokeWidth,
|
585
|
|
- roughness: this.state.currentItemRoughness,
|
586
|
|
- opacity: this.state.currentItemOpacity,
|
587
|
|
- text: data.text,
|
588
|
|
- font: this.state.currentItemFont,
|
589
|
|
- });
|
590
|
|
-
|
591
|
|
- globalSceneState.replaceAllElements([
|
592
|
|
- ...globalSceneState.getAllElements(),
|
593
|
|
- element,
|
594
|
|
- ]);
|
595
|
|
- this.setState({ selectedElementIds: { [element.id]: true } });
|
596
|
|
- history.resumeRecording();
|
597
|
|
- }
|
598
|
|
- this.selectShapeTool("selection");
|
599
|
|
- event?.preventDefault();
|
|
567
|
+ return;
|
|
568
|
+ }
|
|
569
|
+ const data = await getClipboardContent(event);
|
|
570
|
+ if (data.elements) {
|
|
571
|
+ this.addElementsFromPaste(data.elements);
|
|
572
|
+ } else if (data.text) {
|
|
573
|
+ this.addTextFromPaste(data.text);
|
600
|
574
|
}
|
|
575
|
+ this.selectShapeTool("selection");
|
|
576
|
+ event?.preventDefault();
|
601
|
577
|
},
|
602
|
578
|
);
|
603
|
579
|
|
|
@@ -639,6 +615,35 @@ export class App extends React.Component<any, AppState> {
|
639
|
615
|
});
|
640
|
616
|
};
|
641
|
617
|
|
|
618
|
+ private addTextFromPaste(text: any) {
|
|
619
|
+ const { x, y } = viewportCoordsToSceneCoords(
|
|
620
|
+ { clientX: cursorX, clientY: cursorY },
|
|
621
|
+ this.state,
|
|
622
|
+ this.canvas,
|
|
623
|
+ window.devicePixelRatio,
|
|
624
|
+ );
|
|
625
|
+
|
|
626
|
+ const element = newTextElement({
|
|
627
|
+ x: x,
|
|
628
|
+ y: y,
|
|
629
|
+ strokeColor: this.state.currentItemStrokeColor,
|
|
630
|
+ backgroundColor: this.state.currentItemBackgroundColor,
|
|
631
|
+ fillStyle: this.state.currentItemFillStyle,
|
|
632
|
+ strokeWidth: this.state.currentItemStrokeWidth,
|
|
633
|
+ roughness: this.state.currentItemRoughness,
|
|
634
|
+ opacity: this.state.currentItemOpacity,
|
|
635
|
+ text: text,
|
|
636
|
+ font: this.state.currentItemFont,
|
|
637
|
+ });
|
|
638
|
+
|
|
639
|
+ globalSceneState.replaceAllElements([
|
|
640
|
+ ...globalSceneState.getAllElements(),
|
|
641
|
+ element,
|
|
642
|
+ ]);
|
|
643
|
+ this.setState({ selectedElementIds: { [element.id]: true } });
|
|
644
|
+ history.resumeRecording();
|
|
645
|
+ }
|
|
646
|
+
|
642
|
647
|
// Collaboration
|
643
|
648
|
|
644
|
649
|
setAppState = (obj: any) => {
|