🐛 Fix exception on paste text on comments input

This commit is contained in:
Andrey Antukh
2025-12-03 08:20:58 +01:00
parent a28c5b61ca
commit 58f82da61e
2 changed files with 14 additions and 4 deletions

View File

@@ -522,18 +522,22 @@
:blobs (seq files)}]
(st/emit! (dwm/upload-media-workspace params))))))))
(def ^:private invalid-paste-targets
#{"INPUT" "TEXTAREA"})
(defn on-paste
[disable-paste-ref in-viewport-ref read-only?]
(mf/use-fn
(mf/deps read-only?)
(fn [event]
;; We disable the paste just after mouse-up of a middle button so
;; when panning won't paste the content into the workspace
;; We disable the paste when: 1. just after mouse-up of a middle
;; button (so when panning won't paste the content into the
;; workspace); 2. when we paste content in an input on the
;; sidebar
(let [tag-name (-> event dom/get-target dom/get-tag-name)
disable-paste? (mf/ref-val disable-paste-ref)
in-viewport? (mf/ref-val in-viewport-ref)]
(when (and (not (#{"INPUT" "TEXTAREA"} tag-name))
(when (and (not (contains? invalid-paste-targets tag-name))
(not disable-paste?)
(not read-only?))
(st/emit! (dw/paste-from-event event in-viewport?)))))))

View File

@@ -59,6 +59,12 @@
(mf/with-effect [drawing-tool drawing-path?]
(let [key (events/listen js/window EventType.POINTERDOWN on-pointer-down)]
;; We need to disable workspace paste when we on comments
(if (= drawing-tool :comments)
(mf/set-ref-val! disable-paste-ref true)
(mf/set-ref-val! disable-paste-ref false))
#(events/unlistenByKey key)))
(mf/with-layout-effect [on-key-down on-key-up on-mouse-wheel on-paste workspace-read-only?]