Browse Source

fix: can't copy and paste multiple blocks

Tienson Qin 4 years ago
parent
commit
077ce43b59

+ 2 - 2
src/main/frontend/db.cljs

@@ -42,9 +42,9 @@
   get-block-parent get-block-parents parents-collapsed? get-block-referenced-blocks
   get-block-children-ids get-block-immediate-children get-block-page
   get-blocks-contents get-custom-css
-  get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file
+  get-date-scheduled-or-deadlines get-db-type get-file
   get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id file-exists?
-  get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
+  get-file-pages get-files get-files-blocks get-files-full get-journals-length
   get-latest-journals get-matched-blocks get-page get-page-alias get-page-alias-names get-page-blocks get-page-linked-refs-refed-pages
   get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-properties
   get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references get-page-referenced-blocks-no-cache

+ 0 - 29
src/main/frontend/db/model.cljs

@@ -769,19 +769,6 @@
      (distinct))))
 
 ;; Ignore files with empty blocks for now
-(defn get-empty-pages
-  [repo]
-  (when-let [conn (conn/get-conn repo)]
-    (->
-     (d/q
-      '[:find ?page
-        :where
-        [?p :block/name ?page]
-        (not [?p :block/file])]
-      conn)
-     (db-utils/seq-flatten)
-     (distinct))))
-
 (defn get-pages-relation
   [repo with-journal?]
   (when-let [conn (conn/get-conn repo)]
@@ -950,22 +937,6 @@
                (sort-by-left-recursive)
                db-utils/group-by-page))))))
 
-(defn get-files-that-referenced-page
-  [page-id]
-  (when-let [repo (state/get-current-repo)]
-    (when-let [db (conn/get-conn repo)]
-      (->> (d/q
-            '[:find ?path
-              :in $ ?page-id
-              :where
-              [?block :block/refs ?page-id]
-              [?block :block/page ?p]
-              [?p :block/file ?f]
-              [?f :file/path ?path]]
-            db
-            page-id)
-           (db-utils/seq-flatten)))))
-
 (defn get-page-unlinked-references
   [page]
   (when-let [repo (state/get-current-repo)]

+ 0 - 5
src/main/frontend/db/utils.cljs

@@ -42,11 +42,6 @@
              (group-by :block/page))
     blocks))
 
-(defn group-by-file
-  [blocks]
-  (some->> blocks
-           (group-by :block/file)))
-
 (defn get-tx-id [tx-report]
   (get-in tx-report [:tempids :db/current-tx]))
 

+ 1 - 1
src/main/frontend/handler/draw.cljs

@@ -31,7 +31,7 @@
           (db/transact! repo
                         [{:file/path path
                           :block/name file
-                          :block/file [:file/path path]
+                          :block/file {:file/path path}
                           :block/journal? false}]))
          (p/catch (fn [error]
                     (prn "Write file failed, path: " path ", data: " data)

+ 24 - 25
src/main/frontend/handler/editor.cljs

@@ -1942,7 +1942,7 @@
             editing-block))))
 
 (defn- paste-block-tree-at-point-edit-aux
-  [uuid page exclude-properties format content-update-fn]
+  [uuid file page exclude-properties format content-update-fn]
   (fn [block]
     (outliner-core/block
      (let [[new-content new-title]
@@ -1964,34 +1964,33 @@
            new-content
            (->> new-content
                 (property/remove-property format "id")
-                (property/remove-property format "custom_id"))]
-       (conj {:block/uuid uuid
-              :block/page (select-keys page [:db/id])
-              :block/format format
-              :block/properties (apply dissoc (:block/properties block)
-                                       (concat [:id :custom_id :custom-id]
-                                               exclude-properties))
-              :block/meta (dissoc (:block/meta block) :start-pos :end-pos)
-              :block/content new-content
-              :block/title new-title}
-             (dissoc block
-                     :block/pre-block?
-                     :block/uuid
-                     :block/page
-                     :db/id
-                     :block/left
-                     :block/parent
-                     :block/format
-                     :block/properties
-                     :block/meta
-                     :block/content
-                     :block/title))))))
+                (property/remove-property format "custom_id"))
+           m (merge (dissoc block
+                            :block/pre-block?
+                            :block/uuid
+                            :db/id
+                            :block/left
+                            :block/parent
+                            :block/file)
+                    {:block/uuid uuid
+                     :block/page (select-keys page [:db/id])
+                     :block/format format
+                     :block/properties (apply dissoc (:block/properties block)
+                                         (concat [:id :custom_id :custom-id]
+                                                 exclude-properties))
+                     :block/meta (dissoc (:block/meta block) :start-pos :end-pos)
+                     :block/content new-content
+                     :block/title new-title})]
+       (if file
+         (assoc m :block/file (select-keys file [:db/id]))
+         m)))))
 
 (defn- paste-block-tree-at-point
   ([tree exclude-properties] (paste-block-tree-at-point tree exclude-properties nil))
   ([tree exclude-properties content-update-fn]
    (let [repo (state/get-current-repo)
-         page (:block/page (db/entity (:db/id (state/get-edit-block))))]
+         page (:block/page (db/entity (:db/id (state/get-edit-block))))
+         file (:block/file page)]
      (when-let [[target-block sibling? delete-editing-block? editing-block]
                 (get-block-tree-insert-pos-at-point)]
        (let [target-block (outliner-core/block target-block)
@@ -2010,7 +2009,7 @@
                       (recur (zip/next (zip/edit
                                         loc
                                         (paste-block-tree-at-point-edit-aux
-                                         uuid page exclude-properties format content-update-fn)))))))))
+                                         uuid file page exclude-properties format content-update-fn)))))))))
              _ (outliner-core/save-node editing-block)
              _ (outliner-core/insert-nodes metadata-replaced-blocks target-block sibling?)
              _ (when delete-editing-block?

+ 2 - 2
src/main/frontend/handler/extract.cljs

@@ -68,7 +68,7 @@
                             (swap! ref-pages set/union (set block-ref-pages)))
                           (-> block
                               (dissoc :ref-pages)
-                              (assoc :block/file [:file/path file]
+                              (assoc :block/file {:file/path file}
                                      :block/format format
                                      :block/page [:block/name (string/lower-case page)]
                                      :block/refs block-ref-pages
@@ -84,7 +84,7 @@
                           (util/remove-nils
                            (assoc
                             (block/page-name->map page false)
-                            :block/file [:file/path file]))
+                            :block/file {:file/path file}))
                           (seq properties)
                           (assoc :block/properties properties)
 

+ 3 - 2
src/main/frontend/modules/file/core.cljs

@@ -123,13 +123,14 @@
           dir (config/get-repo-dir repo)]
       (let [file-path (config/get-file-path repo path)
             page-blocks (db/get-page-blocks-no-cache (:block/name page))
+            file {:file/path file-path}
             tx (->>
                 (concat
                  [{:file/path file-path}
                   {:block/name (:block/name page)
-                   :block/file [:file/path file-path]}]
+                   :block/file file}]
                  (map (fn [block] {:db/id (:db/id block)
-                                   :block/file [:file/path file-path]})
+                                  :block/file file})
                    page-blocks))
                 (remove nil?))]
         (db/transact! tx)