umd/fieldstack.js
/**
 * Transpose the characters on either side of a collapsed cursor, or
 * if the cursor is at the end of the block, transpose the last two
 * characters.
 */
Transpose the characters on either side of a collapsed cursor, or
if the cursor is at the end of the block, transpose the last two
characters.
Transpose the characters on either side of a collapsed cursor or if the cursor is at the end of the block transpose the last two characters .
function keyCommandTransposeCharacters(editorState) {
  var selection = editorState.getSelection();
  if (!selection.isCollapsed()) {
    return editorState;
  }
  var offset = selection.getAnchorOffset();
  if (offset === 0) {
    return editorState;
  }
  var blockKey = selection.getAnchorKey();
  var content = editorState.getCurrentContent();
  var block = content.getBlockForKey(blockKey);
  var length = block.getLength();
  if (length <= 1) {
    return editorState;
  }
  var removalRange;
  var finalSelection;
  if (offset === length) {
    removalRange = selection.set('anchorOffset', offset - 1);
    finalSelection = selection;
  } else {
    removalRange = selection.set('focusOffset', offset + 1);
    finalSelection = removalRange.set('anchorOffset', offset + 1);
  }
  var movedFragment = getContentStateFragment_1(content, removalRange);
  var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  var selectionAfter = afterRemoval.getSelectionAfter();
  var targetOffset = selectionAfter.getAnchorOffset() - 1;
  var targetRange = selectionAfter.merge({
    anchorOffset: targetOffset,
    focusOffset: targetOffset
  });
  var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  return EditorState_1.acceptSelection(newEditorState, finalSelection);
}
function keyCommandTransposeCharacters ( editorState ) { var selection = editorState . getSelection ( ) ; if ( ! selection . isCollapsed ( ) ) { return editorState ; } var offset = selection . getAnchorOffset ( ) ; if ( offset === 0 ) { return editorState ; } var blockKey = selection . getAnchorKey ( ) ; var content = editorState . getCurrentContent ( ) ; var block = content . getBlockForKey ( blockKey ) ; var length = block . getLength ( ) ; if ( length <= 1 ) { return editorState ; } var removalRange ; var finalSelection ; if ( offset === length ) { removalRange = selection . set ( 'anchorOffset' , offset - 1 ) ; finalSelection = selection ; } else { removalRange = selection . set ( 'focusOffset' , offset + 1 ) ; finalSelection = removalRange . set ( 'anchorOffset' , offset + 1 ) ; } var movedFragment = getContentStateFragment_1 ( content , removalRange ) ; var afterRemoval = DraftModifier_1 . removeRange ( content , removalRange , 'backward' ) ; var selectionAfter = afterRemoval . getSelectionAfter ( ) ; var targetOffset = selectionAfter . getAnchorOffset ( ) - 1 ; var targetRange = selectionAfter . merge ( { anchorOffset : targetOffset , focusOffset : targetOffset } ) ; var afterInsert = DraftModifier_1 . replaceWithFragment ( afterRemoval , targetRange , movedFragment ) ; var newEditorState = EditorState_1 . push ( editorState , afterInsert , 'insert-fragment' ) ; return EditorState_1 . acceptSelection ( newEditorState , finalSelection ) ; }
Transpose the characters on either side of a collapsed cursor, or
 if the cursor is at the end of the block, transpose the last two
 characters.
Transpose the characters on either side of a collapsed cursor or if the cursor is at the end of the block transpose the last two characters .
// Nothing to transpose if there aren't two characters. // The cursor is at the end of the block. Swap the last two characters. // Extract the character to move as a fragment. This preserves its // styling and entity, if any. // After the removal, the insertion target is one character back.