No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

74 líneas
2.1 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 DraftModifier = require("./DraftModifier");
  13. var gkx = require("./gkx");
  14. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  15. /**
  16. * For a collapsed selection state, remove text based on the specified strategy.
  17. * If the selection state is not collapsed, remove the entire selected range.
  18. */
  19. function removeTextWithStrategy(editorState, strategy, direction) {
  20. var selection = editorState.getSelection();
  21. var content = editorState.getCurrentContent();
  22. var target = selection;
  23. var anchorKey = selection.getAnchorKey();
  24. var focusKey = selection.getFocusKey();
  25. var anchorBlock = content.getBlockForKey(anchorKey);
  26. if (experimentalTreeDataSupport) {
  27. if (direction === 'forward') {
  28. if (anchorKey !== focusKey) {
  29. // For now we ignore forward delete across blocks,
  30. // if there is demand for this we will implement it.
  31. return content;
  32. }
  33. }
  34. }
  35. if (selection.isCollapsed()) {
  36. if (direction === 'forward') {
  37. if (editorState.isSelectionAtEndOfContent()) {
  38. return content;
  39. }
  40. if (experimentalTreeDataSupport) {
  41. var isAtEndOfBlock = selection.getAnchorOffset() === content.getBlockForKey(anchorKey).getLength();
  42. if (isAtEndOfBlock) {
  43. var anchorBlockSibling = content.getBlockForKey(anchorBlock.nextSibling);
  44. if (!anchorBlockSibling || anchorBlockSibling.getLength() === 0) {
  45. // For now we ignore forward delete at the end of a block,
  46. // if there is demand for this we will implement it.
  47. return content;
  48. }
  49. }
  50. }
  51. } else if (editorState.isSelectionAtStartOfContent()) {
  52. return content;
  53. }
  54. target = strategy(editorState);
  55. if (target === selection) {
  56. return content;
  57. }
  58. }
  59. return DraftModifier.removeRange(content, target, direction);
  60. }
  61. module.exports = removeTextWithStrategy;