mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
Don't normalize with schema when moving selection
This commit is contained in:
@@ -32,7 +32,6 @@ function Plugin(options = {}) {
|
|||||||
placeholderClassName,
|
placeholderClassName,
|
||||||
placeholderStyle,
|
placeholderStyle,
|
||||||
} = options
|
} = options
|
||||||
let prevState
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On before change, enforce the editor's schema.
|
* On before change, enforce the editor's schema.
|
||||||
@@ -43,8 +42,15 @@ function Plugin(options = {}) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function onBeforeChange(state, editor) {
|
function onBeforeChange(state, editor) {
|
||||||
|
// Don't normalize with plugins schema when typing text in native mode
|
||||||
if (state.isNative) return state
|
if (state.isNative) return state
|
||||||
|
|
||||||
const schema = editor.getSchema()
|
const schema = editor.getSchema()
|
||||||
|
const { state: prevState } = editor.state
|
||||||
|
|
||||||
|
// Since schema can only normalize the document, we avoid creating
|
||||||
|
// a transform and normalize the selection if the document is the same
|
||||||
|
if (prevState && state.document == prevState.document) return state
|
||||||
|
|
||||||
console.time('onBeforeChange');
|
console.time('onBeforeChange');
|
||||||
const newState = state.transform()
|
const newState = state.transform()
|
||||||
@@ -52,8 +58,7 @@ function Plugin(options = {}) {
|
|||||||
.apply({ save: false })
|
.apply({ save: false })
|
||||||
console.timeEnd('onBeforeChange');
|
console.timeEnd('onBeforeChange');
|
||||||
|
|
||||||
prevState = newState
|
return newState
|
||||||
return newState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user