Selaa lähdekoodia

fix: suggestions from gabriel

Tienson Qin 3 vuotta sitten
vanhempi
sitoutus
139075e679

+ 6 - 6
src/main/frontend/commands.cljs

@@ -605,22 +605,22 @@
         (state/set-edit-content! input-id new-value)))))
 
 (defmethod handle-step :editor/search-page [[_]]
-  (state/set-editor-show-page-search! true))
+  (state/set-editor-action! :page-search))
 
 (defmethod handle-step :editor/search-page-hashtag [[_]]
-  (state/set-editor-show-page-search-hashtag! true))
+  (state/set-editor-action! :page-search-hashtag))
 
 (defmethod handle-step :editor/search-block [[_ _type]]
-  (state/set-editor-show-block-search! true))
+  (state/set-editor-action! :block-search))
 
 (defmethod handle-step :editor/search-template [[_]]
-  (state/set-editor-show-template-search! true))
+  (state/set-editor-action! :template-search))
 
 (defmethod handle-step :editor/show-input [[_ option]]
   (state/set-editor-show-input! option))
 
 (defmethod handle-step :editor/show-zotero [[_]]
-  (state/set-editor-show-zotero! true))
+  (state/set-editor-action! :zotero))
 
 (defn insert-youtube-timestamp
   []
@@ -643,7 +643,7 @@
     (do
       (notification/show! [:div "Please add some content first."] :warning)
       (restore-state))
-    (state/set-editor-show-date-picker! true)))
+    (state/set-editor-action! :datepicker)))
 
 (defmethod handle-step :editor/click-hidden-file-input [[_ _input-id]]
   (when-let [input-file (gdom/getElement "upload-file")]

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

@@ -1896,12 +1896,12 @@
                            (do
                              (reset! show? false)
                              (reset! commands/*current-command nil)
-                             (state/set-editor-show-date-picker! false)
+                             (state/clear-editor-action!)
                              (state/set-timestamp-block! nil))
                            (do
                              (reset! show? true)
                              (reset! commands/*current-command typ)
-                             (state/set-editor-show-date-picker! true)
+                             (state/set-editor-action! :datepicker)
                              (state/set-timestamp-block! {:block block
                                                           :typ typ
                                                           :show? show?}))))}

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

@@ -105,7 +105,6 @@
     (when show?
       (reset! show? false)))
   (clear-timestamp!)
-  (state/set-editor-show-date-picker! false)
   (commands/restore-state))
 
 (rum/defc time-repeater < rum/reactive
@@ -164,7 +163,7 @@
                                                (util/format "[[%s]]" journal)
                                                format
                                                nil)
-               (state/set-editor-show-date-picker! false)
+               (state/clear-editor-action!)
                (reset! commands/*current-command nil))))})
        (when deadline-or-schedule?
          (time-repeater))])))

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

@@ -219,7 +219,7 @@
                "")
             matched-templates (editor-handler/get-matched-templates q)
             non-exist-handler (fn [_state]
-                                (state/set-editor-show-template-search! false))]
+                                (state/clear-editor-action!))]
         (ui/auto-complete
          matched-templates
          {:on-chosen   (editor-handler/template-on-chosen-handler id)

+ 1 - 1
src/main/frontend/extensions/zotero/handler.cljs

@@ -41,7 +41,7 @@
 
 (defn handle-command-zotero
   [id page-name]
-  (state/set-editor-show-zotero! false)
+  (state/clear-editor-action!)
   (editor-handler/insert-command! id (str "[[" page-name "]]") nil {}))
 
 (defn- create-abstract-note!

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

@@ -1848,7 +1848,7 @@
       (do
         (cursor/move-cursor-backward input 2)
         (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
-        (state/set-editor-show-property-search! true))
+        (state/set-editor-action! :property-search))
 
       (and
        (not= :property-search (state/get-editor-action))
@@ -1856,7 +1856,7 @@
            (wrapped-by? input "\n" "::")))
       (do
         (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
-        (state/set-editor-show-property-search! true))
+        (state/set-editor-action! :property-search))
 
       (and (= last-input-char commands/colon) (= :property-search (state/get-editor-action)))
       (state/clear-editor-action!)
@@ -1867,7 +1867,7 @@
 (defn block-on-chosen-handler
   [_input id q format]
   (fn [chosen _click?]
-    (state/set-editor-show-block-search! false)
+    (state/clear-editor-action!)
     (let [uuid-string (str (:block/uuid chosen))]
 
       ;; block reference
@@ -1890,7 +1890,7 @@
 (defn block-non-exist-handler
   [input]
   (fn []
-    (state/set-editor-show-block-search! false)
+    (state/clear-editor-action!)
     (cursor/move-cursor-forward input 2)))
 
 (defn- paste-block-cleanup
@@ -2299,7 +2299,7 @@
                             :check-fn (fn [_ _ _]
                                         (state/set-editor-action-data! {:pos new-pos})
                                         (commands/handle-step [:editor/search-page]))}))]
-        (state/set-editor-show-page-search! false)
+        (state/clear-editor-action!)
         (let [selection (get-selection-and-format)
               {:keys [selection-start selection-end selection]} selection]
           (if selection
@@ -2332,7 +2332,7 @@
                              :check-fn     (fn [_ _ _]
                                              (state/set-editor-action-data! {:pos new-pos})
                                              (commands/handle-step [:editor/search-block]))}))]
-        (state/set-editor-show-block-search! false)
+        (state/clear-editor-action!)
         (if-let [embed-ref (thingatpt/embed-macro-at-point input)]
           (let [{:keys [raw-content start end]} embed-ref]
             (delete-and-update input start end)
@@ -2638,10 +2638,10 @@
         (commands/delete-pair! id)
         (cond
           (and (= deleted "[") (state/get-editor-show-page-search?))
-          (state/set-editor-show-page-search! false)
+          (state/clear-editor-action!)
 
           (and (= deleted "(") (state/get-editor-show-block-search?))
-          (state/set-editor-show-block-search! false)
+          (state/clear-editor-action!)
 
           :else
           nil))
@@ -2649,7 +2649,7 @@
       ;; deleting hashtag
       (and (= deleted "#") (state/get-editor-show-page-search-hashtag?))
       (do
-        (state/set-editor-show-page-search-hashtag! false)
+        (state/clear-editor-action!)
         (delete-and-update input (dec current-pos) current-pos))
 
       ;; just delete
@@ -2729,7 +2729,7 @@
         (and (= key "#")
              (and (> pos 0)
                   (= "#" (util/nth-safe value (dec pos)))))
-        (state/set-editor-show-page-search-hashtag! false)
+        (state/clear-editor-action!)
 
         (and (contains? (set/difference (set (keys reversed-autopair-map))
                                         #{"`"})
@@ -2831,7 +2831,7 @@
 
           (and (state/get-editor-show-page-search-hashtag?)
                (= c " "))
-          (state/set-editor-show-page-search-hashtag! false)
+          (state/clear-editor-action!)
 
           :else
           (when (and (not editor-action) (not non-enter-processed?))

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

@@ -683,7 +683,7 @@
 ;; Editor
 (defn page-not-exists-handler
   [input id q current-pos]
-  (state/set-editor-show-page-search! false)
+  (state/clear-editor-action!)
   (if (state/org-mode-file-link? (state/get-current-repo))
     (let [page-ref-text (get-page-ref-text q)
           value (gobj/get input "value")

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

@@ -602,36 +602,18 @@
   []
   (:editor/action-data @state))
 
-(defn set-editor-show-page-search!
-  [value]
-  (set-editor-action! (when value :page-search)))
-
 (defn get-editor-show-page-search?
   []
   (= (get-editor-action) :page-search))
 
-(defn set-editor-show-page-search-hashtag!
-  [value]
-  (set-editor-action! (when value :page-search-hashtag)))
-
 (defn get-editor-show-page-search-hashtag?
   []
   (= (get-editor-action) :page-search-hashtag))
-(defn set-editor-show-block-search!
-  [value]
-  (set-editor-action! (when value :block-search)))
+
 (defn get-editor-show-block-search?
   []
   (= (get-editor-action) :block-search))
-(defn set-editor-show-template-search!
-  [value]
-  (set-editor-action! (when value :template-search)))
-(defn set-editor-show-property-search!
-  [value]
-  (set-editor-action! (when value :property-search)))
-(defn set-editor-show-date-picker!
-  [value]
-  (set-editor-action! (when value :datepicker)))
+
 (defn set-editor-show-input!
   [value]
   (if value
@@ -652,10 +634,6 @@
   []
   (when-not (get-editor-action) (set-editor-action! :block-commands)))
 
-(defn set-editor-show-zotero!
-  [value]
-  (set-state! :editor/show-zotero value))
-
 (defn clear-editor-action!
   []
   (swap! state (fn [state]

+ 3 - 3
src/main/frontend/util/text.cljs

@@ -86,7 +86,7 @@
 
 (defn get-string-all-indexes
   "Get all indexes of `value` in the string `s`."
-  [s value before?]
+  [s value {:keys [before?] :or {before? true}}]
   (if (= value "")
     (if before? [0] [(dec (count s))])
     (loop [acc []
@@ -98,9 +98,9 @@
 (defn wrapped-by?
   "`pos` must be wrapped by `before` and `and` in string `value`, e.g. ((a|b))"
   [value pos before end]
-  (let [before-matches (->> (get-string-all-indexes value before true)
+  (let [before-matches (->> (get-string-all-indexes value before {:before? true})
                             (map (fn [i] [i :before])))
-        end-matches (->> (get-string-all-indexes value end false)
+        end-matches (->> (get-string-all-indexes value end {:before? false})
                          (map (fn [i] [i :end])))
         indexes (sort-by first (concat before-matches end-matches [[pos :between]]))
         ks (map second indexes)

+ 3 - 3
src/test/frontend/util/text_test.cljs

@@ -23,11 +23,11 @@
 (deftest get-string-all-indexes
   []
   (are [x y] (= x y)
-    (text-util/get-string-all-indexes "[[hello]] [[world]]" "[[" true)
+    (text-util/get-string-all-indexes "[[hello]] [[world]]" "[[" {})
     [0 10]
 
-    (text-util/get-string-all-indexes "abc abc ab" "ab" true)
+    (text-util/get-string-all-indexes "abc abc ab" "ab" {})
     [0 4 8]
 
-    (text-util/get-string-all-indexes "a.c a.c ab" "a." true)
+    (text-util/get-string-all-indexes "a.c a.c ab" "a." {})
     [0 4]))