Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

45 Zeilen
1.4 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 DraftRemovableWord = require("./DraftRemovableWord");
  13. var EditorState = require("./EditorState");
  14. var moveSelectionForward = require("./moveSelectionForward");
  15. var removeTextWithStrategy = require("./removeTextWithStrategy");
  16. /**
  17. * Delete the word that is right of the cursor, as well as any spaces or
  18. * punctuation before the word.
  19. */
  20. function keyCommandDeleteWord(editorState) {
  21. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  22. var selection = strategyState.getSelection();
  23. var offset = selection.getStartOffset();
  24. var key = selection.getStartKey();
  25. var content = strategyState.getCurrentContent();
  26. var text = content.getBlockForKey(key).getText().slice(offset);
  27. var toRemove = DraftRemovableWord.getForward(text); // If there are no words in front of the cursor, remove the newline.
  28. return moveSelectionForward(strategyState, toRemove.length || 1);
  29. }, 'forward');
  30. if (afterRemoval === editorState.getCurrentContent()) {
  31. return editorState;
  32. }
  33. return EditorState.push(editorState, afterRemoval, 'remove-range');
  34. }
  35. module.exports = keyCommandDeleteWord;