Browse Source

fix: blocks disappear in long page when outdent

Tienson Qin 3 years ago
parent
commit
0d29421117

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

@@ -266,7 +266,7 @@
         href (config/get-local-asset-absolute-path href)]
     (when (or granted? (util/electron?) (mobile-util/is-native-platform?))
       (p/then (editor-handler/make-asset-url href) #(reset! src %)))
-    
+
     (when @src
       (let [ext (keyword (util/get-file-ext @src))
             share-fn (fn [event]
@@ -2438,7 +2438,7 @@
        (fn []
          (block-container-inner state repo config block))
        nil
-       false)
+       {:reset-height? false})
       (block-container-inner state repo config block))))
 
 (defn divide-lists
@@ -2768,7 +2768,7 @@
    (ui/lazy-visible
     (fn [] (custom-query* config q))
     nil
-    true)))
+    {:reset-height? true})))
 
 (defn admonition
   [config type result]

+ 2 - 1
src/main/frontend/components/journal.cljs

@@ -66,7 +66,8 @@
 
 (rum/defc journal-cp
   [journal]
-  (ui/lazy-visible (fn [] (journal-cp-inner journal)) nil true))
+  (ui/lazy-visible (fn [] (journal-cp-inner journal)) nil
+                   {:reset-height? true}))
 
 (rum/defc journals < rum/reactive
   [latest-journals]

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

@@ -590,7 +590,11 @@
   (let [db-before (or db-before current-db)
         cached-ids (map :db/id @result)
         cached-ids-set (set (conj cached-ids page-id))
-        first-changed-id (if (= outliner-op :move-blocks)
+        first-changed-id (cond
+                           (= (:real-outliner-op tx-meta) :indent-outdent)
+                           (last (:move-blocks tx-meta))
+
+                           (= outliner-op :move-blocks)
                            (let [{:keys [move-blocks target from-page to-page]} tx-meta]
                              (cond
                                (= page-id target) ; move to the first block
@@ -611,6 +615,7 @@
                                        (when (seq others)
                                          (recur others)))
                                      nil)))))
+                           :else
                            (let [insert? (= :insert-blocks outliner-op)]
                              (some #(when (and (or (and insert? (not (contains? cached-ids-set %)))
                                                    true)
@@ -635,11 +640,11 @@
         (let [start-page? (:block/name (db-utils/entity start-id))]
           (when-not start-page?
             (let [previous-blocks (take-while (fn [b] (not= start-id (:db/id b))) @result)
-                  previous-count (count previous-blocks)
                   limit 25
                   more (get-paginated-blocks-no-cache current-db start-id {:limit limit
                                                                            :include-start? true
                                                                            :scoped-block-id scoped-block-id})]
+              (util/pprint (last more))
               (concat previous-blocks more)))))
 
       :else

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

@@ -1708,7 +1708,8 @@
   (let [blocks (get-selected-ordered-blocks)]
     (when (seq blocks)
       (outliner-tx/transact!
-        {:outliner-op :move-blocks}
+        {:outliner-op :move-blocks
+         :real-outliner-op :indent-outdent}
         (outliner-core/indent-outdent-blocks! blocks (= direction :right))))))
 
 (defn- get-link [format link label]
@@ -2033,7 +2034,8 @@
   (when-not (parent-is-page? node)
     (let [parent-node (tree/-get-parent node)]
       (outliner-tx/transact!
-        {:outliner-op :move-blocks}
+        {:outliner-op :move-blocks
+         :real-outliner-op :indent-outdent}
         (save-current-block!)
         (outliner-core/move-blocks! [(:data node)] (:data parent-node) true)))))
 
@@ -2590,7 +2592,8 @@
     (when block
       (state/set-editor-last-pos! pos)
       (outliner-tx/transact!
-        {:outliner-op :move-blocks}
+        {:outliner-op :move-blocks
+         :real-outliner-op :indent-outdent}
         (save-current-block!)
         (outliner-core/indent-outdent-blocks! [block] indent?)))
     (state/set-editor-op! :nil)))

+ 21 - 16
src/main/frontend/ui.cljs

@@ -913,7 +913,7 @@
   {:init (fn [state]
            (assoc state
                   ::ref (atom nil)
-                  ::height (atom 26)))
+                  ::height (atom 24)))
    :did-mount (fn [state]
                 (when (last (:rum/args state))
                   (let [observer (js/ResizeObserver. (fn [entries]
@@ -928,7 +928,6 @@
   [state visible? content-fn _reset-height?]
   [:div.lazy-visibility {:ref #(reset! (::ref state) %)
                          :style {:min-height @(::height state)}}
-
    (if visible?
      (when (fn? content-fn) (content-fn))
      [:div.shadow.rounded-md.p-4.w-full.mx-auto {:style {:height 64}}
@@ -943,17 +942,23 @@
 
 (rum/defcs lazy-visible <
   (rum/local false ::visible?)
-  [state content-fn sensor-opts reset-height?]
-  (if (or (util/mobile?) (mobile-util/is-native-platform?))
-    (content-fn)
-    (let [*visible? (::visible? state)]
-      (visibility-sensor
-       (merge
-        {:on-change #(reset! *visible? %)
-         :partialVisibility true
-         :offset {:top -300
-                  :bottom -300}
-         :scrollCheck true
-         :scrollThrottle 1}
-        sensor-opts)
-       (lazy-visible-inner @*visible? content-fn reset-height?)))))
+  (rum/local true ::active?)
+  [state content-fn sensor-opts {:keys [reset-height? once?]}]
+  (let [*active? (::active? state)]
+    (if (or (util/mobile?) (mobile-util/is-native-platform?))
+      (content-fn)
+      (let [*visible? (::visible? state)]
+        (visibility-sensor
+         (merge
+          {:on-change (fn [v]
+                        (reset! *visible? v)
+                        (when (and once? v)
+                          (reset! *active? false)))
+           :partialVisibility true
+           :offset {:top -300
+                    :bottom -300}
+           :scrollCheck true
+           :scrollThrottle 500
+           :active @*active?}
+          sensor-opts)
+         (lazy-visible-inner @*visible? content-fn reset-height?))))))