Sfoglia il codice sorgente

fix: page/block auto-complete search can clear the editing block

Related to #2526
Tienson Qin 4 anni fa
parent
commit
d8400b389a

+ 16 - 2
src/main/frontend/commands.cljs

@@ -306,12 +306,18 @@
 
 (defn insert!
   [id value
-   {:keys [last-pattern postfix-fn backward-pos forward-pos]
+   {:keys [last-pattern postfix-fn backward-pos forward-pos
+           end-pattern]
     :or {last-pattern slash}
     :as option}]
   (when-let [input (gdom/getElement id)]
     (let [edit-content (gobj/get input "value")
           current-pos (cursor/pos input)
+          current-pos (or
+                       (when (and end-pattern (string? end-pattern))
+                         (when-let [i (string/index-of (util/safe-subs edit-content current-pos) end-pattern)]
+                           (+ current-pos i)))
+                       current-pos)
           prefix (subs edit-content 0 current-pos)
           space? (when (and last-pattern prefix)
                    (let [s (when-let [last-index (string/last-index-of prefix last-pattern)]
@@ -330,8 +336,16 @@
                    (util/replace-last last-pattern prefix value space?))
           postfix (subs edit-content current-pos)
           postfix (if postfix-fn (postfix-fn postfix) postfix)
-          new-value (if space?
+          new-value (cond
+                      (and
+                       (string/blank? prefix)
+                       (string/blank? postfix))
+                      edit-content
+
+                      space?
                       (util/concat-without-spaces prefix postfix)
+
+                      :else
                       (str prefix postfix))
           new-pos (- (+ (count prefix)
                         (or forward-pos 0))

+ 3 - 1
src/main/frontend/components/page.cljs

@@ -103,7 +103,9 @@
     [:div.flex.flex-row.items-center.mr-2.ml-1 {:style {:height 24}}
      [:span.bullet-container.cursor
       [:span.bullet]]]
-    [:div.flex.flex-1 {:on-click #(editor-handler/insert-first-page-block-if-not-exists! page-name)}
+    [: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)))}
      [:span.opacity-50
       "Click here to edit..."]]]])
 

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

@@ -239,7 +239,7 @@
        :on-change (fn [e]
                     (let [format (util/evalue e)]
                       (when-not (string/blank? format)
-                        (config-handler/set-config! :date-formatter format)
+                        (config-handler/set-config! :journal/page-title-format format)
                         (notification/show!
                          [:div "You need to re-index your graph to make the change works"]
                          :success)

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

@@ -1899,6 +1899,7 @@
                        (util/format "((%s))" uuid-string)
                        format
                        {:last-pattern (str "((" (if @*selected-text "" q))
+                        :end-pattern "))"
                         :postfix-fn   (fn [s] (util/replace-first "))" s ""))})
 
       ;; Save it so it'll be parsed correctly in the future

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

@@ -598,6 +598,7 @@
                                           (str "#" (when wrapped? "[[") chosen)
                                           format
                                           {:last-pattern last-pattern
+                                           :end-pattern "]]"
                                            :forward-pos forward-pos})))
       (fn [chosen _click?]
         (state/set-editor-show-page-search! false)
@@ -606,6 +607,7 @@
                                           page-ref-text
                                           format
                                           {:last-pattern (str "[[" (if @editor-handler/*selected-text "" q))
+                                           :end-pattern "]]"
                                            :postfix-fn   (fn [s] (util/replace-first "]]" s ""))}))))))
 
 (defn create-today-journal!

+ 2 - 1
src/main/frontend/state.cljs

@@ -949,7 +949,8 @@
   []
   (or
    (when-let [repo (get-current-repo)]
-     (get-in @state [:config repo :date-formatter]))
+     (or (get-in @state [:config repo :date-formatter])
+         (get-in @state [:config repo :journal/page-title-format])))
    ;; TODO:
    (get-in @state [:me :settings :date-formatter])
    "MMM do, yyyy"))