|
@@ -1153,7 +1153,10 @@ class App extends React.Component<AppProps, AppState> {
|
|
|
// Copy/paste
|
|
|
|
|
|
private onCut = withBatchedUpdates((event: ClipboardEvent) => {
|
|
|
- if (isWritableElement(event.target)) {
|
|
|
+ const isExcalidrawActive = this.excalidrawContainerRef.current?.contains(
|
|
|
+ document.activeElement,
|
|
|
+ );
|
|
|
+ if (!isExcalidrawActive || isWritableElement(event.target)) {
|
|
|
return;
|
|
|
}
|
|
|
this.cutAll();
|
|
@@ -1161,22 +1164,10 @@ class App extends React.Component<AppProps, AppState> {
|
|
|
});
|
|
|
|
|
|
private onCopy = withBatchedUpdates((event: ClipboardEvent) => {
|
|
|
- const activeSelection = document.getSelection();
|
|
|
- // if there's a selected text is outside the component, prevent our copy
|
|
|
- // action
|
|
|
- if (
|
|
|
- activeSelection?.anchorNode &&
|
|
|
- // it can happen that certain interactions will create a selection
|
|
|
- // outside (or potentially inside) the component without actually
|
|
|
- // selecting anything (i.e. the selection range is collapsed). Copying
|
|
|
- // in such case wouldn't copy anything to the clipboard anyway, so prevent
|
|
|
- // our copy handler only if the selection isn't collapsed
|
|
|
- !activeSelection.isCollapsed &&
|
|
|
- !this.excalidrawContainerRef.current!.contains(activeSelection.anchorNode)
|
|
|
- ) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (isWritableElement(event.target)) {
|
|
|
+ const isExcalidrawActive = this.excalidrawContainerRef.current?.contains(
|
|
|
+ document.activeElement,
|
|
|
+ );
|
|
|
+ if (!isExcalidrawActive || isWritableElement(event.target)) {
|
|
|
return;
|
|
|
}
|
|
|
this.copyAll();
|
|
@@ -1239,6 +1230,13 @@ class App extends React.Component<AppProps, AppState> {
|
|
|
async (event: ClipboardEvent | null) => {
|
|
|
// #686
|
|
|
const target = document.activeElement;
|
|
|
+ const isExcalidrawActive = this.excalidrawContainerRef.current?.contains(
|
|
|
+ target,
|
|
|
+ );
|
|
|
+ if (!isExcalidrawActive) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const elementUnderCursor = document.elementFromPoint(cursorX, cursorY);
|
|
|
if (
|
|
|
// if no ClipboardEvent supplied, assume we're pasting via contextMenu
|