1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 15:02:51 +02:00

Wrap scrolling logic in setTimeout (#847)

The native selection will be updated after componentDidMount or componentDidUpdate.
Use setTimeout to queue scrolling to the last when the native selection has been updated to the correct value.
This commit is contained in:
pa-nam
2017-05-31 03:13:21 +07:00
committed by Ian Storm Taylor
parent 53542cb55b
commit 890d790d42

View File

@@ -180,12 +180,16 @@ class Node extends React.Component {
if (selection.isBlurred) return
if (!selection.hasEndIn(node)) return
const el = ReactDOM.findDOMNode(this)
const window = getWindow(el)
const native = window.getSelection()
scrollToSelection(native)
// The native selection will be updated after componentDidMount or componentDidUpdate.
// Use setTimeout to queue scrolling to the last when the native selection has been updated to the correct value.
setTimeout(() => {
const el = ReactDOM.findDOMNode(this)
const window = getWindow(el)
const native = window.getSelection()
scrollToSelection(native)
this.debug('updateScroll', el)
this.debug('updateScroll', el)
})
}
/**