Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix: onPaste should return false to prevent paste action (#3974)

zsviczian7d1fddc14438
diff --git a/src/components/App.tsx b/src/components/App.tsx
index aa75f7f269..bf0642a378 100644
--- a/src/components/App.tsx
+++ b/src/components/App.tsx
@@ -1193,8 +1193,12 @@ class App extends React.Component<AppProps, AppState> {
}
const data = await parseClipboard(event);
if (this.props.onPaste) {
- if (await this.props.onPaste(data, event)) {
- return;
+ try {
+ if ((await this.props.onPaste(data, event)) === false) {
+ return;
+ }
+ } catch (e) {
+ console.error(e);
}
}
if (data.errorMessage) {
diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md
index b3ba79f803..1db617bf38 100644
--- a/src/packages/excalidraw/CHANGELOG.md
+++ b/src/packages/excalidraw/CHANGELOG.md
@@ -21,6 +21,14 @@ Please add the latest change on the top under the correct section.
## Excalidraw API
+### Fixes
+
+- [`onPaste`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPaste) prop should return false to prevent the native excalidraw paste action.
+
+#### BREAKING CHANGE
+
+- Earlier the paste action was prevented when the prop [`onPaste`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPaste) returned true, but now it should return false to prevent the paste action. This was done to make it semantically more correct and intuitive.
+
### Docs
- Correct exportToBackend in README to onExportToBackend [#3952](https://github.com/excalidraw/excalidraw/pull/3952)
diff --git a/src/packages/excalidraw/README_NEXT.md b/src/packages/excalidraw/README_NEXT.md
index b210a7cb35..64b81a5142 100644
--- a/src/packages/excalidraw/README_NEXT.md
+++ b/src/packages/excalidraw/README_NEXT.md
@@ -610,7 +610,7 @@ This callback is triggered if passed when something is pasted into the scene. Yo
This callback must return a `boolean` value or a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) which resolves to a boolean value.
-In case you want to prevent the excalidraw paste action you must return `true`, it will stop the native excalidraw clipboard management flow (nothing will be pasted into the scene).
+In case you want to prevent the excalidraw paste action you must return `false`, it will stop the native excalidraw clipboard management flow (nothing will be pasted into the scene).
### Does it support collaboration ?