fix: block property values auto-complete

pull/5935/head
Tienson Qin 2022-07-05 09:14:47 +08:00
parent 1d88e285b0
commit 204392f896
4 changed files with 38 additions and 26 deletions

View File

@ -342,7 +342,10 @@
(string/ends-with? s "(")
(or (string/starts-with? last-pattern "((")
(string/starts-with? last-pattern "[[")))
(and s (string/starts-with? s "{{embed"))))))]
(and s (string/starts-with? s "{{embed"))
(and last-pattern
(or (string/ends-with? last-pattern "::")
(string/starts-with? last-pattern "::")))))))]
(if (and space? (string/starts-with? last-pattern "#[["))
false
space?))

View File

@ -262,6 +262,7 @@
(when (>= current-pos (+ start-idx 2))
(subs edit-content (+ start-idx 2) current-pos))
"")
q (string/triml q)
matched-values (editor-handler/get-matched-property-values property q)
non-exist-handler (fn [_state]
((editor-handler/property-value-on-chosen-handler id q) nil))]

View File

@ -2080,17 +2080,22 @@
(when-let [input (gdom/getElement element-id)]
(let [{:keys [end-index searching-property]} (get-searching-property input)]
(cursor/move-cursor-to input (+ end-index 2))
(commands/insert! element-id (str (or property q) "::")
(commands/insert! element-id (str (or property q) ":: ")
{:last-pattern (str searching-property "::")})
(state/set-editor-action-data! {:property (or property q)
:pos (cursor/get-caret-pos input)})
(state/set-editor-action! :property-value-search)))))
(state/clear-editor-action!)
(js/setTimeout (fn []
(let [pos (let [input (gdom/getElement element-id)]
(cursor/get-caret-pos input))]
(state/set-editor-action-data! {:property (or property q)
:pos pos})
(state/set-editor-action! :property-value-search)))
50)))))
(defn property-value-on-chosen-handler
[element-id q]
(fn [property-value]
(commands/insert! element-id (or property-value q)
{:last-pattern q})
(commands/insert! element-id (str ":: " (or property-value q))
{:last-pattern (str ":: " q)})
(state/clear-editor-action!)))
(defn parent-is-page?

View File

@ -156,35 +156,38 @@
([q]
(template-search q 10))
([q limit]
(let [q (clean-str q)
templates (db/get-all-templates)]
(when (seq templates)
(let [result (fuzzy-search (keys templates) q :limit limit)]
(vec (select-keys templates result)))))))
(when q
(let [q (clean-str q)
templates (db/get-all-templates)]
(when (seq templates)
(let [result (fuzzy-search (keys templates) q :limit limit)]
(vec (select-keys templates result))))))))
(defn property-search
([q]
(property-search q 10))
([q limit]
(let [q (clean-str q)
properties (map name (db-model/get-all-properties))]
(when (seq properties)
(if (string/blank? q)
properties
(let [result (fuzzy-search properties q :limit limit)]
(vec result)))))))
(when q
(let [q (clean-str q)
properties (map name (db-model/get-all-properties))]
(when (seq properties)
(if (string/blank? q)
properties
(let [result (fuzzy-search properties q :limit limit)]
(vec result))))))))
(defn property-value-search
([property q]
(property-value-search property q 10))
([property q limit]
(let [q (clean-str q)
result (db-model/get-property-values (keyword property))]
(when (seq result)
(if (string/blank? q)
result
(let [result (fuzzy-search result q :limit limit)]
(vec result)))))))
(when q
(let [q (clean-str q)
result (db-model/get-property-values (keyword property))]
(when (seq result)
(if (string/blank? q)
result
(let [result (fuzzy-search result q :limit limit)]
(vec result))))))))
(defn sync-search-indice!
[repo tx-report]