Skip to content

feat(merge): blocks of different types can be merged#2671

Merged
neSpecc merged 31 commits intonextfrom
feat/merge-different-blocks
Apr 1, 2024
Merged

feat(merge): blocks of different types can be merged#2671
neSpecc merged 31 commits intonextfrom
feat/merge-different-blocks

Conversation

@neSpecc
Copy link
Member

@neSpecc neSpecc commented Mar 30, 2024

This PR based on #2564 made by @GuillaumeOnepilot


Feature

Now it is possible to merge blocks of different types.

If blocks provides the conversionConfig, we use it for merging:

BlockA -> string -> BlockB
blocks-merging.mov

Changes

  • requestAnimationFrame removed from BlockEvents@mergeBlocks. It was added because Paragraph was having RAF in merge() method. It was removed by fix(merge): incorrect caret position on merge editor-js/paragraph#86
  • normalize() removed as well since it creates issues with caret restoring — nodes text length changes and caret is being set in wrong position. It's better to call normalize() at the tool's merge() method if needed.
  • mergeBlocks and areBlocksMergeable logic improved:
    • Target block tool should have the merge() method (be .mergeable)
    • Merging blocks should be the same type
    • or Merging blocks should have the conversionConfig
  • In case of using conversion:
    1. We convert blockToMerge data to string
    2. Sanitize string
    3. Convert that string to the target's block data
    4. Call targetBlock.merge()
  • Sanitising added to the merging content.
  • Cypress updated to fix CI which is broken on all last PRs

GuillaumeOnepilot and others added 25 commits December 16, 2023 21:31
Copy link
Contributor

@GuillaumeOnepilot GuillaumeOnepilot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes 👍

/**
* 2) Blocks with different Tools if they provides conversionConfig
*/
} else if (targetBlock.mergeable && isBlockConvertable(blockToMerge, 'export') && isBlockConvertable(targetBlock, 'import')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems areBlocksMergable can be used here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

areBlockMergeable is checked before mergeBlocks call. I've written these 2 statements explicitly for clarity: first about same-tool merge, second about merging through the conversion

@neSpecc neSpecc merged commit 1320b04 into next Apr 1, 2024
@neSpecc neSpecc deleted the feat/merge-different-blocks branch April 1, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants