fix: simplify internal pasting check

pull/5716/head^2
Tienson Qin 2022-06-16 04:19:43 +08:00
parent b59d98ada5
commit 807beb2586
1 changed files with 9 additions and 16 deletions

View File

@ -73,17 +73,14 @@
(let [copied-blocks (state/get-copied-blocks) (let [copied-blocks (state/get-copied-blocks)
copied-block-ids (:copy/block-ids copied-blocks) copied-block-ids (:copy/block-ids copied-blocks)
copied-graph (:copy/graph copied-blocks) copied-graph (:copy/graph copied-blocks)
input (state/get-input)] input (state/get-input)
(if internal-paste? (and
;; Internal blocks by either copy or cut blocks (= copied-graph (state/get-current-repo))
(and (or (seq copied-block-ids)
(= copied-graph (state/get-current-repo)) (seq (:copy/full-blocks copied-blocks)))
(or (seq copied-block-ids) ;; not copied from the external clipboard
(seq (:copy/full-blocks copied-blocks))) (= text (:copy/content copied-blocks)))]
text (if internal-paste?
;; not copied from the external clipboard
(= (string/replace (string/trim text) "\r" "")
(string/replace (string/trim (or (:copy/content copied-blocks) "")) "\r" "")))
(do (do
(util/stop e) (util/stop e)
(let [blocks (or (let [blocks (or
@ -92,7 +89,6 @@
(when (seq blocks) (when (seq blocks)
(state/set-copied-full-blocks! blocks) (state/set-copied-full-blocks! blocks)
(editor-handler/paste-blocks blocks {})))) (editor-handler/paste-blocks blocks {}))))
(cond (cond
(and (gp-util/url? text) (and (gp-util/url? text)
(not (string/blank? (util/get-selected-text)))) (not (string/blank? (util/get-selected-text))))
@ -177,10 +173,7 @@
html (when-not raw-paste? (.getData clipboard-data "text/html")) html (when-not raw-paste? (.getData clipboard-data "text/html"))
edit-block (state/get-edit-block) edit-block (state/get-edit-block)
format (or (:block/format edit-block) :markdown) format (or (:block/format edit-block) :markdown)
text (.getData clipboard-data "text") text (.getData clipboard-data "text")]
text (or (when-not (string/blank? html)
(html-parser/convert format html))
text)]
(if-not (string/blank? text) (if-not (string/blank? text)
(paste-text-or-blocks-aux input e text html) (paste-text-or-blocks-aux input e text html)
(when id (when id