fix: raw paste

pull/5716/head^2
Tienson Qin 2022-06-16 01:00:05 +08:00
parent 7bab4469a6
commit 999defdad1
2 changed files with 44 additions and 27 deletions

View File

@ -2971,33 +2971,50 @@
(fn [error]
(js/console.error error))))
(defn editor-on-paste!
[id]
(fn [e]
(state/set-state! :editor/on-paste? true)
(let [clipboard-data (gobj/get e "clipboardData")
html (.getData clipboard-data "text/html")
edit-block (state/get-edit-block)
format (or (:block/format edit-block) :markdown)
initial-text (.getData clipboard-data "text")
text (or (when-not (string/blank? html)
(html-parser/convert format html))
initial-text)
input (state/get-input)]
(if-not (string/blank? text)
(defn- paste-text-or-blocks-aux
[input e initial-text text]
(if (or (thingatpt/markdown-src-at-point input)
(thingatpt/org-admonition&src-at-point input))
(when-not (mobile-util/native-ios?)
(util/stop e)
(paste-text-in-one-block-at-point))
(paste-copied-blocks-or-text initial-text text e))
(paste-copied-blocks-or-text initial-text text e)))
(defn editor-on-paste!
([id]
(editor-on-paste! id false))
([id raw-paste?]
(fn [e]
(state/set-state! :editor/on-paste? true)
(let [input (state/get-input)]
(if raw-paste?
(utils/getClipText
(fn [clipboard-data]
(when-let [_ (state/get-input)]
(let [text (or (when (gp-util/url? clipboard-data)
(wrap-macro-url clipboard-data))
clipboard-data)]
(paste-text-or-blocks-aux input e text text))))
(fn [error]
(js/console.error error)))
(let [clipboard-data (gobj/get e "clipboardData")
html (when-not raw-paste? (.getData clipboard-data "text/html"))
edit-block (state/get-edit-block)
format (or (:block/format edit-block) :markdown)
initial-text (.getData clipboard-data "text")
text (or (when-not (string/blank? html)
(html-parser/convert format html))
initial-text)]
(if-not (string/blank? text)
(paste-text-or-blocks-aux input e initial-text text)
(when id
(let [_handled
(let [clipboard-data (gobj/get e "clipboardData")
files (.-files clipboard-data)]
(when-let [file (first files)]
(when-let [block (state/get-edit-block)]
(upload-asset id #js[file] (:block/format block) *asset-uploading? true))))]
(util/stop e))))))
(util/stop e))))))))))
(defn- cut-blocks-and-clear-selections!
[copy?]

View File

@ -149,7 +149,7 @@
:fn editor-handler/copy-current-block-embed}
:editor/paste-text-in-one-block-at-point {:binding "mod+shift+v"
:fn editor-handler/paste-text-in-one-block-at-point}
:fn (fn [_state e] ((editor-handler/editor-on-paste! nil true) e))}
:editor/insert-youtube-timestamp {:binding "mod+shift+y"
:fn commands/insert-youtube-timestamp}