umd/fieldstack.js
/**
 * Intercept keydown behavior to handle keys and commands manually, if desired.
 *
 * Keydown combinations may be mapped to `DraftCommand` values, which may
 * correspond to command functions that modify the editor or its contents.
 *
 * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
 * component may provide a custom mapping via the `keyBindingFn` prop.
 */
Intercept keydown behavior to handle keys and commands manually, if desired.
Keydown combinations may be mapped to `DraftCommand` values, which may
correspond to command functions that modify the editor or its contents.

See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
component may provide a custom mapping via the `keyBindingFn` prop.
Intercept keydown behavior to handle keys and commands manually if desired . Keydown combinations may be mapped to ` DraftCommand ` values which may correspond to command functions that modify the editor or its contents . See ` getDefaultKeyBinding ` for defaults . Alternatively the top - level component may provide a custom mapping via the ` keyBindingFn ` prop .
function editOnKeyDown(editor, e) {
  var keyCode = e.which;
  var editorState = editor._latestEditorState;
  switch (keyCode) {
    case Keys.RETURN:
      e.preventDefault();
      if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
        return;
      }
      break;
    case Keys.ESC:
      e.preventDefault();
      editor.props.onEscape && editor.props.onEscape(e);
      return;
    case Keys.TAB:
      editor.props.onTab && editor.props.onTab(e);
      return;
    case Keys.UP:
      editor.props.onUpArrow && editor.props.onUpArrow(e);
      return;
    case Keys.RIGHT:
      editor.props.onRightArrow && editor.props.onRightArrow(e);
      return;
    case Keys.DOWN:
      editor.props.onDownArrow && editor.props.onDownArrow(e);
      return;
    case Keys.LEFT:
      editor.props.onLeftArrow && editor.props.onLeftArrow(e);
      return;
    case Keys.SPACE:
      if (isChrome && isOptionKeyCommand(e)) {
        e.preventDefault();
        var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
        editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
        return;
      }
  }
  var command = editor.props.keyBindingFn(e);
  if (!command) {
    return;
  }
  if (command === 'undo') {
    keyCommandUndo_1(e, editorState, editor.update);
    return;
  }
  e.preventDefault();
  if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
    return;
  }
  var newState = onKeyCommand(command, editorState);
  if (newState !== editorState) {
    editor.update(newState);
  }
}
function editOnKeyDown ( editor , e ) { var keyCode = e . which ; var editorState = editor . _latestEditorState ; switch ( keyCode ) { case Keys . RETURN : e . preventDefault ( ) ; if ( editor . props . handleReturn && isEventHandled_1 ( editor . props . handleReturn ( e , editorState ) ) ) { return ; } break ; case Keys . ESC : e . preventDefault ( ) ; editor . props . onEscape && editor . props . onEscape ( e ) ; return ; case Keys . TAB : editor . props . onTab && editor . props . onTab ( e ) ; return ; case Keys . UP : editor . props . onUpArrow && editor . props . onUpArrow ( e ) ; return ; case Keys . RIGHT : editor . props . onRightArrow && editor . props . onRightArrow ( e ) ; return ; case Keys . DOWN : editor . props . onDownArrow && editor . props . onDownArrow ( e ) ; return ; case Keys . LEFT : editor . props . onLeftArrow && editor . props . onLeftArrow ( e ) ; return ; case Keys . SPACE : if ( isChrome && isOptionKeyCommand ( e ) ) { e . preventDefault ( ) ; var contentState = DraftModifier_1 . replaceText ( editorState . getCurrentContent ( ) , editorState . getSelection ( ) , '\xA0' ) ; editor . update ( EditorState_1 . push ( editorState , contentState , 'insert-characters' ) ) ; return ; } } var command = editor . props . keyBindingFn ( e ) ; if ( ! command ) { return ; } if ( command === 'undo' ) { keyCommandUndo_1 ( e , editorState , editor . update ) ; return ; } e . preventDefault ( ) ; if ( editor . props . handleKeyCommand && isEventHandled_1 ( editor . props . handleKeyCommand ( command , editorState ) ) ) { return ; } var newState = onKeyCommand ( command , editorState ) ; if ( newState !== editorState ) { editor . update ( newState ) ; } }
Intercept keydown behavior to handle keys and commands manually, if desired.
Intercept keydown behavior to handle keys and commands manually if desired .
// The top-level component may manually handle newline insertion. If // no special handling is performed, fall through to command handling. // Handling for OSX where option + space scrolls. // Insert a nbsp into the editor. // If no command is specified, allow keydown event to continue. // Since undo requires some special updating behavior to keep the editor // in sync, handle it separately. // At this point, we know that we're handling a command of some kind, so // we don't want to insert a character following the keydown. // Allow components higher up the tree to handle the command first.