Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

getTextAfterNearestEntity.js.flow 814 B

3 лет назад
1234567891011121314151617181920212223242526272829
  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. * @flow strict-local
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type { BlockNodeRecord } from "./BlockNodeRecord";
  13. /**
  14. * Find the string of text between the previous entity and the specified
  15. * offset. This allows us to narrow down search areas for regex matching.
  16. */
  17. function getTextAfterNearestEntity(block: BlockNodeRecord, offset: number): string {
  18. let start = offset; // Get start based on where the last entity ended.
  19. while (start > 0 && block.getEntityAt(start - 1) === null) {
  20. start--;
  21. }
  22. return block.getText().slice(start, offset);
  23. }
  24. module.exports = getTextAfterNearestEntity;