Browse Source

fix: should not pasting html when shiftkey is down

Peng Xiao 3 years ago
parent
commit
cd1e8d88a9

+ 2 - 2
tldraw/apps/tldraw-logseq/src/hooks/usePaste.ts

@@ -31,7 +31,7 @@ const getYoutubeId = (url: string) => {
 export function usePaste(context: LogseqContextValue) {
   const { handlers } = context
 
-  return React.useCallback<TLReactCallbacks<Shape>['onPaste']>(async (app, { point }) => {
+  return React.useCallback<TLReactCallbacks<Shape>['onPaste']>(async (app, { point, shiftKey }) => {
     const assetId = uniqueId()
     interface ImageAsset extends TLAsset {
       size: number[]
@@ -218,7 +218,7 @@ export function usePaste(context: LogseqContextValue) {
       try {
         let handled = await handleImage(item)
 
-        if (!handled) {
+        if (!handled && !shiftKey) {
           handled = await handleHTML(item)
         }
 

+ 8 - 3
tldraw/packages/core/src/lib/TLApp/TLApp.ts

@@ -115,7 +115,11 @@ export class TLApp<
         keys: 'mod+a',
         fn: () => {
           const { selectedTool } = this
-          if (selectedTool.currentState.id !== 'idle') return
+          if (
+            selectedTool.currentState.id !== 'idle' &&
+            !selectedTool.currentState.id.includes('hovering')
+          )
+            return
           if (selectedTool.id !== 'select') {
             this.selectTool('select')
           }
@@ -218,7 +222,7 @@ export class TLApp<
       currentPageId: this.currentPageId,
       selectedIds: Array.from(this.selectedIds.values()),
       pages: Array.from(this.pages.values()).map(page => page.serialized),
-      assets: this.getCleanUpAssets()
+      assets: this.getCleanUpAssets(),
     }
   }
 
@@ -376,10 +380,11 @@ export class TLApp<
     }
   }
 
-  paste = (e?: ClipboardEvent) => {
+  paste = (e?: ClipboardEvent, shiftKey?: boolean) => {
     if (!this.editingShape) {
       this.notify('paste', {
         point: this.inputs.currentPoint,
+        shiftKey: !!shiftKey,
       })
     }
   }

+ 1 - 1
tldraw/packages/core/src/types/types.ts

@@ -158,7 +158,7 @@ export type TLSubscriptionEvent =
     }
   | {
       event: 'paste'
-      info: { point: number[] }
+      info: { point: number[]; shiftKey: boolean }
     }
   | {
       event: 'create-assets'

+ 4 - 1
tldraw/packages/react/src/hooks/useKeyboardEvents.ts

@@ -6,20 +6,23 @@ import type { TLReactCustomEvents } from '~types'
 export function useKeyboardEvents(ref: React.RefObject<HTMLDivElement>) {
   const app = useApp()
   const { callbacks } = useRendererContext()
+  const shiftKeyDownRef = React.useRef(false)
 
   React.useEffect(() => {
     const onKeyDown: TLReactCustomEvents['keyboard'] = e => {
       callbacks.onKeyDown?.({ type: TLTargetType.Canvas, order: -1 }, e)
+      shiftKeyDownRef.current = e.shiftKey
     }
 
     const onKeyUp: TLReactCustomEvents['keyboard'] = e => {
       callbacks.onKeyUp?.({ type: TLTargetType.Canvas, order: -1 }, e)
+      shiftKeyDownRef.current = e.shiftKey
     }
 
     const onPaste = (e: ClipboardEvent) => {
       if (!app.editingShape && ref.current?.contains(document.activeElement)) {
         e.preventDefault()
-        app.paste(e)
+        app.paste(e, shiftKeyDownRef.current)
       }
     }