mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 12:41:44 +02:00
Prevent crash when handling composition of 2+ keypresses when selection is not collapsed (#2218)
https://github.com/ianstormtaylor/slate/issues/1879 When composition starts and the current selection is not collapsed, the second composition key-down would drop the text wrapping <spans> which resulted on crash in content.updateSelection after composition ends (because it cannot find <span> nodes in DOM). This is a workaround that erases selection as soon as composition starts and preventing <spans> to be dropped.
This commit is contained in:
committed by
Ian Storm Taylor
parent
abc75bb45e
commit
d5834bb5b0
@@ -167,6 +167,20 @@ function BeforePlugin() {
|
|||||||
editor.setState({ isComposing: true })
|
editor.setState({ isComposing: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { value } = change
|
||||||
|
const { selection } = value
|
||||||
|
|
||||||
|
if (!selection.isCollapsed) {
|
||||||
|
// https://github.com/ianstormtaylor/slate/issues/1879
|
||||||
|
// When composition starts and the current selection is not collapsed, the
|
||||||
|
// second composition key-down would drop the text wrapping <spans> which
|
||||||
|
// resulted on crash in content.updateSelection after composition ends
|
||||||
|
// (because it cannot find <span> nodes in DOM). This is a workaround that
|
||||||
|
// erases selection as soon as composition starts and preventing <spans>
|
||||||
|
// to be dropped.
|
||||||
|
change.delete()
|
||||||
|
}
|
||||||
|
|
||||||
debug('onCompositionStart', { event })
|
debug('onCompositionStart', { event })
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user