mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-15 11:44:05 +02:00
add withMatch
option to Editor.mergeNodes
This commit is contained in:
@@ -184,12 +184,13 @@ export const NodeTransforms = {
|
|||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: NodeMatch
|
match?: NodeMatch
|
||||||
|
withMatch?: NodeMatch
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
) {
|
) {
|
||||||
Editor.withoutNormalizing(editor, () => {
|
Editor.withoutNormalizing(editor, () => {
|
||||||
let { match, at = editor.selection } = options
|
let { match, withMatch, at = editor.selection } = options
|
||||||
const { hanging = false, voids = false } = options
|
const { hanging = false, voids = false } = options
|
||||||
|
|
||||||
if (!at) {
|
if (!at) {
|
||||||
@@ -225,18 +226,23 @@ export const NodeTransforms = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let prevMatch: NodeMatch = 'block'
|
|
||||||
const [node, path] = current
|
const [node, path] = current
|
||||||
|
|
||||||
if (Editor.isEditor(node)) {
|
if (Editor.isEditor(node)) {
|
||||||
return
|
return
|
||||||
} else if (Text.isText(node)) {
|
|
||||||
prevMatch = 'text'
|
|
||||||
} else if (editor.isInline(node)) {
|
|
||||||
prevMatch = 'inline'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const prev = Editor.previous(editor, at, prevMatch, { voids })
|
if (withMatch == null) {
|
||||||
|
if (Text.isText(node)) {
|
||||||
|
withMatch = 'text'
|
||||||
|
} else if (editor.isInline(node)) {
|
||||||
|
withMatch = 'inline'
|
||||||
|
} else {
|
||||||
|
withMatch = 'block'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const prev = Editor.previous(editor, at, withMatch, { voids })
|
||||||
|
|
||||||
if (!prev) {
|
if (!prev) {
|
||||||
return
|
return
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
<block>one</block>
|
||||||
|
</block>
|
||||||
|
<block>
|
||||||
|
<block>two</block>
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const run = editor => {
|
||||||
|
Editor.mergeNodes(editor, {
|
||||||
|
at: [1],
|
||||||
|
withMatch: ([, p]) => p.length === 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
<block>one</block>
|
||||||
|
<block>two</block>
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
Reference in New Issue
Block a user