Przeglądaj źródła

fix: add spaces around block ref

Tienson Qin 2 lat temu
rodzic
commit
e32b73fa11

+ 4 - 3
src/main/frontend/commands.cljs

@@ -322,7 +322,7 @@
 
 (defn insert!
   [id value
-   {:keys [last-pattern postfix-fn backward-pos forward-pos end-pattern backward-truncate-number]
+   {:keys [last-pattern postfix-fn backward-pos forward-pos end-pattern backward-truncate-number command]
     :as _option}]
   (when-let [input (gdom/getElement id)]
     (let [last-pattern (when-not backward-truncate-number
@@ -342,8 +342,9 @@
                                           (gp-util/safe-subs orig-prefix 0 last-index))]
                                   (not
                                    (or
-                                    (util/cjk-string? (str (last orig-prefix)))
-                                    (util/cjk-string? (str (first postfix)))
+                                    (and (not= command :block-ref)
+                                         (or (util/cjk-string? (str (last orig-prefix)))
+                                             (util/cjk-string? (str (first postfix)))))
                                     (and s
                                          (string/ends-with? s "(")
                                          (or (string/starts-with? last-pattern block-ref/left-parens)

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

@@ -163,7 +163,7 @@
                (editor-handler/insert-command! id
                                                (page-ref/->page-ref journal)
                                                format
-                                               nil)
+                                               {:command :page-ref})
                (state/clear-editor-action!)
                (reset! commands/*current-command nil))))})
        (when deadline-or-schedule?

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

@@ -76,7 +76,8 @@
                                    (not (contains? #{"Date picker" "Template" "Deadline" "Scheduled" "Upload an image"} command))))]
               (editor-handler/insert-command! id command-steps
                                               format
-                                              {:restore? restore-slash?}))))
+                                              {:restore? restore-slash?
+                                               :command command}))))
         :class
         "black"}))))
 
@@ -89,7 +90,8 @@
        {:on-chosen (fn [chosen]
                      (editor-handler/insert-command! id (get (into {} matched) chosen)
                                                      format
-                                                     {:last-pattern commands/angle-bracket}))
+                                                     {:last-pattern commands/angle-bracket
+                                                      :command :block-commands}))
         :class     "black"}))))
 
 (defn- in-sidebar? [el]

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

@@ -1478,7 +1478,8 @@
                                        image?)
                   format
                   {:last-pattern (if drop-or-paste? "" (state/get-editor-command-trigger))
-                   :restore?     true})))))
+                   :restore?     true
+                   :command      :insert-asset})))))
           (p/finally
             (fn []
               (reset! uploading? false)
@@ -1732,7 +1733,8 @@
                id
                (get-link format link label)
                format
-               {:last-pattern (str (state/get-editor-command-trigger) "link")})))
+               {:last-pattern (str (state/get-editor-command-trigger) "link")
+                :command :link})))
 
     :image-link (let [{:keys [link label]} m]
                   (when (not (string/blank? link))
@@ -1740,7 +1742,8 @@
                      id
                      (get-image-link format link label)
                      format
-                     {:last-pattern (str (state/get-editor-command-trigger) "link")})))
+                     {:last-pattern (str (state/get-editor-command-trigger) "link")
+                      :command :image-link})))
 
     nil)
 
@@ -1858,7 +1861,8 @@
                        {:last-pattern (str block-ref/left-parens (if @*selected-text "" q))
                         :end-pattern block-ref/right-parens
                         :postfix-fn   (fn [s] (util/replace-first block-ref/right-parens s ""))
-                        :forward-pos 3})
+                        :forward-pos 3
+                        :command :block-ref})
 
       ;; Save it so it'll be parsed correctly in the future
       (set-block-property! (:block/uuid chosen)
@@ -1890,7 +1894,7 @@
            {:block/page {:db/id (:db/id page)}
             :block/format format
             :block/properties (apply dissoc (:block/properties block)
-                                (concat 
+                                (concat
                                   (when (not keep-uuid?) [:id])
                                   [:custom_id :custom-id]
                                   exclude-properties))
@@ -2837,7 +2841,8 @@
                   (insert-command! input-id
                                    (last (first matched-block-commands))
                                    format
-                                   {:last-pattern commands/angle-bracket}))
+                                   {:last-pattern commands/angle-bracket
+                                    :command :block-commands}))
 
                 :else
                 (reset! commands/*matched-block-commands matched-block-commands))

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

@@ -782,7 +782,8 @@
                                           format
                                           {:last-pattern last-pattern
                                            :end-pattern (when wrapped? page-ref/right-brackets)
-                                           :forward-pos forward-pos})))
+                                           :forward-pos forward-pos
+                                           :command :tag-page-ref})))
       (fn [chosen _click?]
         (state/clear-editor-action!)
         (let [prefix (str (t :new-page) ": ")
@@ -796,7 +797,8 @@
                                           {:last-pattern (str page-ref/left-brackets (if @editor-handler/*selected-text "" q))
                                            :end-pattern page-ref/right-brackets
                                            :postfix-fn   (fn [s] (util/replace-first page-ref/right-brackets s ""))
-                                           :forward-pos 3}))))))
+                                           :forward-pos 3
+                                           :command :page-ref}))))))
 
 (defn create-today-journal!
   []