mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 13:11:17 +02:00
fix for firefox erroring on copy/cut, closes #142
This commit is contained in:
@@ -210,6 +210,7 @@ class Content extends React.Component {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
onCutCopy = (e) => {
|
onCutCopy = (e) => {
|
||||||
|
// debugger
|
||||||
const native = window.getSelection()
|
const native = window.getSelection()
|
||||||
if (!native.rangeCount) return
|
if (!native.rangeCount) return
|
||||||
|
|
||||||
@@ -244,7 +245,12 @@ class Content extends React.Component {
|
|||||||
|
|
||||||
// Set the `isCopying` flag, so our `onSelect` logic doesn't fire.
|
// Set the `isCopying` flag, so our `onSelect` logic doesn't fire.
|
||||||
this.tmp.isCopying = true
|
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.
|
// Revert to the previous selection right after copying.
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
@@ -302,7 +308,7 @@ class Content extends React.Component {
|
|||||||
const data = e.clipboardData
|
const data = e.clipboardData
|
||||||
const paste = {}
|
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)
|
const types = Array.from(data.types)
|
||||||
|
|
||||||
// Handle files.
|
// Handle files.
|
||||||
@@ -410,8 +416,9 @@ class Content extends React.Component {
|
|||||||
whiteSpace: 'pre-wrap',
|
whiteSpace: 'pre-wrap',
|
||||||
// Allow words to break if they are too long.
|
// Allow words to break if they are too long.
|
||||||
wordWrap: 'break-word',
|
wordWrap: 'break-word',
|
||||||
// COMPAT: Prevent iOS from showing the BIU formatting menu, which causes
|
// COMPAT: In iOS, a formatting menu with bold, italic and underline
|
||||||
// the internal state to get out of sync in weird ways.
|
// 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' }),
|
...(readOnly ? {} : { WebkitUserModify: 'read-write-plaintext-only' }),
|
||||||
// Allow for passed-in styles to override anything.
|
// Allow for passed-in styles to override anything.
|
||||||
...this.props.style,
|
...this.props.style,
|
||||||
|
Reference in New Issue
Block a user