mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-24 09:13:24 +01:00
fix logic to determine isNative inside inline nodes
This commit is contained in:
parent
5b1793b116
commit
7e333a067c
@ -60,6 +60,7 @@ class Links extends React.Component {
|
||||
|
||||
onChange = (state) => {
|
||||
this.setState({ state })
|
||||
console.log(state.document.toJS())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,46 +217,6 @@ class State extends new Record(DEFAULTS) {
|
||||
return this.selection.focusOffset
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current start text node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get startText() {
|
||||
return this.document.getDescendant(this.selection.startKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current end node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get endText() {
|
||||
return this.document.getDescendant(this.selection.endKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current anchor node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get anchorText() {
|
||||
return this.document.getDescendant(this.selection.anchorKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current focus node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get focusText() {
|
||||
return this.document.getDescendant(this.selection.focusKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current start text node's closest block parent.
|
||||
*
|
||||
@ -297,6 +257,86 @@ class State extends new Record(DEFAULTS) {
|
||||
return this.document.getClosestBlock(this.selection.focusKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current start text node's closest inline parent.
|
||||
*
|
||||
* @return {Inline} inline
|
||||
*/
|
||||
|
||||
get startInline() {
|
||||
return this.document.getClosestInline(this.selection.startKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current end text node's closest inline parent.
|
||||
*
|
||||
* @return {Inline} inline
|
||||
*/
|
||||
|
||||
get endInline() {
|
||||
return this.document.getClosestInline(this.selection.endKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current anchor text node's closest inline parent.
|
||||
*
|
||||
* @return {Inline} inline
|
||||
*/
|
||||
|
||||
get anchorInline() {
|
||||
return this.document.getClosestInline(this.selection.anchorKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current focus text node's closest inline parent.
|
||||
*
|
||||
* @return {Inline} inline
|
||||
*/
|
||||
|
||||
get focusInline() {
|
||||
return this.document.getClosestInline(this.selection.focusKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current start text node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get startText() {
|
||||
return this.document.getDescendant(this.selection.startKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current end node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get endText() {
|
||||
return this.document.getDescendant(this.selection.endKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current anchor node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get anchorText() {
|
||||
return this.document.getDescendant(this.selection.anchorKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current focus node.
|
||||
*
|
||||
* @return {Text} text
|
||||
*/
|
||||
|
||||
get focusText() {
|
||||
return this.document.getDescendant(this.selection.focusKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the characters in the current selection.
|
||||
*
|
||||
|
@ -58,7 +58,7 @@ function Plugin(options = {}) {
|
||||
*/
|
||||
|
||||
function onBeforeInput(e, data, state, editor) {
|
||||
const { document, startKey, startOffset, startText } = state
|
||||
const { document, startKey, startOffset, startInline, startText } = state
|
||||
|
||||
// Determine what the characters would be if natively inserted.
|
||||
const schema = editor.getSchema()
|
||||
@ -85,13 +85,16 @@ function Plugin(options = {}) {
|
||||
const nextChars = nextText.getDecorations(decorators)
|
||||
|
||||
// We do not have to re-render if the current selection is collapsed, the
|
||||
// current node is not empty, there are no marks on the cursor, and the
|
||||
// natively inserted characters would be the same as the non-native.
|
||||
// current node is not empty, there are no marks on the cursor, the cursor
|
||||
// is not at the edge of an inline node, and the natively inserted
|
||||
// characters would be the same as the non-native.
|
||||
const isNative = (
|
||||
state.isCollapsed &&
|
||||
state.startText.text != '' &&
|
||||
state.selection.marks == null &&
|
||||
chars.equals(nextChars)
|
||||
(state.isCollapsed) &&
|
||||
(state.startText.text != '') &&
|
||||
(state.selection.marks == null) &&
|
||||
(!startInline || !state.selection.isAtStartOf(startInline)) &&
|
||||
(!startInline || !state.selection.isAtEndOf(startInline)) &&
|
||||
(chars.equals(nextChars))
|
||||
)
|
||||
|
||||
// Add the `isNative` flag directly, so we don't have to re-transform.
|
||||
|
Loading…
x
Reference in New Issue
Block a user