mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix(plugin): incorrect mouse point payload for the plugin hook of input selection (#10175)
This commit is contained in:
@@ -86,20 +86,24 @@
|
||||
(rum/defc ls-textarea
|
||||
< rum/reactive
|
||||
{:did-mount (fn [state]
|
||||
(let [^js el (rum/dom-node state)]
|
||||
(let [^js el (rum/dom-node state)
|
||||
*mouse-point (volatile! nil)]
|
||||
;; Passing aria-label as a prop to TextareaAutosize removes the dash
|
||||
(.setAttribute el "aria-label" "editing block")
|
||||
(. el addEventListener "select"
|
||||
#(let [start (util/get-selection-start el)
|
||||
end (util/get-selection-end el)]
|
||||
(when (and start end)
|
||||
(when-let [e (and (not= start end)
|
||||
{:caret (cursor/get-caret-pos el)
|
||||
:start start :end end
|
||||
:text (. (.-value el) substring start end)
|
||||
:point {:x (.-x %) :y (.-y %)}})]
|
||||
|
||||
(plugin-handler/hook-plugin-editor :input-selection-end (bean/->js e)))))))
|
||||
(doto el
|
||||
(.addEventListener "select"
|
||||
#(let [start (util/get-selection-start el)
|
||||
end (util/get-selection-end el)]
|
||||
(when (and start end)
|
||||
(when-let [e (and (not= start end)
|
||||
(let [caret-pos (cursor/get-caret-pos el)]
|
||||
{:caret caret-pos
|
||||
:start start :end end
|
||||
:text (. (.-value el) substring start end)
|
||||
:point (select-keys (or @*mouse-point caret-pos) [:x :y])}))]
|
||||
(plugin-handler/hook-plugin-editor :input-selection-end (bean/->js e))
|
||||
(vreset! *mouse-point nil)))))
|
||||
(.addEventListener "mouseup" #(vreset! *mouse-point {:x (.-x %) :y (.-y %)}))))
|
||||
state)}
|
||||
[{:keys [on-change] :as props}]
|
||||
(let [skip-composition? (state/sub :editor/action)
|
||||
@@ -112,16 +116,16 @@
|
||||
(on-change e))
|
||||
(state/set-editor-in-composition! true))))
|
||||
props (assoc props
|
||||
:on-change (fn [e] (when-not (state/editor-in-composition?)
|
||||
(on-change e)))
|
||||
:on-composition-start on-composition
|
||||
:on-composition-update on-composition
|
||||
:on-composition-end on-composition)]
|
||||
:on-change (fn [e] (when-not (state/editor-in-composition?)
|
||||
(on-change e)))
|
||||
:on-composition-start on-composition
|
||||
:on-composition-update on-composition
|
||||
:on-composition-end on-composition)]
|
||||
(textarea props)))
|
||||
|
||||
(rum/defc dropdown-content-wrapper
|
||||
< {:did-mount (fn [state]
|
||||
(let [k (inc (count (state/sub :modal/dropdowns)))
|
||||
(let [k (inc (count (state/sub :modal/dropdowns)))
|
||||
args (:rum/args state)]
|
||||
(state/set-state! [:modal/dropdowns k] (second args))
|
||||
(assoc state ::k k)))
|
||||
|
||||
Reference in New Issue
Block a user