How to insert multi images in a one-time


#1

I have a array of image’s url, I want to insert them to editor in one-time. But now i read the example, the replaceSelectionWith function only accept one node

 run: (state, dispatch) => {
    ... // get url code
    img = schema.nodes.image.createAndFill({ src: url })
    dispatch(state.tr.replaceSelectionWith(img))
}

How can i use this function or other way to insert multi images


#2

You can’t, but you could wrap them in a slice with new Slice(Fragment.from(imageNodes), 0, 0) and pass that to replaceSelection. Or, alternatively, call replaceSelectionWith once for each node.


#3

@marijn Thank you. Your suggestion worked great.

By the way, may i ask for another question that recently I can’t in perfect way to realize it.

It’s alignment.

I have read that topic Implementing alignment. And I use class such as "align-right" to control the alignment like the questioner. But it didn’t seem to work, I don’t know how to wrap the nodes because it not perfect combination with the order_lis and bullet_list. Maybe your suggestion will make me suddenly see the light.

thx again!