Просмотр исходного кода

fix slash command clashes with Org-mode italics (#3010)

* enhance: fix https://github.com/logseq/logseq/issues/990

Co-authored-by: leizhe <[email protected]>
llcc 4 лет назад
Родитель
Сommit
b2e3901631

+ 5 - 9
src/main/frontend/components/block.cljs

@@ -389,8 +389,7 @@
                  {:page page-entity})))
             (do
               (create-first-block!)
-              (route-handler/redirect! {:to :page
-                                        :path-params {:name redirect-page-name}}))))
+              (route-handler/redirect-to-page! redirect-page-name))))
         (when (and contents-page?
                    (util/mobile?)
                    (state/get-left-sidebar-open?))
@@ -673,8 +672,7 @@
                       [:annotation true] (pdf-assets/open-block-ref! block)
 
                       ;; default open block page
-                      :else (route-handler/redirect! {:to          :page
-                                                      :path-params {:name id}}))))))}
+                      :else (route-handler/redirect-to-page! id))))))}
 
            (if (and (not (util/mobile?)) (not (:preview? config)) (nil? block-type))
              (ui/tippy {:html        (fn []
@@ -1317,8 +1315,7 @@
        :block
        block)
       (util/stop e))
-    (route-handler/redirect! {:to :page
-                              :path-params {:name (str uuid)}})))
+    (route-handler/redirect-to-page! uuid)))
 
 (rum/defc block-children < rum/reactive
   [config children collapsed? *ref-collapsed?]
@@ -1870,7 +1867,7 @@
            {:on-mouse-down (fn [e]
                              (util/stop e)
                              (when-let [block (:embed-parent config)]
-                               (editor-handler/edit-block! block :max (:block/format block) (:block/uuid block))))}
+                               (editor-handler/edit-block! block :max (:block/uuid block))))}
            svg/edit])
 
         (when (and (state/enable-timetracking?)
@@ -1921,8 +1918,7 @@
                 (:db/id block)
                 :block-ref
                 {:block block}))
-             (route-handler/redirect! {:to :page
-                                       :path-params {:name (str (:block/uuid block))}})))}
+             (route-handler/redirect-to-page! (:block/uuid block))))}
      label]))
 
 (rum/defc breadcrumb-separator [] [:span.mx-2.opacity-50 "➤"])

+ 1 - 1
src/main/frontend/components/editor.cljs

@@ -527,7 +527,7 @@
      (state/sub :editor/show-input)
      (animated-modal "input" (input id
                                     (fn [command m pos]
-                                      (editor-handler/handle-command-input command id format m pos)))
+                                      (editor-handler/handle-command-input command id format m)))
                      true (util/react *slash-caret-pos))
 
      (state/sub :editor/show-zotero)

+ 2 - 2
src/main/frontend/components/page.cljs

@@ -62,7 +62,7 @@
         (when (and (= (count blocks) 1)
                    (string/blank? (:block/content block))
                    (not preview?))
-          (editor-handler/edit-block! block :max (:block/format block) (:block/uuid block))))))
+          (editor-handler/edit-block! block :max (:block/uuid block))))))
   state)
 
 (rum/defc page-blocks-inner <
@@ -96,7 +96,7 @@
       [:span.bullet]]]
     [:div.flex.flex-1 {:on-click (fn []
                                    (let [block (editor-handler/insert-first-page-block-if-not-exists! page-name)]
-                                     (js/setTimeout #(editor-handler/edit-block! block :max nil (:block/uuid block)) 100)))}
+                                     (js/setTimeout #(editor-handler/edit-block! block :max (:block/uuid block)) 100)))}
      [:span.opacity-50
       "Click here to edit..."]]]])
 

+ 4 - 9
src/main/frontend/components/search.cljs

@@ -184,8 +184,7 @@
 
                         :page
                         (let [data (or alias data)]
-                          (route/redirect! {:to :page
-                                            :path-params {:name data}}))
+                          (route/redirect-to-page! data))
 
                         :file
                         (route/redirect! {:to :file
@@ -195,12 +194,9 @@
                         (let [block-uuid (uuid (:block/uuid data))
                               collapsed? (db/parents-collapsed? (state/get-current-repo) block-uuid)]
                           (if collapsed?
-                            (route/redirect! {:to :page
-                                              :path-params {:name (str block-uuid)}})
+                            (route/redirect-to-page! block-uuid)
                             (let [page (:block/name (:block/page (db/entity [:block/uuid block-uuid])))]
-                              (route/redirect! {:to :page
-                                                :path-params {:name page}
-                                                :query-params {:anchor (str "ls-block-" (:block/uuid data))}}))))
+                              (route/redirect-to-page! page  (str "ls-block-" (:block/uuid data))))))
                         nil)
                       (state/close-modal!))
          :on-shift-chosen (fn [{:keys [type data alias]}]
@@ -308,8 +304,7 @@
       {:on-chosen (fn [{:keys [type data]}]
                     (case type
                       :page
-                      (route/redirect! {:to :page
-                                        :path-params {:name data}})
+                      (route/redirect-to-page! data)
                       :search
                       (let [q data]
                         (state/set-q! q)

+ 2 - 4
src/main/frontend/components/sidebar.cljs

@@ -93,8 +93,7 @@
                             (:db/id page-entity)
                             :page
                             {:page page-entity}))
-                         (route-handler/redirect! {:to :page
-                                                   :path-params {:name name}}))))}
+                         (route-handler/redirect-to-page! name))))}
      (pdf-assets/fix-local-asset-filename original-name)]))
 
 (rum/defcs favorite-item <
@@ -350,8 +349,7 @@
               (= :home (state/get-current-route))
               (not (state/route-has-p?))
               (:page default-home))
