diff --git a/webapp/src/components/addContentMenuItem.tsx b/webapp/src/components/addContentMenuItem.tsx index aeba34c08..434715300 100644 --- a/webapp/src/components/addContentMenuItem.tsx +++ b/webapp/src/components/addContentMenuItem.tsx @@ -41,11 +41,11 @@ const AddContentMenuItem = React.memo((props:Props): JSX.Element => { newBlock.parentId = card.id newBlock.rootId = card.rootId - contentOrder.splice(index, 0, newBlock.id) const typeName = handler.getDisplayText(intl) const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName}) mutator.performAsUndoGroup(async () => { - await mutator.insertBlock(newBlock, description) + const insertedBlock = await mutator.insertBlock(newBlock, description) + contentOrder.splice(index, 0, insertedBlock.id) await mutator.changeCardContentOrder(card.id, card.fields.contentOrder, contentOrder, description) }) }} diff --git a/webapp/src/components/cardDetail/cardDetailContents.tsx b/webapp/src/components/cardDetail/cardDetailContents.tsx index 15d2ba4b9..3b1eb6467 100644 --- a/webapp/src/components/cardDetail/cardDetailContents.tsx +++ b/webapp/src/components/cardDetail/cardDetailContents.tsx @@ -29,11 +29,11 @@ function addTextBlock(card: Card, intl: IntlShape, text: string): void { block.rootId = card.rootId block.title = text - const contentOrder = card.fields.contentOrder.slice() - contentOrder.push(block.id) mutator.performAsUndoGroup(async () => { const description = intl.formatMessage({id: 'CardDetail.addCardText', defaultMessage: 'add card text'}) - await mutator.insertBlock(block, description) + const insertedBlock = await mutator.insertBlock(block, description) + const contentOrder = card.fields.contentOrder.slice() + contentOrder.push(insertedBlock.id) await mutator.changeCardContentOrder(card.id, card.fields.contentOrder, contentOrder, description) }) } diff --git a/webapp/src/components/cardDetail/cardDetailContext.tsx b/webapp/src/components/cardDetail/cardDetailContext.tsx index 2b25bf05d..ee6c2ffe3 100644 --- a/webapp/src/components/cardDetail/cardDetailContext.tsx +++ b/webapp/src/components/cardDetail/cardDetailContext.tsx @@ -50,16 +50,16 @@ export const CardDetailProvider = (props: CardDetailProps): ReactElement => { const block = await handler.createBlock(card.rootId) block.parentId = card.id block.rootId = card.rootId - const contentOrder = card.fields.contentOrder.slice() - contentOrder.splice(index, 0, block.id) - setLastAddedBlock({ - id: block.id, - autoAdded: auto, - }) const typeName = handler.getDisplayText(intl) const description = intl.formatMessage({id: 'ContentBlock.addElement', defaultMessage: 'add {type}'}, {type: typeName}) await mutator.performAsUndoGroup(async () => { - await mutator.insertBlock(block, description) + const insertedBlock = await mutator.insertBlock(block, description) + const contentOrder = card.fields.contentOrder.slice() + contentOrder.splice(index, 0, insertedBlock.id) + setLastAddedBlock({ + id: insertedBlock.id, + autoAdded: auto, + }) await mutator.changeCardContentOrder(card.id, card.fields.contentOrder, contentOrder, description) }) }, diff --git a/webapp/src/components/cardDetail/imagePaste.tsx b/webapp/src/components/cardDetail/imagePaste.tsx index d6d740a00..43e3200fb 100644 --- a/webapp/src/components/cardDetail/imagePaste.tsx +++ b/webapp/src/components/cardDetail/imagePaste.tsx @@ -36,11 +36,11 @@ export default function useImagePaste(cardId: string, contentOrder: Array b.id)) - mutator.performAsUndoGroup(async () => { - await mutator.insertBlocks(blocksToInsert, 'pasted images') + const newContentBlocks = await mutator.insertBlocks(blocksToInsert, 'pasted images') + const newContentOrder = JSON.parse(JSON.stringify(contentOrder)) + newContentOrder.push(...newContentBlocks.map((b: ImageBlock) => b.id)) + await mutator.changeCardContentOrder(cardId, contentOrder, newContentOrder, 'paste image') }) }, [cardId, contentOrder, rootId])