draft-js
Version:
A React framework for building text editors.
43 lines (37 loc) • 1 kB
JavaScript
/**
* 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
*/
;
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;