🐛 Fix replace text by ref when dropdown is opened by click

This commit is contained in:
Eva Marco 2026-06-15 09:38:25 +02:00
parent 68d4238277
commit 26ed476d72
5 changed files with 17 additions and 7 deletions

View File

@ -721,7 +721,7 @@
(or (nil? last-space-left) (> (dm/number open-pos) (dm/number last-space-left)))
(or (nil? first-space-right) (< (dm/number close-pos) (dm/number first-space-right)))))))
(defn- build-result
(defn build-result
"Builds the result map for `insert-ref` by replacing the substring of `value`
between `prefix-end` and `suffix-start` with a formatted reference `{name}`.
Returns a map with:

View File

@ -147,12 +147,14 @@
toggle-dropdown
(mf/use-fn
(mf/deps is-open)
(fn [event]
(fn [event & [select-text?]]
(dom/prevent-default event)
(swap! is-open* not)
(reset! selected-id* (get-selected-id))
(let [input-node (mf/ref-val ref)]
(dom/focus! input-node))))
(when select-text?
(let [input-node (mf/ref-val ref)]
(dom/select-text! input-node)
(dom/focus! input-node)))))
resolve-stream
(mf/with-memo [token]
@ -264,7 +266,7 @@
:tab-index "-1"
:aria-label (tr "ds.inputs.numeric-input.open-token-list-dropdown")
:on-mouse-down dom/prevent-default
:on-click toggle-dropdown}]))})
:on-click #(toggle-dropdown % true)}]))})
props
(if (or extra-error (and error touched?))
(mf/spread-props props {:hint-type "error"

View File

@ -65,7 +65,7 @@
;; Dropdown closed with options: open and focus first
(seq focusables)
(do
(toggle-dropdown event)
(toggle-dropdown event false)
(when get-selected-id
(get-selected-id))
(reset! focused-id* (first-focusable-id focusables)))

View File

@ -50,9 +50,12 @@
(defn select-option-by-id
[id options-ref input-node value]
(let [cursor (dom/selection-start input-node)
sel-end (dom/selection-end input-node)
options (mf/ref-val options-ref)
options (if (delay? options) @options options)
option (get-option options id)
name (:name option)]
(cto/insert-ref value cursor name)))
(if (= cursor sel-end)
(cto/insert-ref value cursor name)
(cto/build-result value cursor sel-end name))))

View File

@ -299,6 +299,11 @@
(when (some? node)
(.-selectionStart node)))
(defn selection-end
[^js node]
(when (some? node)
(.-selectionEnd node)))
(defn set-selection-range!
[^js node start end]
(when (some? node)