selectionrootobtainer.js 757 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module ui/selectionrootobtainer
  7. */
  8. /**
  9. * Returns a function, which obtains the farthest DOM
  10. * {@link module:engine/view/rooteditableelement~RootEditableElement}
  11. * of the {@link module:engine/view/document~Document#selection}.
  12. *
  13. * @param {module:core/editor/editor~Editor} editor Editor instance.
  14. * @returns {Function}
  15. */
  16. export default function selectionRootObtainer( editor ) {
  17. return () => {
  18. const view = editor.editing.view;
  19. const editableElement = view.selection.editableElement;
  20. if ( editableElement ) {
  21. return view.domConverter.mapViewToDom( editableElement.root );
  22. }
  23. return null;
  24. };
  25. }