mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 14:11:35 +02:00
support insertFragment with text/inline + block mixed fragments. (#5018)
This commit is contained in:
5
.changeset/pretty-plums-grow.md
Normal file
5
.changeset/pretty-plums-grow.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Fix for insertFragment text/inline + block mixed fragments.
|
@@ -397,7 +397,7 @@ export const TextTransforms: TextTransforms = {
|
||||
|
||||
const middleRef = Editor.pathRef(
|
||||
editor,
|
||||
isBlockEnd ? Path.next(blockPath) : blockPath
|
||||
isBlockEnd && !ends.length ? Path.next(blockPath) : blockPath
|
||||
)
|
||||
|
||||
const endRef = Editor.pathRef(
|
||||
@@ -405,8 +405,6 @@ export const TextTransforms: TextTransforms = {
|
||||
isInlineEnd ? Path.next(inlinePath) : inlinePath
|
||||
)
|
||||
|
||||
const blockPathRef = Editor.pathRef(editor, blockPath)
|
||||
|
||||
Transforms.splitNodes(editor, {
|
||||
at,
|
||||
match: n =>
|
||||
@@ -414,6 +412,10 @@ export const TextTransforms: TextTransforms = {
|
||||
? Editor.isBlock(editor, n)
|
||||
: Text.isText(n) || Editor.isInline(editor, n),
|
||||
mode: hasBlocks ? 'lowest' : 'highest',
|
||||
always:
|
||||
hasBlocks &&
|
||||
(!isBlockStart || starts.length > 0) &&
|
||||
(!isBlockEnd || ends.length > 0),
|
||||
voids,
|
||||
})
|
||||
|
||||
@@ -431,8 +433,8 @@ export const TextTransforms: TextTransforms = {
|
||||
voids,
|
||||
})
|
||||
|
||||
if (isBlockEmpty && middles.length) {
|
||||
Transforms.delete(editor, { at: blockPathRef.unref()!, voids })
|
||||
if (isBlockEmpty && !starts.length && middles.length && !ends.length) {
|
||||
Transforms.delete(editor, { at: blockPath, voids })
|
||||
}
|
||||
|
||||
Transforms.insertNodes(editor, middles, {
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<text>one</text>
|
||||
<block>two</block>
|
||||
<text>three</text>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
<block>one</block>
|
||||
<block>two</block>
|
||||
<block>
|
||||
three
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,33 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<block>two</block>
|
||||
<text>three</text>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
<block>two</block>
|
||||
<block>
|
||||
<text>
|
||||
three
|
||||
<cursor />
|
||||
</text>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,31 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<text>one</text>
|
||||
<block>two</block>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
<block>one</block>
|
||||
<block>
|
||||
two
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,32 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<text>one</text>
|
||||
<block>two</block>
|
||||
<text>three</text>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
word
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>wordone</block>
|
||||
<block>two</block>
|
||||
<block>
|
||||
three
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,30 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<text>one</text>
|
||||
<block>two</block>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
word
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>wordone</block>
|
||||
<block>
|
||||
two
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,34 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<text>one</text>
|
||||
<block>two</block>
|
||||
<text>three</text>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
wo
|
||||
<cursor />
|
||||
rd
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>woone</block>
|
||||
<block>two</block>
|
||||
<block>
|
||||
three
|
||||
<cursor />
|
||||
rd
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,33 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<text>one</text>
|
||||
<block>two</block>
|
||||
<text>three</text>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<cursor />
|
||||
word
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>one</block>
|
||||
<block>two</block>
|
||||
<block>
|
||||
three
|
||||
<cursor />
|
||||
word
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,31 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.insertFragment(
|
||||
editor,
|
||||
<fragment>
|
||||
<block>one</block>
|
||||
<text>two</text>
|
||||
</fragment>
|
||||
)
|
||||
}
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<cursor />
|
||||
word
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>one</block>
|
||||
<block>
|
||||
two
|
||||
<cursor />
|
||||
word
|
||||
</block>
|
||||
</editor>
|
||||
)
|
Reference in New Issue
Block a user