Browse Source

fix: drag-drop / copy-paste should work for multiple files (#11214)

Co-authored-by: Gabriel Horner <[email protected]>
Ayush Agrawal 1 year ago
parent
commit
53d8c5a3c6

+ 3 - 2
src/main/frontend/components/block.cljs

@@ -2693,7 +2693,7 @@
                 (-> (editor-handler/save-assets! repo (js->clj files))
                     (p/then
                      (fn [res]
-                       (when-let [[asset-file-name file-obj asset-file-fpath matched-alias] (and (seq res) (first res))]
+                       (when-let [[asset-file-name file-obj asset-file-fpath matched-alias] (first res)]
                          (let [image? (config/ext-of-image? asset-file-name)
                                link-content (assets-handler/get-asset-file-link format
                                                                                 (if matched-alias
@@ -2709,7 +2709,8 @@
                              :edit-block? false
                              :replace-empty-target? true
                              :sibling?   true
-                             :before?    false}))))))))
+                             :before?    false}))
+                         (recur (rest res))))))))
 
             :else
             (prn ::unhandled-drop-data-transfer-type transfer-types))))))

+ 3 - 3
src/main/frontend/handler/editor.cljs

@@ -1540,10 +1540,9 @@
   (let [repo (state/get-current-repo)]
     (when (config/local-db? repo)
       (-> (save-assets! repo (js->clj files))
-          ;; FIXME: only the first asset is handled
           (p/then
            (fn [res]
-             (when-let [[asset-file-name file-obj asset-file-fpath matched-alias] (and (seq res) (first res))]
+             (when-let [[asset-file-name file-obj asset-file-fpath matched-alias] (first res)]
                (let [image? (config/ext-of-image? asset-file-name)]
                  (insert-command!
                   id
@@ -1558,7 +1557,8 @@
                   format
                   {:last-pattern (if drop-or-paste? "" commands/command-trigger)
                    :restore?     true
-                   :command      :insert-asset})))))
+                   :command      :insert-asset})
+                 (recur (rest res))))))
           (p/finally
             (fn []
               (reset! uploading? false)

+ 5 - 4
src/main/frontend/handler/paste.cljs

@@ -219,10 +219,11 @@
   (when id
     (let [clipboard-data (gobj/get e "clipboardData")
           files (.-files clipboard-data)]
-      (when-let [file (first files)]
-        (when-let [block (state/get-edit-block)]
-          (editor-handler/upload-asset id #js[file] (:block/format block)
-                                       editor-handler/*asset-uploading? true)))
+      (loop [files files]
+        (when-let [file (first files)]
+          (when-let [block (state/get-edit-block)]
+            (editor-handler/upload-asset id #js[file] (:block/format block) editor-handler/*asset-uploading? true))
+          (recur (rest files))))
       (util/stop e))))
 
 (defn editor-on-paste!