-         (route-handler/redirect! {:to :page
-                                   :path-params {:name (:page default-home)}})
+         (route-handler/redirect-to-page! (:page default-home))
 
          (and config/publishing?
               (not default-home)

+ 1 - 1
src/main/frontend/extensions/code.cljs

@@ -140,7 +140,7 @@
                                                                  (let [block (db/pull [:block/uuid block-id])
                                                                        value (.getValue cm)
                                                                        textarea-value (gobj/get textarea "value")]
-                                                                   (editor-handler/edit-block! block :max (:block/format block) block-id)))
+                                                                   (editor-handler/edit-block! block :max block-id)))
                                                                ;; TODO: return "handled" or false doesn't always prevent event bubbles
                                                                (reset! esc-pressed? true)
                                                                (js/setTimeout #(reset! esc-pressed? false) 10))}}))]

+ 1 - 2
src/main/frontend/extensions/graph.cljs

@@ -53,8 +53,7 @@
     (when-not drag?
       (let [page-name (string/lower-case node)]
         (.unhoverNode ^js graph node)
-        (route-handler/redirect! {:to :page
-                                  :path-params {:name page-name}})))))
+        (route-handler/redirect-to-page! page-name)))))
 
 (defn reset-graph!
   [^js graph]

+ 135 - 154
src/main/frontend/handler/editor.cljs

@@ -62,7 +62,7 @@
 (defn- get-selection-and-format
   []
   (when-let [block (state/get-edit-block)]
-    (when-let [id (:block/uuid block)]
+    (when (:block/uuid block)
       (when-let [edit-id (state/get-edit-input-id)]
         (when-let [input (gdom/getElement edit-id)]
           {:selection-start (gobj/get input "selectionStart")
@@ -76,7 +76,7 @@
 (defn- format-text!
   [pattern-fn]
   (when-let [m (get-selection-and-format)]
-    (let [{:keys [selection-start selection-end format value block edit-id input]} m
+    (let [{:keys [selection-start selection-end format value edit-id input]} m
           empty-selection? (= selection-start selection-end)
           pattern (pattern-fn format)
           pattern-count (count pattern)
@@ -104,7 +104,7 @@
 (defn italics-format! []
   (format-text! config/get-italic))
 
-(defn highlight-format! [state]
+(defn highlight-format! []
   (when-let [block (state/get-edit-block)]
     (let [format (:block/format block)]
       (format-text! #(config/get-highlight format)))))
@@ -114,7 +114,7 @@
 
 (defn html-link-format! []
   (when-let [m (get-selection-and-format)]
-    (let [{:keys [selection-start selection-end format value block edit-id input]} m
+    (let [{:keys [selection-start selection-end format value edit-id input]} m
           cur-pos (cursor/pos input)
           empty-selection? (= selection-start selection-end)
           selection (subs value selection-start selection-end)
@@ -207,9 +207,9 @@
 
 ;; id: block dom id, "ls-block-counter-uuid"
 (defn edit-block!
-  ([block pos format id]
-   (edit-block! block pos format id nil))
-  ([block pos format id {:keys [custom-content tail-len move-cursor?]
+  ([block pos id]
+   (edit-block! block pos id nil))
+  ([block pos id {:keys [custom-content tail-len move-cursor?]
                          :or {tail-len 0
                               move-cursor? true}}]
    (when-not config/publishing?
@@ -245,7 +245,6 @@
     (edit-block!
      last-block
      pos
-     (:block/format last-block)
      (string/replace (gobj/get first-block "id")
                      "ls-block"
                      "edit-block"))))
@@ -495,48 +494,47 @@
 ;; FIXME: painful
 (defn update-cache-for-block-insert!
   "Currently, this only affects current editor container to improve the performance."
-  [repo config {:block/keys [page uuid] :as block} blocks]
+  [repo config {:block/keys [page uuid] :as _block} blocks]
   (let [blocks (map :data blocks)
         [first-block last-block right-block] blocks
         child? (= (first (:block/parent last-block))
                   (:block/uuid first-block))
         blocks-container-id (when-let [id (:id config)]
-                              (and (util/uuid-string? id) (medley/uuid id)))]
-    (let [new-last-block (let [first-block-uuid (:block/uuid (db/entity (:db/id first-block)))
-                               first-block-id {:db/id (:db/id first-block)}]
+                              (and (util/uuid-string? id) (medley/uuid id)))
+        new-last-block (let [first-block-id {:db/id (:db/id first-block)}]
                            (assoc last-block
                                   :block/left first-block-id
                                   :block/parent (if child?
                                                   first-block-id
                                                   ;; sibling
                                                   (:block/parent first-block))))
-          blocks [first-block new-last-block]
-          blocks-atom (if blocks-container-id
-                        (db/get-block-blocks-cache-atom repo blocks-container-id)
-                        (db/get-page-blocks-cache-atom repo (:db/id page)))
-          [before-part after-part] (and blocks-atom
-                                        (split-with
-                                         #(not= uuid (:block/uuid %))
-                                         @blocks-atom))
-          after-part (rest after-part)
-          blocks (concat before-part blocks after-part)
-          blocks (if right-block
-                   (map (fn [block]
-                          (if (= (:block/uuid right-block) (:block/uuid block))
-                            (assoc block :block/left (:block/left right-block))
-                            block)) blocks)
-                   blocks)]
-      (when blocks-atom
-        (reset! blocks-atom blocks)))))
+        blocks [first-block new-last-block]
+        blocks-atom (if blocks-container-id
+                      (db/get-block-blocks-cache-atom repo blocks-container-id)
+                      (db/get-page-blocks-cache-atom repo (:db/id page)))
+        [before-part after-part] (and blocks-atom
+                                      (split-with
+                                       #(not= uuid (:block/uuid %))
+                                       @blocks-atom))
+        after-part (rest after-part)
+        blocks (concat before-part blocks after-part)
+        blocks (if right-block
+                 (map (fn [block]
+                        (if (= (:block/uuid right-block) (:block/uuid block))
+                          (assoc block :block/left (:block/left right-block))
+                          block)) blocks)
+                 blocks)]
+    (when blocks-atom
+      (reset! blocks-atom blocks))))
 
 (defn insert-new-block-before-block-aux!
   [config
-   {:block/keys [uuid content repo format page]
+   {:block/keys [repo]
     db-id :db/id
     :as block}
    value
    {:keys [ok-handler]
-    :as opts}]
+    :as _opts}]
   (let [input (gdom/getElement (state/get-edit-input-id))
         pos (cursor/pos input)
         repo (or repo (state/get-current-repo))
@@ -561,12 +559,12 @@
 
 (defn insert-new-block-aux!
   [config
-   {:block/keys [uuid content repo format page]
+   {:block/keys [uuid repo]
     db-id :db/id
     :as block}
    value
    {:keys [ok-handler]
-    :as opts}]
+    :as _opts}]
   (let [block-self? (block-self-alone-when-insert? config uuid)
         input (gdom/getElement (state/get-edit-input-id))
         pos (cursor/pos input)
@@ -590,8 +588,7 @@
                      (let [opts {:key :block/insert
                                  :data [current-block next-block]}]
                        (db/refresh! repo opts)))]
-    (do
-      (if (or (:ref? config)
+    (if (or (:ref? config)
               (not sibling?)
               zooming?)
         (refresh-fn)
@@ -601,7 +598,7 @@
       ;; WORKAROUND: The block won't refresh itself even if the content is empty.
       (when block-self?
         (gobj/set input "value" ""))
-      (profile "ok handler" (ok-handler next-block)))))
+      (profile "ok handler" (ok-handler next-block))))
 
 (defn clear-when-saved!
   []
@@ -640,16 +637,14 @@
               (not= :insert (state/get-editor-op)))
      (state/set-editor-op! :insert)
      (when-let [state (get-state)]
-       (let [{:keys [block value format id config]} state
+       (let [{:keys [block value id config]} state
              value (if (string? block-value) block-value value)
              block-id (:block/uuid block)
              block (or (db/pull [:block/uuid block-id])
                        block)
-             repo (or (:block/repo block) (state/get-current-repo))
              block-self? (block-self-alone-when-insert? config block-id)
              input (gdom/getElement (state/get-edit-input-id))
              pos (cursor/pos input)
-             repo (or repo (state/get-current-repo))
              [fst-block-text snd-block-text] (compute-fst-snd-block-text value pos)
              insert-fn (match (mapv boolean [block-self? (seq fst-block-text) (seq snd-block-text)])
                          [true _ _] insert-new-block-aux!
@@ -658,7 +653,7 @@
          (insert-fn config block value
                     {:ok-handler
                      (fn [last-block]
-                       (edit-block! last-block 0 format id)
+                       (edit-block! last-block 0 id)
                        (clear-when-saved!))}))))
    (state/set-editor-op! nil)))
 
@@ -674,8 +669,7 @@
                   (db/entity [:block/name (string/lower-case page)])
                   (db/entity [:block/uuid block-uuid]))]
       (when block
-        (let [repo (state/get-current-repo)
-              last-block (when (not sibling?)
+        (let [last-block (when (not sibling?)
                            (let [children (:block/_parent block)
                                  blocks (db/sort-by-left children block)
                                  last-block-id (:db/id (last blocks))]
@@ -698,8 +692,8 @@
                                  (:db/id (:block/page new-block))))
               new-block (-> new-block
                             (wrap-parse-block)
-                            (assoc :block/uuid (or custom-uuid (db/new-block-id))))]
-          (let [[block-m sibling?] (cond
+                            (assoc :block/uuid (or custom-uuid (db/new-block-id))))
+              [block-m sibling?] (cond
                                      before?
                                      (let [block (db/pull (:db/id (:block/left block)))
                                            sibling? (if (:block/name block) false sibling?)]
@@ -717,10 +711,11 @@
                                      ;; FIXME: assert
                                      :else
                                      nil)]
-            (when block-m
-              (outliner-insert-block! {:skip-save-current-block? true} block-m new-block sibling?)
-              (when re-render-root? (ui-handler/re-render-root!))
-              new-block)))))))
+
+          (when block-m
+            (outliner-insert-block! {:skip-save-current-block? true} block-m new-block sibling?)
+            (when re-render-root? (ui-handler/re-render-root!))
+            new-block))))))
 
 (defn insert-first-page-block-if-not-exists!
   [page-name]
@@ -816,7 +811,7 @@
     content))
 
 (defn check
-  [{:block/keys [uuid marker content format repeated?] :as block}]
+  [{:block/keys [marker content repeated?] :as block}]
   (let [new-content (string/replace-first content marker "DONE")
         new-content (if repeated?
                       (update-timestamps-content! block content)
@@ -824,7 +819,7 @@
     (save-block-if-changed! block new-content)))
 
 (defn uncheck
-  [{:block/keys [uuid marker content format] :as block}]
+  [{:block/keys [content] :as block}]
   (let [marker (if (= :now (state/get-preferred-workflow))
                  "LATER"
                  "TODO")
@@ -833,18 +828,18 @@
 
 (defn cycle-todo!
   []
-  (when-let [block (state/get-edit-block)]
+  (when (state/get-edit-block)
     (let [edit-input-id (state/get-edit-input-id)
           current-input (gdom/getElement edit-input-id)
           content (state/get-edit-content)
           format (or (db/get-page-format (state/get-current-page))
                      (state/get-preferred-format))
           [new-content marker] (marker/cycle-marker content format (state/get-preferred-workflow))
-          new-content (string/triml new-content)]
-      (let [new-pos (commands/compute-pos-delta-when-change-marker
-                     content marker (cursor/pos current-input))]
-        (state/set-edit-content! edit-input-id new-content)
-        (cursor/move-cursor-to current-input new-pos)))))
+          new-content (string/triml new-content)
+          new-pos (commands/compute-pos-delta-when-change-marker
+                   content marker (cursor/pos current-input))]
+      (state/set-edit-content! edit-input-id new-content)
+      (cursor/move-cursor-to current-input new-pos))))
 
 (defn set-marker
   [{:block/keys [marker content] :as block} new-marker]
@@ -867,8 +862,7 @@
 (defn cycle-todos!
   []
   (when-let [blocks (seq (get-selected-blocks-with-children))]
-    (let [repo (state/get-current-repo)
-          workflow (state/get-preferred-workflow)
+    (let [workflow (state/get-preferred-workflow)
           ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
                                      (uuid id)) blocks))
                    (remove nil?))]
@@ -879,14 +873,14 @@
           (set-marker block new-marker))))))
 
 (defn set-priority
-  [{:block/keys [uuid marker priority content] :as block} new-priority]
+  [{:block/keys [priority content] :as block} new-priority]
   (let [new-content (string/replace-first content
                                           (util/format "[#%s]" priority)
                                           (util/format "[#%s]" new-priority))]
     (save-block-if-changed! block new-content)))
 
 (defn delete-block-aux!
-  [{:block/keys [uuid content repo refs] :as block} children?]
+  [{:block/keys [uuid repo] :as _block} children?]
   (let [repo (or repo (state/get-current-repo))
         block (db/pull repo '[*] [:block/uuid uuid])]
     (when block
@@ -910,15 +904,15 @@
                      (utf8/length (utf8/encode original-content))
                      0)
                    0)]
-          (edit-block! block pos format id
+          (edit-block! block pos id
                        {:custom-content new-value
                         :tail-len tail-len
                         :move-cursor? false}))))))
 
 (defn delete-block!
-  ([repo e]
-   (delete-block! repo e true))
-  ([repo e delete-children?]
+  ([repo]
+   (delete-block! repo true))
+  ([repo delete-children?]
    (state/set-editor-op! :delete)
    (let [{:keys [id block-id block-parent-id value format]} (get-state)]
      (when block-id
@@ -958,7 +952,7 @@
   [blocks]
   (if (<= (count blocks) 1)
     blocks
-    (let [[f s & others] blocks]
+    (let [[f s & _others] blocks]
       (if (or
            (= (:block/left s) {:db/id (:db/id f)})
            (let [parents (db/get-block-parents (state/get-current-repo)
@@ -1026,7 +1020,6 @@
             (when (= (:block/uuid editing-block) block-id)
               (edit-block! editing-block
                            input-pos
-                           format
                            (state/get-edit-input-id)))))))))
 
 (defn remove-block-property!
@@ -1062,7 +1055,7 @@
         key (string/lower-case (str key))
         value (str value)]
     (when-let [block (db/pull [:block/uuid block-id])]
-      (let [{:block/keys [content scheduled deadline format]} block
+      (let [{:block/keys [content]} block
             content (or (state/get-edit-content) content)
             new-content (-> (text/remove-timestamp content key)
                             (text/add-timestamp key value))]
@@ -1078,7 +1071,8 @@
       (set-block-property! block-id "id" (str block-id)))))
 
 (defn copy-block-ref!
-  ([block-id] (copy-block-ref! block-id #(str %)))
+  ([block-id]
+   (copy-block-ref! block-id #(str %)))
   ([block-id tap-clipboard]
    (set-block-id! block-id)
    (util/copy-to-clipboard! (tap-clipboard block-id))))
@@ -1138,8 +1132,6 @@
                                  (vec (tree/sort-blocks (db/get-block-children repo (:block/uuid b)) b))
                                  [b])) blocks))
         block-ids* (mapv :block/uuid blocks*)
-        unordered? (:block/unordered (first blocks*))
-        format (:block/format (first blocks*))
         level-blocks-map (blocks-with-level blocks*)
         level-blocks-uuid-map (into {} (mapv (fn [b] [(:block/uuid b) b]) (vals level-blocks-map)))
         level-blocks (mapv (fn [uuid] (get level-blocks-uuid-map uuid)) block-ids*)
@@ -1167,8 +1159,7 @@
 (defn copy-block-refs
   []
   (when-let [blocks (seq (get-selected-blocks-with-children))]
-    (let [repo (state/get-current-repo)
-          ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
+    (let [ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
                                      (uuid id)) blocks))
                    (remove nil?))
           ids-str (some->> ids
@@ -1219,7 +1210,7 @@
 (defn- get-nearest-page
   []
   (when-let [block (state/get-edit-block)]
-    (when-let [id (:block/uuid block)]
+    (when (:block/uuid block)
       (when-let [edit-id (state/get-edit-input-id)]
         (when-let [input (gdom/getElement edit-id)]
           (when-let [pos (cursor/pos input)]
@@ -1254,8 +1245,7 @@
       (let [page-name (string/lower-case page)]
         (state/clear-edit!)
         (insert-first-page-block-if-not-exists! page-name)
-        (route-handler/redirect! {:to :page
-                                  :path-params {:name page-name}})))))
+        (route-handler/redirect-to-page! page-name)))))
 
 (defn open-link-in-sidebar!
   []
@@ -1283,10 +1273,10 @@
                           db/entity
                           :block/uuid)]
       (let [pos (state/get-edit-pos)]
-        (route-handler/redirect! {:to          :page
-                                  :path-params {:name (str id)}})
+        (route-handler/redirect-to-page! id)
         (edit-block! {:block/uuid id} pos nil id)))
     (js/window.history.forward)))
+
 (defn zoom-out!
   []
   (if (state/editing?)
@@ -1301,18 +1291,16 @@
                        (nil? (:block/name block-parent))
                        (:block/uuid block-parent))]
             (do
-              (route-handler/redirect! {:to :page
-                                        :path-params {:name (str id)}})
+              (route-handler/redirect-to-page! id)
 
-              (edit-block! {:block/uuid block-id} :max nil block-id))
+              (edit-block! {:block/uuid block-id} :max block-id))
             (let [page-id (some-> (db/entity [:block/uuid block-id])
                                   :block/page
                                   :db/id)]
 
               (when-let [page-name (:block/name (db/entity page-id))]
-                (route-handler/redirect! {:to :page
-                                          :path-params {:name page-name}})
-                (edit-block! {:block/uuid block-id} :max nil block-id)))))))
+                (route-handler/redirect-to-page! page-name)
+                (edit-block! {:block/uuid block-id} :max block-id)))))))
     (js/window.history.back)))
 
 (defn cut-block!
@@ -1352,7 +1340,7 @@
 
 (defn on-select-block
   [direction]
-  (fn [e]
+  (fn [_event]
     (cond
       ;; when editing, quit editing and select current block
       (state/editing?)
@@ -1378,7 +1366,7 @@
       (clear-last-selected-block!))))
 
 (defn save-block-aux!
-  [block value format opts]
+  [block value opts]
   (let [value (string/trim value)]
     ;; FIXME: somehow frontend.components.editor's will-unmount event will loop forever
     ;; maybe we shouldn't save the block/file in "will-unmount" event?
@@ -1394,9 +1382,9 @@
                  (db-model/query-block-by-uuid block-or-uuid) block-or-uuid)
          format (:block/format block)]
      (save-block! {:block block :repo repo :format format} content)))
-  ([{:keys [format block repo] :as state} value]
+  ([{:keys [block repo] :as _state} value]
    (when (:db/id (db/entity repo [:block/uuid (:block/uuid block)]))
-     (save-block-aux! block value format {}))))
+     (save-block-aux! block value {}))))
 
 (defn save-current-block!
   ([]
@@ -1404,7 +1392,7 @@
   ([{:keys [force?] :as opts}]
    ;; non English input method
    (when-not (state/editor-in-composition?)
-     (when-let [repo (state/get-current-repo)]
+     (when (state/get-current-repo)
        (when (and (not @commands/*show-commands)
                   (not @commands/*show-block-commands)
                   (not (state/get-editor-show-page-search?))
@@ -1425,13 +1413,12 @@
                  value (and elem (gobj/get elem "value"))]
              (cond
                force?
-               (save-block-aux! db-block value (:block/format db-block) opts)
+               (save-block-aux! db-block value opts)
 
                (and block value db-content-without-heading
-                    (or
-                     (not= (string/trim db-content-without-heading)
-                           (string/trim value))))
-               (save-block-aux! db-block value (:block/format db-block) opts)))
+                    (not= (string/trim db-content-without-heading)
+                          (string/trim value)))
+               (save-block-aux! db-block value opts)))
            (catch js/Error error
              (log/error :save-block-failed error))))))))
 
@@ -1508,24 +1495,23 @@
   ([repo dir path files gen-filename]
    (p/all
     (for [[index ^js file] (map-indexed vector files)]
-      (do
-        ;; WARN file name maybe fully qualified path when paste file
-        (let [file-name (util/node-path.basename (.-name file))
-              [file-base ext] (if file-name
-                                (let [last-dot-index (string/last-index-of file-name ".")]
-                                  [(subs file-name 0 last-dot-index)
-                                   (subs file-name last-dot-index)])
-                                ["" ""])
-              filename (str (gen-filename index file-base) ext)
+      ;; WARN file name maybe fully qualified path when paste file
+      (let [file-name (util/node-path.basename (.-name file))
+            [file-base ext] (if file-name
+                              (let [last-dot-index (string/last-index-of file-name ".")]
+                                [(subs file-name 0 last-dot-index)
+                                 (subs file-name last-dot-index)])
+                              ["" ""])
+            filename (str (gen-filename index file-base) ext)
               filename (str path "/" filename)]
                                         ;(js/console.debug "Write asset #" dir filename file)
-          (if (util/electron?)
-            (let [from (.-path file)
-                  from (if (string/blank? from) nil from)]
-              (p/then (js/window.apis.copyFileToAssets dir filename from)
-                      #(p/resolved [filename (if (string? %) (js/File. #js[] %) file) (.join util/node-path dir filename)])))
+        (if (util/electron?)
+          (let [from (.-path file)
+                from (if (string/blank? from) nil from)]
+            (p/then (js/window.apis.copyFileToAssets dir filename from)
+                    #(p/resolved [filename (if (string? %) (js/File. #js[] %) file) (.join util/node-path dir filename)])))
             (p/then (fs/write-file! repo dir filename (.stream file) nil)
-                    #(p/resolved [filename file])))))))))
+                    #(p/resolved [filename file]))))))))
 
 (defonce *assets-url-cache (atom {}))
 
@@ -1536,7 +1522,7 @@
     (cond
       (util/electron?)
       (str "assets://" repo-dir path)
-
+      
       (mobile/is-native-platform?)
       (mobile/convert-file-src
        (str "file://" repo-dir path))
@@ -1554,10 +1540,9 @@
                 url))))))))
 
 (defn delete-asset-of-block!
-  [{:keys [repo href title full-text block-id local? delete-local?] :as opts}]
+  [{:keys [repo href full-text block-id local? delete-local?] :as _opts}]
   (let [block (db-model/query-block-by-uuid block-id)
         _ (or block (throw (str block-id " not exists")))
-        format (:block/format block)
         text (:block/content block)
         content (string/replace text full-text "")]
     (save-block! repo block content)
@@ -1641,6 +1626,8 @@
    "_" "_"
    "^" "^"
    "=" "="
+   "/" "/"
+   "+" "+"
    ;; ":" ":"                              ; TODO: only properties editing and org mode tag
    })
 
@@ -1648,8 +1635,8 @@
   (zipmap (vals autopair-map)
           (keys autopair-map)))
 
-(defonce autopair-when-selected
-  #{"^" "_" "="})
+(def autopair-when-selected
+  #{"*" "^" "_" "=" "+" "/"})
 
 (def delete-map
   (assoc autopair-map
@@ -1663,7 +1650,7 @@
 (defn autopair
   [input-id prefix format {:keys [restore?]
                            :or {restore? true}
-                           :as option}]
+                           :as _option}]
   (let [value (get autopair-map prefix)
         selected (util/get-selected-text)
         postfix (str selected value)
@@ -1671,7 +1658,7 @@
         input (gdom/getElement input-id)]
     (when value
       (when-not (string/blank? selected) (reset! *selected-text selected))
-      (let [[prefix pos] (commands/simple-replace! input-id value selected
+      (let [[prefix _pos] (commands/simple-replace! input-id value selected
                                                    {:backward-pos (count postfix)
                                                     :check-fn (fn [new-value prefix-pos]
                                                                 (when (>= prefix-pos 0)
@@ -1717,12 +1704,12 @@
   (let [block (state/get-edit-block)
         editing-page (and block
                           (when-let [page-id (:db/id (:block/page block))]
-                            (:block/name (db/entity page-id))))]
-    (let [pages (search/page-search q 20)]
-      (if editing-page
-        ;; To prevent self references
-        (remove (fn [p] (= (string/lower-case p) editing-page)) pages)
-        pages))))
+                            (:block/name (db/entity page-id))))
+        pages (search/page-search q 20)]
+    (if editing-page
+      ;; To prevent self references
+      (remove (fn [p] (= (string/lower-case p) editing-page)) pages)
+      pages)))
 
 (defn get-matched-blocks
   [q block-id]
@@ -1776,7 +1763,7 @@
               (commands/get-matched-commands
                last-command
                (commands/block-commands-map))))))
-    (catch js/Error e
+    (catch js/Error _error
       nil)))
 
 (defn auto-complete?
@@ -1830,7 +1817,7 @@
 
 (defn move-up-down
   [up?]
-  (fn [e]
+  (fn [_event]
     (when-let [block-id (:block/uuid (state/get-edit-block))]
       (when-let [block (db/pull [:block/uuid block-id])]
         (outliner-core/move-node (outliner-core/block block) up?)
@@ -1896,7 +1883,7 @@
       :org (util/format "[[%s]]"))))
 
 (defn handle-command-input
-  [command id format m pos]
+  [command id format m]
   (case command
     :link
     (let [{:keys [link label]} m]
@@ -1942,7 +1929,7 @@
              (or (state/get-editor-show-page-search?)
                  (state/get-editor-show-page-search-hashtag?)
                  (state/get-editor-show-block-search?)))
-    (when-let [q (get-search-q)]
+    (when (get-search-q)
       (let [value (gobj/get input "value")
             pos (:editor/last-saved-cursor @state/state)
             current-pos (cursor/pos input)
@@ -1973,7 +1960,7 @@
         block (db/pull [:block/uuid block-id])
         value (:block/content block)
         new-value (string/replace value full_text new-full-text)]
-    (save-block-aux! block new-value (:block/format block) {})))
+    (save-block-aux! block new-value {})))
 
 (defn- mark-last-input-time!
   [repo]
@@ -2151,7 +2138,7 @@
   [tree exclude-properties {:keys [content-update-fn
                                    get-pos-fn
                                    page-block]
-                            :as opts}]
+                            :as _opts}]
   (let [repo (state/get-current-repo)
         page (or page-block
                  (:block/page (db/entity (:db/id (state/get-edit-block)))))
@@ -2280,7 +2267,7 @@
          (let [block (if (tree/satisfied-inode? last-block)
                        (:data last-block)
                        (:data (last (flatten last-block))))]
-           (edit-block! block :max (:block/format block) (:block/uuid block))))))))
+           (edit-block! block :max (:block/uuid block))))))))
 
 (defn template-on-chosen-handler
   [element-id]
@@ -2301,7 +2288,7 @@
     (db/refresh! repo {:key :block/change :data [(:data node)]})))
 
 (defn- last-top-level-child?
-  [{:keys [id config]} current-node]
+  [{:keys [id]} current-node]
   (when id
     (when-let [entity (if (util/uuid-string? (str id))
                         (db/entity [:block/uuid (uuid id)])
@@ -2494,7 +2481,6 @@
               block (db/pull repo '[*] [:block/uuid new-uuid])]
           (edit-block! block
                        [direction line-pos]
-                       format
                        new-id))))))
 
 (defn keydown-up-down-handler
@@ -2525,18 +2511,18 @@
         pos (if up? :max 0)
         {:block/keys [format uuid] :as block} (state/get-edit-block)
         id (state/get-edit-input-id)
-        repo (state/get-current-repo)]
-    (let [f (if up? util/get-prev-block-non-collapsed util/get-next-block-non-collapsed)
-          sibling-block (f (gdom/getElement (state/get-editing-block-dom-id)))]
-      (when sibling-block
-        (when-let [sibling-block-id (dom/attr sibling-block "blockid")]
-          (let [content (:block/content block)
-                value (state/get-edit-content)]
-            (when (not= (clean-content! format content)
-                        (string/trim value))
-              (save-block! repo uuid value)))
-          (let [block (db/pull repo '[*] [:block/uuid (cljs.core/uuid sibling-block-id)])]
-            (edit-block! block pos format id)))))))
+        repo (state/get-current-repo)
+        f (if up? util/get-prev-block-non-collapsed util/get-next-block-non-collapsed)
+        sibling-block (f (gdom/getElement (state/get-editing-block-dom-id)))]
+    (when sibling-block
+      (when-let [sibling-block-id (dom/attr sibling-block "blockid")]
+        (let [content (:block/content block)
+              value (state/get-edit-content)]
+          (when (not= (clean-content! format content)
+                      (string/trim value))
+            (save-block! repo uuid value)))
+        (let [block (db/pull repo '[*] [:block/uuid (cljs.core/uuid sibling-block-id)])]
+          (edit-block! block pos id))))))
 
 (defn keydown-arrow-handler
   [direction]
@@ -2641,7 +2627,7 @@
                      (= (medley/uuid page) block-id))))
       (do
         (util/stop e)
-        (delete-block! repo e false))
+        (delete-block! repo false))
 
       (and (> current-pos 1)
            (= (util/nth-safe value (dec current-pos)) commands/slash))
@@ -2731,7 +2717,7 @@
 
 (defn keydown-not-matched-handler
   [format]
-  (fn [e key-code]
+  (fn [e _key-code]
     (let [input-id (state/get-edit-input-id)
           input (state/get-input)
           key (gobj/get e "key")
@@ -2775,7 +2761,7 @@
               (commands/handle-step [:editor/search-block :reference])
               (reset! commands/*slash-caret-pos (cursor/get-caret-pos input)))
             :else
-            nil))
+            (reset! commands/*show-commands false)))
 
         (or
          (surround-by? input "#" " ")
@@ -2935,11 +2921,7 @@
 
 (defn- paste-text
   [text e]
-  (let [repo (state/get-current-repo)
-        page (or (db/entity [:block/name (state/get-current-page)])
-                 (db/entity [:block/original-name (state/get-current-page)])
-                 (:block/page (db/entity (:db/id (state/get-edit-block)))))
-        copied-blocks (state/get-copied-blocks)
+  (let [copied-blocks (state/get-copied-blocks)
         copied-block-tree (:copy/block-tree copied-blocks)]
     (if (and
          (:copy/content copied-blocks)
@@ -2990,7 +2972,7 @@
     (let [text (.getData (gobj/get e "clipboardData") "text")]
       (if-not (string/blank? text)
         (paste-text text e)
-        (let [handled
+        (let [_handled
               (let [clipboard-data (gobj/get e "clipboardData")
                     files (.-files clipboard-data)]
                 (when-let [file (first files)]
@@ -3004,7 +2986,7 @@
   (clear-selection!))
 
 (defn shortcut-copy-selection
-  [e]
+  [_e]
   (copy-selection-blocks))
 
 (defn shortcut-cut-selection
@@ -3110,7 +3092,6 @@
           left?    (= direction :left)]
       (edit-block! block
                    (if left? 0 :max)
-                   (:block/format block)
                    block-id))))
 
 (defn shortcut-left-right [direction]

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

@@ -50,7 +50,7 @@
              push-result (git/push repo token true)]
        (reset! pushing? false)
        (notification/clear! nil)
-       (route-handler/redirect! {:to :home}))
+       (route-handler/redirect-to-home!))
      (p/catch (fn [error]
                 (log/error :git/commit-and-force-push! error))))))
 

+ 0 - 1
src/main/frontend/handler/history.cljs

@@ -23,7 +23,6 @@
       (when-let [block-uuid (:block/uuid last-edit-block)]
         (when-let [block (db/pull [:block/uuid block-uuid])]
           (editor/edit-block! block pos
-                              (:block/format block)
                               (:block/uuid block)
                               {:custom-content (:block/content block)}))))))
 

+ 1 - 2
src/main/frontend/handler/page.cljs

@@ -118,8 +118,7 @@
            (outliner-file/sync-to-file page))
 
          (when redirect?
-           (route-handler/redirect! {:to          :page
-                                     :path-params {:name page}}))
+           (route-handler/redirect-to-page! page))
          page)))))
 
 (defn page-add-property!

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

@@ -656,7 +656,7 @@
         (rebuild-index! repo))
       (js/setTimeout
        (fn []
-         (route-handler/redirect! {:to :home}))
+         (route-handler/redirect-to-home!))
        500))))
 
 (defn git-commit-and-push!

+ 13 - 5
src/main/frontend/handler/route.cljs

@@ -25,9 +25,18 @@
   (redirect! {:to :home}))
 
 (defn redirect-to-page!
-  [page-name]
-  (redirect! {:to :page
-              :path-params {:name page-name}}))
+  ([page-name]
+   (redirect! {:to :page
+               :path-params {:name (str page-name)}}))
+  ([page-name anchor]
+   (redirect! {:to :page
+               :path-params {:name (str page-name)}
+               :query-params {:anchor anchor}}))
+  ([page-name anchor push]
+   (redirect! {:to :page
+               :path-params {:name (str page-name)}
+               :query-params {:anchor anchor}
+               :push push})))
 
 (defn get-title
   [name path-params]
@@ -148,7 +157,6 @@
       :file
       (when-let [path (get-in (state/get-route-match) [:path-params :path])]
         (when-let [page (db/get-file-page path)]
-          (redirect! {:to :page
-                      :path-params {:name page}})))
+          (redirect-to-page! page)))
 
       nil)))

+ 1 - 1
src/main/frontend/modules/shortcut/config.cljs

@@ -346,7 +346,7 @@
     :go/home
     {:desc    "Go to home"
      :binding "g h"
-     :fn      #(route-handler/redirect! {:to :home})}
+     :fn      #(route-handler/redirect-to-home!)}
     :go/keyboard-shortcuts
     {:desc    "Go to keyboard shortcuts"
      :binding "g s"

+ 6 - 4
src/main/frontend/util/cursor.cljs

@@ -131,10 +131,12 @@
     (move-cursor-to input pos)))
 
 (defn move-cursor-to-thing
-  [input thing from]
-  (let [[content _pos] (get-input-content&pos input)
-        pos (string/index-of content thing from)]
-    (move-cursor-to input pos)))
+  ([input thing]
+   (move-cursor-to-thing input thing (pos input)))
+  ([input thing from]
+   (let [[content _pos] (get-input-content&pos input)
+         pos (string/index-of content thing from)]
+     (move-cursor-to input pos))))
 
 (defn move-cursor-forward-by-word
   [input]

+ 2 - 2
src/main/logseq/api.cljs

@@ -352,7 +352,7 @@
   (fn [block-uuid {:keys [pos] :or {pos :max} :as opts}]
     (when-let [block-uuid (and block-uuid (medley/uuid block-uuid))]
       (when-let [block (db-model/query-block-by-uuid block-uuid)]
-        (editor-handler/edit-block! block pos nil block-uuid)))))
+        (editor-handler/edit-block! block pos block-uuid)))))
 
 (def ^:export insert_block
   (fn [block-uuid-or-page-name content ^js opts]
@@ -526,4 +526,4 @@
 (defn ^:export force_save_graph
   []
   (p/let [_ (el/persist-dbs!)
-          _ (reset! handler/triggered? true)]))
+          _ (reset! handler/triggered? true)]))