|
123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- /**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @format
- *
- * @emails oncall+draft_js
- */
- 'use strict';
-
- var EditorState = require("./EditorState");
-
- var UnicodeUtils = require("fbjs/lib/UnicodeUtils");
-
- var moveSelectionBackward = require("./moveSelectionBackward");
-
- var removeTextWithStrategy = require("./removeTextWithStrategy");
- /**
- * Remove the selected range. If the cursor is collapsed, remove the preceding
- * character. This operation is Unicode-aware, so removing a single character
- * will remove a surrogate pair properly as well.
- */
-
-
- function keyCommandPlainBackspace(editorState) {
- var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
- var selection = strategyState.getSelection();
- var content = strategyState.getCurrentContent();
- var key = selection.getAnchorKey();
- var offset = selection.getAnchorOffset();
- var charBehind = content.getBlockForKey(key).getText()[offset - 1];
- return moveSelectionBackward(strategyState, charBehind ? UnicodeUtils.getUTF16Length(charBehind, 0) : 1);
- }, 'backward');
-
- if (afterRemoval === editorState.getCurrentContent()) {
- return editorState;
- }
-
- var selection = editorState.getSelection();
- return EditorState.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
- }
-
- module.exports = keyCommandPlainBackspace;
|