import { __require as requireEditorState } from './EditorState.js';
import { __require as requireUnicodeUtils } from '../../../../fbjs@2.0.0/node_modules/fbjs/lib/UnicodeUtils.js';
import { __require as requireMoveSelectionBackward } from './moveSelectionBackward.js';
import { __require as requireRemoveTextWithStrategy } from './removeTextWithStrategy.js';

/**
 * 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
 */

var keyCommandPlainBackspace_1;
var hasRequiredKeyCommandPlainBackspace;

function requireKeyCommandPlainBackspace () {
	if (hasRequiredKeyCommandPlainBackspace) return keyCommandPlainBackspace_1;
	hasRequiredKeyCommandPlainBackspace = 1;

	var EditorState = requireEditorState();

	var UnicodeUtils = requireUnicodeUtils();

	var moveSelectionBackward = requireMoveSelectionBackward();

	var removeTextWithStrategy = requireRemoveTextWithStrategy();
	/**
	 * 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');
	}

	keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
	return keyCommandPlainBackspace_1;
}

export { requireKeyCommandPlainBackspace as __require };
//# sourceMappingURL=keyCommandPlainBackspace.js.map
