Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

45 lignes
1.5 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 EditorState = require("./EditorState");
  13. var UnicodeUtils = require("fbjs/lib/UnicodeUtils");
  14. var moveSelectionBackward = require("./moveSelectionBackward");
  15. var removeTextWithStrategy = require("./removeTextWithStrategy");
  16. /**
  17. * Remove the selected range. If the cursor is collapsed, remove the preceding
  18. * character. This operation is Unicode-aware, so removing a single character
  19. * will remove a surrogate pair properly as well.
  20. */
  21. function keyCommandPlainBackspace(editorState) {
  22. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  23. var selection = strategyState.getSelection();
  24. var content = strategyState.getCurrentContent();
  25. var key = selection.getAnchorKey();
  26. var offset = selection.getAnchorOffset();
  27. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  28. return moveSelectionBackward(strategyState, charBehind ? UnicodeUtils.getUTF16Length(charBehind, 0) : 1);
  29. }, 'backward');
  30. if (afterRemoval === editorState.getCurrentContent()) {
  31. return editorState;
  32. }
  33. var selection = editorState.getSelection();
  34. return EditorState.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  35. }
  36. module.exports = keyCommandPlainBackspace;