mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-24 09:13:24 +01:00
Save some remove_text calls if the text is zero length (#4193)
* Save some remove_text calls if the text is zero length. * Remove unnecessary !text check - text is always string, and add similar check to 'insert_text' as well * Create giant-adults-matter.md Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
This commit is contained in:
parent
2dad21d1d7
commit
fd70dc0b2c
5
.changeset/giant-adults-matter.md
Normal file
5
.changeset/giant-adults-matter.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
slate: patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed insert and remove text operations to no-op without any text.
|
@ -44,6 +44,7 @@ export const GeneralTransforms: GeneralTransforms = {
|
|||||||
|
|
||||||
case 'insert_text': {
|
case 'insert_text': {
|
||||||
const { path, offset, text } = op
|
const { path, offset, text } = op
|
||||||
|
if (text.length === 0) break
|
||||||
const node = Node.leaf(editor, path)
|
const node = Node.leaf(editor, path)
|
||||||
const before = node.text.slice(0, offset)
|
const before = node.text.slice(0, offset)
|
||||||
const after = node.text.slice(offset)
|
const after = node.text.slice(offset)
|
||||||
@ -167,6 +168,7 @@ export const GeneralTransforms: GeneralTransforms = {
|
|||||||
|
|
||||||
case 'remove_text': {
|
case 'remove_text': {
|
||||||
const { path, offset, text } = op
|
const { path, offset, text } = op
|
||||||
|
if (text.length === 0) break
|
||||||
const node = Node.leaf(editor, path)
|
const node = Node.leaf(editor, path)
|
||||||
const before = node.text.slice(0, offset)
|
const before = node.text.slice(0, offset)
|
||||||
const after = node.text.slice(offset + text.length)
|
const after = node.text.slice(offset + text.length)
|
||||||
|
@ -182,7 +182,8 @@ export const TextTransforms: TextTransforms = {
|
|||||||
const { path } = point
|
const { path } = point
|
||||||
const { offset } = start
|
const { offset } = start
|
||||||
const text = node.text.slice(offset)
|
const text = node.text.slice(offset)
|
||||||
editor.apply({ type: 'remove_text', path, offset, text })
|
if (text.length > 0)
|
||||||
|
editor.apply({ type: 'remove_text', path, offset, text })
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const pathRef of pathRefs) {
|
for (const pathRef of pathRefs) {
|
||||||
@ -196,7 +197,8 @@ export const TextTransforms: TextTransforms = {
|
|||||||
const { path } = point
|
const { path } = point
|
||||||
const offset = isSingleText ? start.offset : 0
|
const offset = isSingleText ? start.offset : 0
|
||||||
const text = node.text.slice(offset, end.offset)
|
const text = node.text.slice(offset, end.offset)
|
||||||
editor.apply({ type: 'remove_text', path, offset, text })
|
if (text.length > 0)
|
||||||
|
editor.apply({ type: 'remove_text', path, offset, text })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -483,7 +485,8 @@ export const TextTransforms: TextTransforms = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { path, offset } = at
|
const { path, offset } = at
|
||||||
editor.apply({ type: 'insert_text', path, offset, text })
|
if (text.length > 0)
|
||||||
|
editor.apply({ type: 'insert_text', path, offset, text })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user