1
0
Эх сурвалжийг харах

fix: sometimes dragging or pasting images don't work

related to #2545
Tienson Qin 4 жил өмнө
parent
commit
d408605c12

+ 0 - 9
src/main/frontend/components/editor.cljs

@@ -332,15 +332,6 @@
        (absolute-modal cp set-default-width? pos)))))
 
 (rum/defc image-uploader < rum/reactive
-  {:did-mount    (fn [state]
-                   (let [[id format] (:rum/args state)]
-                     (add-watch editor-handler/*asset-pending-file ::pending-asset
-                                (fn [_ _ _ f]
-                                  (reset! *slash-caret-pos (cursor/get-caret-pos (gdom/getElement id)))
-                                  (editor-handler/upload-asset id #js[f] format editor-handler/*asset-uploading? true))))
-                   state)
-   :will-unmount (fn [state]
-                   (remove-watch editor-handler/*asset-pending-file ::pending-asset))}
   [id format]
   [:div.image-uploader
    [:input

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

@@ -51,7 +51,6 @@
 ;; FIXME: should support multiple images concurrently uploading
 
 
-(defonce *asset-pending-file (atom nil))
 (defonce *asset-uploading? (atom false))
 (defonce *asset-uploading-process (atom 0))
 (defonce *selected-text (atom nil))
@@ -1521,9 +1520,6 @@
               (reset! *asset-uploading? false)
               (reset! *asset-uploading-process process)))))))))
 
-(defn set-asset-pending-file [file]
-  (reset! *asset-pending-file file))
-
 ;; Editor should track some useful information, like editor modes.
 ;; For example:
 ;; 1. Which file format is it, markdown or org mode?
@@ -2788,9 +2784,9 @@
                    items (or (.-items clipboard-data)
                              (.-files clipboard-data))
                    picked (pick-one-allowed-item items)]
-               (if (get picked 1)
-                 (match picked
-                   [:asset file] (set-asset-pending-file file))))]
+               (when-let [file (second picked)]
+                 (when-let [block (state/get-edit-block)]
+                   (upload-asset id #js[file] (:block/format block) *asset-uploading? true))))]
       (util/stop e)
       (paste-text (.getData (gobj/get e "clipboardData") "text") e))))