mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 10:51:44 +02:00
fix core onBeforeInput logic to re-render only when necessary
This commit is contained in:
@@ -110,10 +110,9 @@ function Plugin(options = {}) {
|
|||||||
/**
|
/**
|
||||||
* The core `onBeforeInput` handler.
|
* The core `onBeforeInput` handler.
|
||||||
*
|
*
|
||||||
* If the current selection is expanded, we have to re-render.
|
|
||||||
*
|
*
|
||||||
* If the next state resolves a new list of decorations for any of its text
|
*
|
||||||
* nodes, we have to re-render.
|
*
|
||||||
*
|
*
|
||||||
* Otherwise, we can allow the default, native text insertion, avoiding a
|
* Otherwise, we can allow the default, native text insertion, avoiding a
|
||||||
* re-render for improved performance.
|
* re-render for improved performance.
|
||||||
@@ -128,17 +127,32 @@ function Plugin(options = {}) {
|
|||||||
const transform = state.transform().insertText(e.data)
|
const transform = state.transform().insertText(e.data)
|
||||||
const synthetic = transform.apply()
|
const synthetic = transform.apply()
|
||||||
const resolved = editor.resolveState(synthetic)
|
const resolved = editor.resolveState(synthetic)
|
||||||
|
let isNative = true
|
||||||
|
|
||||||
const isSynthenic = (
|
// If the current selection is expanded, we have to re-render.
|
||||||
state.isExpanded ||
|
if (state.isExpanded) {
|
||||||
!resolved.equals(synthetic)
|
isNative = false
|
||||||
)
|
}
|
||||||
|
|
||||||
if (isSynthenic) e.preventDefault()
|
// If the current node was empty, we have to re-render so that any empty
|
||||||
|
// placeholder logic will be updated.
|
||||||
|
if (state.startText.text == '') {
|
||||||
|
isNative = false
|
||||||
|
}
|
||||||
|
|
||||||
return isSynthenic
|
// If the next state resolves a new list of decorations for any of its
|
||||||
? synthetic
|
// text nodes, we have to re-render.
|
||||||
: transform.apply({ isNative: true })
|
else if (!resolved.equals(synthetic)) {
|
||||||
|
isNative = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the state with the proper `isNative`.
|
||||||
|
state = isNative
|
||||||
|
? transform.apply({ isNative })
|
||||||
|
: synthetic
|
||||||
|
|
||||||
|
if (!isNative) e.preventDefault()
|
||||||
|
return state
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user