Home Reference Source

application/components/common/rich-editor2/util/ensure-empty-graf.js

  1. import {Block} from 'slate';
  2.  
  3. export function ensureEmptyGraf(editor) {
  4. // ensures that an empty paragraph exists at the end of the editor
  5. // this keeps non-text blocks from consuming the cursor at the end
  6. // of the editor
  7. const parent = editor.value.document;
  8. const newLine = Block.create({
  9. 'type': 'paragraph'
  10. });
  11. editor.insertNodeByKey(parent.key, parent.nodes.size, newLine);
  12. return;
  13. }