1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-16 12:14:14 +02:00

Don't clone nodes when applying a split_node operation (#4004)

This commit is contained in:
Andrew Herron
2021-01-31 11:13:59 +10:00
committed by GitHub
parent dd351c9d0a
commit 4e667b9109
7 changed files with 182 additions and 2 deletions

View File

@@ -248,7 +248,6 @@ export const GeneralTransforms: GeneralTransforms = {
const after = node.text.slice(position)
node.text = before
newNode = {
...node,
...(properties as Partial<Text>),
text: after,
}
@@ -258,7 +257,6 @@ export const GeneralTransforms: GeneralTransforms = {
node.children = before
newNode = {
...node,
...(properties as Partial<Element>),
children: after,
}

View File

@@ -0,0 +1,30 @@
/** @jsx jsx */
import { jsx } from '../..'
export const input = (
<editor>
<element data>
before text
<inline>hyperlink</inline>
after text
</element>
</editor>
)
export const operations = [
{
type: 'split_node',
path: [0],
position: 1,
properties: {},
},
]
export const output = (
<editor>
<element data>before text</element>
<element>
<text />
<inline>hyperlink</inline>
after text
</element>
</editor>
)

View File

@@ -0,0 +1,32 @@
/** @jsx jsx */
import { jsx } from '../..'
export const input = (
<editor>
<element data>
before text
<inline>hyperlink</inline>
after text
</element>
</editor>
)
export const operations = [
{
type: 'split_node',
path: [0],
position: 1,
properties: {
data: true,
},
},
]
export const output = (
<editor>
<element data>before text</element>
<element data>
<text />
<inline>hyperlink</inline>
after text
</element>
</editor>
)

View File

@@ -0,0 +1,26 @@
/** @jsx jsx */
import { jsx } from '../..'
export const input = (
<editor>
<element>
<text bold>some text</text>
</element>
</editor>
)
export const operations = [
{
type: 'split_node',
path: [0, 0],
position: 5,
properties: {},
},
]
export const output = (
<editor>
<element>
<text bold>some </text>
<text>text</text>
</element>
</editor>
)

View File

@@ -0,0 +1,36 @@
/** @jsx jsx */
import { jsx } from '../..'
export const input = (
<editor>
<element>
<text bold>some text</text>
</element>
</editor>
)
export const operations = [
{
type: 'split_node',
path: [0, 0],
position: 5,
properties: {
bold: true,
},
},
{
type: 'split_node',
path: [0],
position: 1,
properties: {},
},
]
export const output = (
<editor>
<element>
<text bold>some </text>
</element>
<element>
<text bold>text</text>
</element>
</editor>
)

View File

@@ -0,0 +1,32 @@
/** @jsx jsx */
import { Transforms } from 'slate'
import { jsx } from '../../..'
export const run = editor => {
Transforms.splitNodes(editor, { at: [0, 2] })
}
export const input = (
<editor>
<block data>
<text />
<inline>one</inline>
<text />
<inline>two</inline>
<text />
</block>
</editor>
)
export const output = (
<editor>
<block data>
<text />
<inline>one</inline>
<text />
</block>
<block data>
<text />
<inline>two</inline>
<text />
</block>
</editor>
)

View File

@@ -0,0 +1,26 @@
/** @jsx jsx */
import { Editor, Transforms } from 'slate'
import { jsx } from '../../..'
export const run = editor => {
Transforms.splitNodes(editor, {
at: { path: [0, 0], offset: 2 },
})
}
export const input = (
<editor>
<block>
<text bold>word</text>
</block>
</editor>
)
export const output = (
<editor>
<block>
<text bold>wo</text>
</block>
<block>
<text bold>rd</text>
</block>
</editor>
)