mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 20:51:20 +02:00
Don't clone nodes when applying a split_node operation (#4004)
This commit is contained in:
@@ -248,7 +248,6 @@ export const GeneralTransforms: GeneralTransforms = {
|
|||||||
const after = node.text.slice(position)
|
const after = node.text.slice(position)
|
||||||
node.text = before
|
node.text = before
|
||||||
newNode = {
|
newNode = {
|
||||||
...node,
|
|
||||||
...(properties as Partial<Text>),
|
...(properties as Partial<Text>),
|
||||||
text: after,
|
text: after,
|
||||||
}
|
}
|
||||||
@@ -258,7 +257,6 @@ export const GeneralTransforms: GeneralTransforms = {
|
|||||||
node.children = before
|
node.children = before
|
||||||
|
|
||||||
newNode = {
|
newNode = {
|
||||||
...node,
|
|
||||||
...(properties as Partial<Element>),
|
...(properties as Partial<Element>),
|
||||||
children: after,
|
children: after,
|
||||||
}
|
}
|
||||||
|
@@ -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>
|
||||||
|
)
|
32
packages/slate/test/operations/split_node/element.tsx
Normal file
32
packages/slate/test/operations/split_node/element.tsx
Normal 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>
|
||||||
|
)
|
@@ -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>
|
||||||
|
)
|
36
packages/slate/test/operations/split_node/text.tsx
Normal file
36
packages/slate/test/operations/split_node/text.tsx
Normal 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>
|
||||||
|
)
|
@@ -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>
|
||||||
|
)
|
@@ -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>
|
||||||
|
)
|
Reference in New Issue
Block a user