Browse Source

enhance: display parent page when referencing a page

Tienson Qin 5 months ago
parent
commit
68640cb4e5
2 changed files with 14 additions and 4 deletions
  1. 10 3
      src/main/frontend/components/block.cljs
  2. 4 1
      src/main/frontend/util.cljc

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

@@ -663,8 +663,9 @@
    All page-names are sanitized except page-name-in-block"
   [state
    {:keys [contents-page? whiteboard-page? other-position? show-unique-title? stop-click-event?
-           on-context-menu]
-    :or {stop-click-event? true}
+           on-context-menu with-parent?]
+    :or {stop-click-event? true
+         with-parent? true}
     :as config}
    page-entity children label]
   (let [*hover? (::hover? state)
@@ -732,6 +733,11 @@
                                                                        :own-icon? true})]
            [:span {:class (str "icon-emoji-wrap " (when emoji? "as-emoji"))}
             icon])))
+
+     (when (and (ldb/page? page-entity) with-parent?)
+       (when-let [parent (:block/parent page-entity)]
+         [:span.select-none (str (:block/title parent) "/")]))
+
      [:span
       (if (and (coll? children) (seq children))
         (for [child children]
@@ -3239,7 +3245,8 @@
       (let [parents-props (doall
                            (for [{:block/keys [uuid name title] :as block} parents]
                              (if name
-                               [block (page-cp {:disable-preview? true} block) true]
+                               [block (page-cp {:disable-preview? true
+                                                :with-parent? false} block) true]
                                (let [result (block/parse-title-and-body
                                              uuid
                                              (get block :block/format :markdown)

+ 4 - 1
src/main/frontend/util.cljc

@@ -354,6 +354,9 @@
                           (gobj/get range "endContainer")
                           (gobj/get range "endOffset"))
                  (let [contents (.cloneContents pre-caret-range)
+                       ;; Remove all `.select-none` nodes
+                       _  (doseq [el (.querySelectorAll contents ".select-none")]
+                            (.remove el))
                        html (some-> (first (.-childNodes contents))
                                     (gobj/get "innerHTML")
                                     str)
@@ -365,7 +368,7 @@
                                        (string/ends-with? html "<div class=\"is-paragraph\"></div></div></span></div></div></div>")
                                        ;; multiple lines with a new line
                                        (string/ends-with? html "<br></div></div></span></div></div></div>")))
-                       value (.toString pre-caret-range)]
+                       value (.-textContent contents)]
                    (if br-ended?
                      (str value "\n")
                      value)))))