1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-14 19:24:09 +02:00

add logic to handle rich text pastes

This commit is contained in:
Ian Storm Taylor
2016-11-21 13:36:00 -08:00
parent 1c1954a1de
commit 0b5ba16400

View File

@@ -157,6 +157,24 @@ class Transfer {
return node
}
/**
* Get the rich text content of the data transfer.
*
* @return {String|Void}
*/
getRichText() {
if ('richtext' in this.cache) return this.cache.richtext
let richtext
const string = this.data.getData('text/rtf')
if (string != '') richtext = string
this.cache.richtext = richtext
return richtext
}
/**
* Get the text content of the data transfer.
*
@@ -184,6 +202,13 @@ class Transfer {
getType() {
if (this.hasFragment()) return 'fragment'
if (this.hasNode()) return 'node'
// COMPAT: Microsoft Word adds an image of the selected text to the data.
// Since files are preferred over HTML, this would cause the type to be
// considered `files`. But it also adds rich text data so we can check for
// that and properly set the type to `html`. (2016/11/21)
if (this.hasRichText() && this.hasHtml()) return 'html'
if (this.hasFiles()) return 'files'
if (this.hasHtml()) return 'html'
if (this.hasText()) return 'text'
@@ -210,6 +235,16 @@ class Transfer {
return this.getHtml() != null
}
/**
* Check whether the data transfer has rich text content.
*
* @return {Boolean}
*/
hasRichText() {
return this.getRichText() != null
}
/**
* Check whether the data transfer has text content.
*