1
0
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:
Bjørn Stabell 2021-04-13 08:14:30 -07:00 committed by GitHub
parent 2dad21d1d7
commit fd70dc0b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
slate: patch
---
Fixed insert and remove text operations to no-op without any text.

View File

@ -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)

View File

@ -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 })
}) })
}, },
} }