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

42 строки
1.7 KiB

  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. var TokenizeUtil = require("fbjs/lib/TokenizeUtil");
  13. var punctuation = TokenizeUtil.getPunctuation(); // The apostrophe and curly single quotes behave in a curious way: when
  14. // surrounded on both sides by word characters, they behave as word chars; when
  15. // either neighbor is punctuation or an end of the string, they behave as
  16. // punctuation.
  17. var CHAMELEON_CHARS = "['\u2018\u2019]"; // Remove the underscore, which should count as part of the removable word. The
  18. // "chameleon chars" also count as punctuation in this regex.
  19. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  20. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  21. var DELETE_REGEX = new RegExp(DELETE_STRING);
  22. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  23. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  24. function getRemovableWord(text, isBackward) {
  25. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  26. return matches ? matches[0] : text;
  27. }
  28. var DraftRemovableWord = {
  29. getBackward: function getBackward(text) {
  30. return getRemovableWord(text, true);
  31. },
  32. getForward: function getForward(text) {
  33. return getRemovableWord(text, false);
  34. }
  35. };
  36. module.exports = DraftRemovableWord;