mirror of https://github.com/logseq/logseq
feat: set text/html when copy html text
parent
435c2110bc
commit
07917b36c7
|
@ -149,5 +149,5 @@
|
|||
|
||||
(ui/button (if @copied? "Copied to clipboard!" "Copy to clipboard")
|
||||
:on-click (fn []
|
||||
(util/copy-to-clipboard! content)
|
||||
(util/copy-to-clipboard! content (= type :html))
|
||||
(reset! copied? true)))]))
|
||||
|
|
|
@ -771,16 +771,11 @@
|
|||
#?(:cljs (def clear-selection! selection/clearSelection))
|
||||
|
||||
#?(:cljs
|
||||
(defn copy-to-clipboard! [s]
|
||||
(let [el (js/document.createElement "textarea")]
|
||||
(set! (.-value el) s)
|
||||
(.setAttribute el "readonly" "")
|
||||
(set! (-> el .-style .-position) "absolute")
|
||||
(set! (-> el .-style .-left) "-9999px")
|
||||
(js/document.body.appendChild el)
|
||||
(.select el)
|
||||
(js/document.execCommand "copy")
|
||||
(js/document.body.removeChild el))))
|
||||
(defn copy-to-clipboard!
|
||||
([s]
|
||||
(utils/writeClipboard s false))
|
||||
([s html?]
|
||||
(utils/writeClipboard s html?))))
|
||||
|
||||
(def uuid-pattern "[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}")
|
||||
(defonce exactly-uuid-pattern (re-pattern (str "(?i)^" uuid-pattern "$")))
|
||||
|
|
|
@ -231,3 +231,22 @@ export const getClipText = function (cb, errorHandler) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const writeClipboard = function(text, isHtml) {
|
||||
if (isHtml) {
|
||||
var blob = new Blob([text], {type:["text/plain", "text/html"]})
|
||||
var data = [new ClipboardItem({["text/plain"]: blob, ["text/html"]:blob})];
|
||||
} else{
|
||||
var blob = new Blob([text], {type:["text/plain"]})
|
||||
var data = [new ClipboardItem({["text/plain"]: blob})];
|
||||
}
|
||||
navigator.permissions.query({ name: "clipboard-write" }).then((result) => {
|
||||
if (result.state == "granted" || result.state == "prompt") {
|
||||
navigator.clipboard.write(data).then(function() {
|
||||
/* success */
|
||||
}, function(e) {
|
||||
console.log(e, "fail")
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue