import { __require as requireDraftRemovableWord } from './DraftRemovableWord.js';
import { __require as requireEditorState } from './EditorState.js';
import { __require as requireMoveSelectionForward } from './moveSelectionForward.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 keyCommandDeleteWord_1;
var hasRequiredKeyCommandDeleteWord;

function requireKeyCommandDeleteWord () {
	if (hasRequiredKeyCommandDeleteWord) return keyCommandDeleteWord_1;
	hasRequiredKeyCommandDeleteWord = 1;

	var DraftRemovableWord = requireDraftRemovableWord();

	var EditorState = requireEditorState();

	var moveSelectionForward = requireMoveSelectionForward();

	var removeTextWithStrategy = requireRemoveTextWithStrategy();
	/**
	 * Delete the word that is right of the cursor, as well as any spaces or
	 * punctuation before the word.
	 */


	function keyCommandDeleteWord(editorState) {
	  var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
	    var selection = strategyState.getSelection();
	    var offset = selection.getStartOffset();
	    var key = selection.getStartKey();
	    var content = strategyState.getCurrentContent();
	    var text = content.getBlockForKey(key).getText().slice(offset);
	    var toRemove = DraftRemovableWord.getForward(text); // If there are no words in front of the cursor, remove the newline.

	    return moveSelectionForward(strategyState, toRemove.length || 1);
	  }, 'forward');

	  if (afterRemoval === editorState.getCurrentContent()) {
	    return editorState;
	  }

	  return EditorState.push(editorState, afterRemoval, 'remove-range');
	}

	keyCommandDeleteWord_1 = keyCommandDeleteWord;
	return keyCommandDeleteWord_1;
}

export { requireKeyCommandDeleteWord as __require };
//# sourceMappingURL=keyCommandDeleteWord.js.map
