Browse Source

fix: keep editing after tagging a page

Tienson Qin 2 years ago
parent
commit
beee1df4a8

+ 20 - 13
src/main/frontend/handler/block.cljs

@@ -11,7 +11,6 @@
    [frontend.state :as state]
    [frontend.util :as util]
    [goog.dom :as gdom]
-   [goog.object :as gobj]
    [logseq.graph-parser.block :as gp-block]
    [frontend.config :as config]
    [frontend.db.listener :as db-listener]
@@ -327,16 +326,18 @@
     (db-listener/clear-repo-persistent-job! repo)))
 
 (defn- edit-block-aux
-  [repo block content block-node text-range {:keys [direction retry-times]
-                                             :or {retry-times 0}
+  [repo block content block-node text-range {:keys [direction retry-times max-retry-times]
+                                             :or {retry-times 0
+                                                  max-retry-times 3}
                                              :as opts}]
-  (when (and (<= retry-times 3) block)
+  (when (and (<= retry-times max-retry-times) block)
     (let [block-node block-node
           block-id (:block/uuid block)
           id-class (str "id" block-id)
-          next-edit-node (if block-node
+          next-edit-node (cond
+                           (and block-node (< retry-times max-retry-times))
                            (or
-                            ;; up/down
+                              ;; up/down
                             (when direction
                               (let [blocks (dom/by-class "ls-block")
                                     idx (.indexOf blocks block-node)]
@@ -345,21 +346,27 @@
                                     (util/nth-safe blocks (inc idx))
                                     (util/nth-safe blocks (dec idx))))))
 
-                            ;; next | next then first child
-                            (when-let [next (.-nextSibling block-node)]
-                              (when (dom/has-class? next id-class)
-                                next))
-
-                            ;; first child
+                              ;; next
+                            (let [id (some-> (dom/attr block-node "blockid") uuid)
+                                  link (when id (:link (db/entity [:block/uuid id])))
+                                  block-node (if link
+                                               (.-previousSibling block-node)
+                                               block-node)]
+                              (when-let [next (.-nextSibling block-node)]
+                                (when (dom/has-class? next id-class)
+                                  next)))
+
+                              ;; first child
                             (when-let [first-child (first (dom/sel block-node ".ls-block"))]
                               (when (dom/has-class? first-child id-class)
                                 first-child))
 
-                            ;; prev
+                              ;; prev
                             (when-let [prev (.-previousSibling block-node)]
                               (when (dom/has-class? prev id-class)
                                 prev)))
 
+                           :else
                            ;; take the first dom node
                            (gdom/getElement (str "ls-block-" (:block/uuid block))))]
       (if next-edit-node

+ 17 - 13
src/main/frontend/handler/editor.cljs

@@ -708,24 +708,28 @@
        (outliner-core/delete-blocks! [block] {:children? children?})))))
 
 (defn- move-to-prev-block
-  [repo sibling-block format id value]
+  [repo sibling-block format _id value]
   (when (and repo sibling-block)
     (when-let [sibling-block-id (dom/attr sibling-block "blockid")]
       (when-let [block (db/entity [:block/uuid (uuid sibling-block-id)])]
         (if (:block/name block)
-          {:prev-block block}
-          (let [original-block (dom/attr sibling-block "originalblockid")
-                edit-block (some-> (:db/id (state/get-edit-block)) db/entity)
+          (do
+            (edit-block! block :max (state/get-edit-block-node) {})
+            {:prev-block block
+            :new-value (:block/original-name block)})
+          (let [edit-block (some-> (:db/id (state/get-edit-block)) db/entity)
                 edit-block-has-refs? (some? (:block/_refs edit-block))
-                original-content (util/trim-safe
-                                  (if (:block/name block)
-                                    (:block/original-name block)
-                                    (:block/content block)))
-                value' (-> (file-property/remove-built-in-properties-when-file-based repo format original-content)
-                           (drawer/remove-logbook))
-                value (->> value
-                           (file-property/remove-properties-when-file-based repo format)
-                           (drawer/remove-logbook))
+                db? (config/db-based-graph? repo)
+                original-content (util/trim-safe (:block/content block))
+                value' (if db?
+                         original-content
+                         (-> (file-property/remove-built-in-properties-when-file-based repo format original-content)
+                             (drawer/remove-logbook)))
+                value (if db?
+                        value
+                        (->> value
+                             (file-property/remove-properties-when-file-based repo format)
+                             (drawer/remove-logbook)))
                 new-value (str value' value)
                 tail-len (count value)
                 pos (max

+ 5 - 4
src/main/frontend/modules/outliner/tree.cljs

@@ -131,7 +131,8 @@
 
 (defn get-sorted-block-and-children
   [repo db-id]
-  (when-let [root-block (db/pull db-id)]
-    (let [blocks (db/get-block-and-children repo (:block/uuid root-block))
-          blocks-exclude-root (remove (fn [b] (= (:db/id b) db-id)) blocks)]
-      (sort-blocks blocks-exclude-root root-block))))
+  (when db-id
+    (when-let [root-block (db/pull db-id)]
+      (let [blocks (db/get-block-and-children repo (:block/uuid root-block))
+            blocks-exclude-root (remove (fn [b] (= (:db/id b) db-id)) blocks)]
+        (sort-blocks blocks-exclude-root root-block)))))