mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-09 00:36:41 +02:00
make create methods more helpful
This commit is contained in:
@@ -695,13 +695,11 @@ const Node = {
|
|||||||
// character if one exists.
|
// character if one exists.
|
||||||
const prev = characters.get(startOffset - 1)
|
const prev = characters.get(startOffset - 1)
|
||||||
const marks = prev ? prev.marks : null
|
const marks = prev ? prev.marks : null
|
||||||
const newChars = Character.createList(
|
const newChars = Character.createList(text.split('').map((char) => {
|
||||||
text.split('').map((char) => {
|
|
||||||
const obj = { text: char }
|
const obj = { text: char }
|
||||||
if (marks) obj.marks = marks
|
if (marks) obj.marks = marks
|
||||||
return Character.create(obj)
|
return obj
|
||||||
})
|
}))
|
||||||
)
|
|
||||||
|
|
||||||
// Splice in the new characters.
|
// Splice in the new characters.
|
||||||
characters = characters.slice(0, startOffset)
|
characters = characters.slice(0, startOffset)
|
||||||
@@ -939,7 +937,7 @@ const Node = {
|
|||||||
const secondBlock = Block.create({
|
const secondBlock = Block.create({
|
||||||
type: firstBlock.type,
|
type: firstBlock.type,
|
||||||
data: firstBlock.data,
|
data: firstBlock.data,
|
||||||
nodes: Block.createMap([secondChild])
|
nodes: [secondChild]
|
||||||
})
|
})
|
||||||
|
|
||||||
// Replace the block in the parent with the two new blocks.
|
// Replace the block in the parent with the two new blocks.
|
||||||
@@ -981,12 +979,9 @@ const Node = {
|
|||||||
|
|
||||||
// While the parent is an inline parent, split the inline nodes.
|
// While the parent is an inline parent, split the inline nodes.
|
||||||
while (parent = node.getClosestInline(firstChild)) {
|
while (parent = node.getClosestInline(firstChild)) {
|
||||||
debugger
|
firstChild = parent.merge({ nodes: [firstChild] })
|
||||||
const firstNodes = Inline.createMap([firstChild])
|
|
||||||
const secondNodes = Inline.createMap([secondChild])
|
|
||||||
firstChild = parent.merge({ nodes: firstNodes })
|
|
||||||
secondChild = Inline.create({
|
secondChild = Inline.create({
|
||||||
nodes: secondNodes,
|
nodes: [secondChild],
|
||||||
type: parent.type,
|
type: parent.type,
|
||||||
data: parent.data
|
data: parent.data
|
||||||
})
|
})
|
||||||
@@ -1294,10 +1289,8 @@ const Node = {
|
|||||||
|
|
||||||
// Iterate each of the child nodes, wrapping them.
|
// Iterate each of the child nodes, wrapping them.
|
||||||
children.forEach((child) => {
|
children.forEach((child) => {
|
||||||
const wrappedNodes = Inline.createMap([child])
|
|
||||||
|
|
||||||
const obj = {}
|
const obj = {}
|
||||||
obj.nodes = wrappedNodes
|
obj.nodes = [child]
|
||||||
obj.type = type
|
obj.type = type
|
||||||
if (data) obj.data = data
|
if (data) obj.data = data
|
||||||
const wrapper = Inline.create(obj)
|
const wrapper = Inline.create(obj)
|
||||||
|
Reference in New Issue
Block a user