draft-js
Version:
A React framework for building text editors.
36 lines (32 loc) • 881 B
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
*/
;
/**
* Maintain persistence for target list when appending and prepending.
*/
function insertIntoList(targetListArg, toInsert, offset) {
var targetList = targetListArg;
if (offset === targetList.count()) {
toInsert.forEach(function (c) {
targetList = targetList.push(c);
});
} else if (offset === 0) {
toInsert.reverse().forEach(function (c) {
targetList = targetList.unshift(c);
});
} else {
var head = targetList.slice(0, offset);
var tail = targetList.slice(offset);
targetList = head.concat(toInsert, tail).toList();
}
return targetList;
}
module.exports = insertIntoList;