Skip to content

Commit

Permalink
fix: drag-drop / copy-paste should work for multiple files (logseq#11214
Browse files Browse the repository at this point in the history
)

Co-authored-by: Gabriel Horner <[email protected]>
  • Loading branch information
AyushAgrawal-A2 and logseq-cldwalker authored Oct 18, 2024
1 parent 226db20 commit 53d8c5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))))
Expand Down
6 changes: 3 additions & 3 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/main/frontend/handler/paste.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 53d8c5a

Please sign in to comment.