mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 04:04:06 +02:00
remove need for selection to be natively rendered
This commit is contained in:
@@ -184,7 +184,7 @@ If no other plugin handles this event, it will be handled by the [Core plugin](.
|
||||
|
||||
This handler is called whenever the native selection changes.
|
||||
|
||||
The `data` object contains a State [`Selection`](../models/selection.md) object representing the new selection, and an `isNative` boolean connoting whether the editor needs to be re-rendered for the selection to be updated or correctly placed or not.
|
||||
The `data` object contains a State [`Selection`](../models/selection.md) object representing the new selection.
|
||||
|
||||
If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
||||
|
||||
|
@@ -599,9 +599,10 @@ class Content extends React.Component {
|
||||
const anchor = this.getPoint(anchorNode, anchorOffset)
|
||||
const focus = this.getPoint(focusNode, focusOffset)
|
||||
|
||||
// COMPAT: In Firefox, and potentially other browsers, sometimes a select
|
||||
// event will fire that resolves to the same location as the current
|
||||
// selection, so we can ignore it.
|
||||
// There are valid situations where a select event will fire when we're
|
||||
// already at that position (for example when entering a character), since
|
||||
// our `insertText` transform already updates the selection. In those
|
||||
// cases we can safely ignore the event.
|
||||
if (
|
||||
anchor.key == selection.anchorKey &&
|
||||
anchor.offset == selection.anchorOffset &&
|
||||
@@ -611,23 +612,18 @@ class Content extends React.Component {
|
||||
return
|
||||
}
|
||||
|
||||
// If the native selection is inside text nodes, we can trust the native
|
||||
// state and not need to re-render.
|
||||
data.isNative = (
|
||||
anchorNode.nodeType == 3 &&
|
||||
focusNode.nodeType == 3
|
||||
)
|
||||
|
||||
selection = selection.merge({
|
||||
const properties = {
|
||||
anchorKey: anchor.key,
|
||||
anchorOffset: anchor.offset,
|
||||
focusKey: focus.key,
|
||||
focusOffset: focus.offset,
|
||||
isFocused: true,
|
||||
isBackward: null
|
||||
})
|
||||
}
|
||||
|
||||
data.selection = selection.normalize(document)
|
||||
data.selection = selection
|
||||
.merge(properties)
|
||||
.normalize(document)
|
||||
}
|
||||
|
||||
this.props.onSelect(e, data)
|
||||
|
@@ -538,12 +538,12 @@ function Plugin(options = {}) {
|
||||
*/
|
||||
|
||||
function onSelect(e, data, state) {
|
||||
const { selection, isNative } = data
|
||||
const { selection } = data
|
||||
return state
|
||||
.transform()
|
||||
.moveTo(selection)
|
||||
.focus()
|
||||
.apply({ isNative })
|
||||
.apply()
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user