2

This code changes type of the block with matched text.
How to add another block AFTER this one in Slate.js?

import {Range} from 'slate';
import {blockTypes} from 'core/slate-types';

export default function autoreplaceHeading(node, matched, change) {
  const matchedLength = matched[0].length;

  return change
    .setBlocks(blockTypes.HEADING)
    .deleteAtRange(
      Range.create({
        anchorKey: node.key,
        focusKey: node.key,
        anchorOffset: matched.index,
        focusOffset: matched.index + matchedLength
      })
  );
}
Ukr
  • 2,411
  • 18
  • 16

0 Answers0