/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format * * @emails oncall+draft_js */ 'use strict'; function isSelectionAtLeafStart(editorState) { var selection = editorState.getSelection(); var anchorKey = selection.getAnchorKey(); var blockTree = editorState.getBlockTree(anchorKey); var offset = selection.getStartOffset(); var isAtStart = false; blockTree.some(function (leafSet) { if (offset === leafSet.get('start')) { isAtStart = true; return true; } if (offset < leafSet.get('end')) { return leafSet.get('leaves').some(function (leaf) { var leafStart = leaf.get('start'); if (offset === leafStart) { isAtStart = true; return true; } return false; }); } return false; }); return isAtStart; } module.exports = isSelectionAtLeafStart;