mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 16:20:49 +02:00
fix nested unwrapping with splitting
This commit is contained in:
@@ -681,13 +681,8 @@ export const NodeTransforms = {
|
||||
}
|
||||
) {
|
||||
Editor.withoutNormalizing(editor, () => {
|
||||
const {
|
||||
at = editor.selection,
|
||||
mode = 'highest',
|
||||
split = false,
|
||||
voids = false,
|
||||
} = options
|
||||
let { match } = options
|
||||
const { mode = 'highest', split = false, voids = false } = options
|
||||
let { at = editor.selection, match } = options
|
||||
|
||||
if (!at) {
|
||||
return
|
||||
@@ -697,6 +692,11 @@ export const NodeTransforms = {
|
||||
match = Path.isPath(at) ? matchPath(editor, at) : 'block'
|
||||
}
|
||||
|
||||
if (Path.isPath(at)) {
|
||||
at = Editor.range(editor, at)
|
||||
}
|
||||
|
||||
const rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null
|
||||
const matches = Editor.nodes(editor, { at, match, mode, voids })
|
||||
const pathRefs = Array.from(matches, ([, p]) => Editor.pathRef(editor, p))
|
||||
|
||||
@@ -705,8 +705,8 @@ export const NodeTransforms = {
|
||||
const [node] = Editor.node(editor, path)
|
||||
let range = Editor.range(editor, path)
|
||||
|
||||
if (split && Range.isRange(at)) {
|
||||
range = Range.intersection(at, range)!
|
||||
if (split && rangeRef) {
|
||||
range = Range.intersection(rangeRef.current!, range)!
|
||||
}
|
||||
|
||||
Editor.liftNodes(editor, {
|
||||
@@ -715,6 +715,10 @@ export const NodeTransforms = {
|
||||
voids,
|
||||
})
|
||||
}
|
||||
|
||||
if (rangeRef) {
|
||||
rangeRef.unref()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
@@ -0,0 +1,30 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block a>
|
||||
<block a>
|
||||
<block>
|
||||
<cursor />
|
||||
word
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<cursor />
|
||||
word
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,40 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block a>
|
||||
<block a>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,38 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block a>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,48 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all', split: true })
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block a>
|
||||
<block a>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>three</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
<block a>
|
||||
<block a>
|
||||
<block>three</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,46 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block a>
|
||||
<block a>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>three</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
<block a>
|
||||
<block>three</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,44 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const run = editor => {
|
||||
Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block a>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
</block>
|
||||
<block a>
|
||||
<block>three</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<anchor />
|
||||
one
|
||||
</block>
|
||||
<block>
|
||||
two
|
||||
<focus />
|
||||
</block>
|
||||
<block a>
|
||||
<block>three</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
Reference in New Issue
Block a user