You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

getTextAfterNearestEntity.js 704 B

3 years ago
123456789101112131415161718192021222324252627
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. *
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. /**
  13. * Find the string of text between the previous entity and the specified
  14. * offset. This allows us to narrow down search areas for regex matching.
  15. */
  16. function getTextAfterNearestEntity(block, offset) {
  17. var start = offset; // Get start based on where the last entity ended.
  18. while (start > 0 && block.getEntityAt(start - 1) === null) {
  19. start--;
  20. }
  21. return block.getText().slice(start, offset);
  22. }
  23. module.exports = getTextAfterNearestEntity;