瀏覽代碼

fix: event is not being captured sometimes

Peng Xiao 3 年之前
父節點
當前提交
2308a5d120

+ 1 - 1
src/main/frontend/components/search.cljs

@@ -253,7 +253,7 @@
                       (nil? result)
                       all?)
                    []
-                   [{:type :new-page}])
+                   [{:type :new-page}]) ;; todo: add new whiteboard
         result (cond
                  config/publishing?
                  (concat pages files blocks)

+ 19 - 15
tldraw/apps/tldraw-logseq/src/hooks/usePaste.ts

@@ -168,6 +168,7 @@ export function usePaste(context: LogseqContextValue) {
                 pageId: blockRef,
                 blockType: 'B',
               })
+              return true
             }
           } else if (/^\[\[.*\]\]$/.test(rawText)) {
             const pageName = rawText.slice(2, -2)
@@ -179,6 +180,7 @@ export function usePaste(context: LogseqContextValue) {
               pageId: pageName,
               blockType: 'P',
             })
+            return true
           } else if (isValidURL(rawText)) {
             const youtubeId = getYoutubeId(rawText)
             if (youtubeId) {
@@ -188,22 +190,24 @@ export function usePaste(context: LogseqContextValue) {
                 parentId: app.currentPageId,
                 point: [point[0], point[1]],
               })
+              return true
             }
-          } else {
-            const uuid = handlers?.addNewBlock(rawText)
-            if (uuid) {
-              // create text shape
-              shapesToCreate.push({
-                ...LogseqPortalShape.defaultProps,
-                id: uniqueId(),
-                parentId: app.currentPageId,
-                size: [400, 0], // use 0 here to enable auto-resize
-                point: [point[0], point[1]],
-                pageId: uuid,
-                blockType: 'B',
-                compact: true
-              })
-            }
+            // ??? deal with normal URLs?
+          }
+          const uuid = handlers?.addNewBlock(rawText)
+          if (uuid) {
+            // create text shape
+            shapesToCreate.push({
+              ...LogseqPortalShape.defaultProps,
+              id: uniqueId(),
+              parentId: app.currentPageId,
+              size: [400, 0], // use 0 here to enable auto-resize
+              point: [point[0], point[1]],
+              pageId: uuid,
+              blockType: 'B',
+              compact: true,
+            })
+            return true
           }
         }
       }

+ 5 - 0
tldraw/packages/react/src/hooks/useResizeObserver.ts

@@ -81,5 +81,10 @@ export function useResizeObserver<T extends HTMLElement>(
 
   React.useEffect(() => {
     updateBounds()
+    // make sure the document get focus when the component is mounted
+    // so that the document can receive keyboard events
+    setTimeout(() => {
+      ref.current?.querySelector<HTMLElement>('.tl-canvas')?.focus()
+    })
   }, [ref])
 }