Prevent default on native clipboard events (#3536)
This PR calls prevent default on native clipboard events. This prevents the error sound on Safari. ### Change Type - [x] `sdk` — Changes the tldraw SDK - [x] `bugfix` — Bug fix ### Test Plan 1. Use the cut, copy, and paste events on Safari. 2. Everything should still work, but no sounds should play. ### Release Notes - Fix copy sound on clipboard events.
This commit is contained in:
parent
b5dfd81540
commit
b5fab15c6d
1 changed files with 16 additions and 8 deletions
|
@ -9,6 +9,8 @@ import {
|
|||
TLTextShape,
|
||||
VecLike,
|
||||
isNonNull,
|
||||
preventDefault,
|
||||
stopEventPropagation,
|
||||
uniq,
|
||||
useEditor,
|
||||
useValue,
|
||||
|
@ -615,24 +617,29 @@ export function useNativeClipboardEvents() {
|
|||
|
||||
useEffect(() => {
|
||||
if (!appIsFocused) return
|
||||
const copy = () => {
|
||||
const copy = (e: ClipboardEvent) => {
|
||||
if (
|
||||
editor.getSelectedShapeIds().length === 0 ||
|
||||
editor.getEditingShapeId() !== null ||
|
||||
disallowClipboardEvents(editor)
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
preventDefault(e)
|
||||
handleNativeOrMenuCopy(editor)
|
||||
trackEvent('copy', { source: 'kbd' })
|
||||
}
|
||||
|
||||
function cut() {
|
||||
function cut(e: ClipboardEvent) {
|
||||
if (
|
||||
editor.getSelectedShapeIds().length === 0 ||
|
||||
editor.getEditingShapeId() !== null ||
|
||||
disallowClipboardEvents(editor)
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
preventDefault(e)
|
||||
handleNativeOrMenuCopy(editor)
|
||||
editor.deleteShapes(editor.getSelectedShapeIds())
|
||||
trackEvent('cut', { source: 'kbd' })
|
||||
|
@ -648,9 +655,9 @@ export function useNativeClipboardEvents() {
|
|||
}
|
||||
}
|
||||
|
||||
const paste = (event: ClipboardEvent) => {
|
||||
const paste = (e: ClipboardEvent) => {
|
||||
if (disablingMiddleClickPaste) {
|
||||
event.stopPropagation()
|
||||
stopEventPropagation(e)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -660,8 +667,8 @@ export function useNativeClipboardEvents() {
|
|||
if (editor.getEditingShapeId() !== null || disallowClipboardEvents(editor)) return
|
||||
|
||||
// First try to use the clipboard data on the event
|
||||
if (event.clipboardData && !editor.inputs.shiftKey) {
|
||||
handlePasteFromEventClipboardData(editor, event.clipboardData)
|
||||
if (e.clipboardData && !editor.inputs.shiftKey) {
|
||||
handlePasteFromEventClipboardData(editor, e.clipboardData)
|
||||
} else {
|
||||
// Or else use the clipboard API
|
||||
navigator.clipboard.read().then((clipboardItems) => {
|
||||
|
@ -671,6 +678,7 @@ export function useNativeClipboardEvents() {
|
|||
})
|
||||
}
|
||||
|
||||
preventDefault(e)
|
||||
trackEvent('paste', { source: 'kbd' })
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue