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

fix for firefox erroring on copy/cut, closes #142

This commit is contained in:
Ian Storm Taylor
2016-07-21 10:53:52 -07:00
parent 840296617c
commit cac82ac65b

View File

@@ -210,6 +210,7 @@ class Content extends React.Component {
*/
onCutCopy = (e) => {
// debugger
const native = window.getSelection()
if (!native.rangeCount) return
@@ -244,7 +245,12 @@ class Content extends React.Component {
// Set the `isCopying` flag, so our `onSelect` logic doesn't fire.
this.tmp.isCopying = true
native.selectAllChildren(div)
const r = window.document.createRange()
// COMPAT: In Firefox, trying to use the terser `native.selectAllChildren`
// throws an error, so we use the older `range` equivalent. (2016/06/21)
r.selectNodeContents(div)
native.removeAllRanges()
native.addRange(r)
// Revert to the previous selection right after copying.
window.requestAnimationFrame(() => {
@@ -302,7 +308,7 @@ class Content extends React.Component {
const data = e.clipboardData
const paste = {}
// COMPAT: In Firefox, `types` is array-like.
// COMPAT: In Firefox, `types` is array-like. (2016/06/21)
const types = Array.from(data.types)
// Handle files.
@@ -410,8 +416,9 @@ class Content extends React.Component {
whiteSpace: 'pre-wrap',
// Allow words to break if they are too long.
wordWrap: 'break-word',
// COMPAT: Prevent iOS from showing the BIU formatting menu, which causes
// the internal state to get out of sync in weird ways.
// COMPAT: In iOS, a formatting menu with bold, italic and underline
// buttons is shown which causes our internal state to get out of sync in
// weird ways. This hides that. (2016/06/21)
...(readOnly ? {} : { WebkitUserModify: 'read-write-plaintext-only' }),
// Allow for passed-in styles to override anything.
...this.props.style,