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

enhance(editor): reorder page search autocompletion items

Andelf 4 лет назад
Родитель
Сommit
e2ee41733d
1 измененных файлов с 11 добавлено и 7 удалено
  1. 11 7
      src/main/frontend/components/editor.cljs

+ 11 - 7
src/main/frontend/components/editor.cljs

@@ -1,5 +1,6 @@
 (ns frontend.components.editor
   (:require [clojure.string :as string]
+            [goog.string :as gstring]
             [frontend.commands :as commands
              :refer [*angle-bracket-caret-pos *first-command-group *matched-block-commands *matched-commands *show-block-commands *show-commands *slash-caret-pos]]
             [frontend.components.block :as block]
@@ -97,7 +98,7 @@
 
 (rum/defc page-search < rum/reactive
   {:will-unmount (fn [state] (reset! editor-handler/*selected-text nil) state)}
-  "Editor embedded page searching"
+  "Embedded page searching popup"
   [id format]
   (when (state/sub :editor/show-page-search?)
     (let [pos (:editor/last-saved-cursor @state/state)
@@ -119,20 +120,23 @@
                               (contains? (set (map util/page-name-sanity-lc matched-pages)) (util/page-name-sanity-lc (string/trim q)))  ;; if there's a page name fully matched
                               matched-pages
 
+                              (string/blank? q)
+                              nil
+
                               (empty? matched-pages)
-                              matched-pages
+                              (cons (str "New page: " q) matched-pages)
 
                               ;; reorder, shortest and starts-with first.
                               :else
                               (let [matched-pages (remove nil? matched-pages)
                                     matched-pages (sort-by
                                                    (fn [m]
-                                                     [(not (string/starts-with? m q)) (count m)])
+                                                     [(not (gstring/caseInsensitiveStartsWith m q)) (count m)])
                                                    matched-pages)]
-                                (cons (first matched-pages)
-                                      (cons
-                                       (str "New page: " q)
-                                       (rest matched-pages)))))]
+                                (if (gstring/caseInsensitiveStartsWith (first matched-pages) q)
+                                  (cons (first matched-pages)
+                                        (cons  (str "New page: " q) (rest matched-pages)))
+                                  (cons (str "New page: " q) matched-pages))))]
           (ui/auto-complete
            matched-pages
            {:on-chosen   (page-handler/on-chosen-handler input id q pos format)