How to use the draft-js.RichUtils.handleKeyCommand function in draft-js

To help you get started, we’ve selected a few draft-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leejaen / react-lz-editor / src / editor / index.jsx View on Github external
_handleKeyCommand(command) {
    // console.log("command",command);
    const {editorState} = this.state;
    const newState = RichUtils.handleKeyCommand(editorState, command);
    if (command === 'editor-save'&&this.props.autoSave==true) {
      // window.localDB//start20Text
      // let Data=PRO_COMMON.localDB.getter("grab_news_data") || [];

      let rawContentState = editorState.getCurrentContent()
      let content = "",newText="";

      const ConvertFormatProps = this.props.convertFormat;
      if(ConvertFormatProps === 'html') {
        content = stateToHTML(rawContentState);
        newText=content.replace(/<[^>]*>|&[^;]*;/g, "");
      }else if (ConvertFormatProps === 'markdown') {
        content = stateToMD(rawContentState);
      }else if(ConvertFormatProps === 'raw') {
        const rawContent = convertToRaw(rawContentState);
        content = JSON.stringify(rawContent);
github hoppinger / MonadicReact / src / react_monad / rich_text.tsx View on Github external
handleKeyCommand(command:DraftEditorCommand) {
    let new_state = RichUtils.handleKeyCommand(this.state.editor_state, command);
    if (new_state) {
      this.onChange(new_state, () => {
        this.editor.focus()
      })
      return "handled"
    }
    return "not-handled"
  }
github strapi / strapi / packages / strapi-plugin-content-manager / admin / src / components / Wysiwyg / index.js View on Github external
handleKeyCommand = (command, editorState) => {
    const newState = RichUtils.handleKeyCommand(editorState, command);

    if (command === 'bold' || command === 'italic' || command === 'underline') {
      const { content, style } = getKeyCommandData(command);
      this.addContent(content, style);
      return false;
    }

    if (newState && command !== 'backspace') {
      this.onChange(newState);
      return true;
    }

    return false;
  };
github florapdx / react-drafts / src / components / ReactDrafts / index.js View on Github external
_handleKeyCommand(commandName) {
    const { editorState } = this.state;
    const nextState = RichUtils.handleKeyCommand(editorState, commandName);

    if (nextState) {
      this.handleChange(nextState);
      return 'handled';
    }

    return 'not handled';
  }
github jaredpalmer / formik-alicante / src / components / RichEditor.js View on Github external
handleKeyCommand = command => {
    const { editorState } = this.props;
    const newState = RichUtils.handleKeyCommand(editorState, command);
    if (newState) {
      this.onChange(newState);
      return true;
    }
    return false;
  };
github ubyssey / dispatch / dispatch / static / manager / src / js / reducers / EditorReducer.js View on Github external
export default function editorReducer(editorState = initialState, action) {
  switch (action.type) {
  case types.UPDATE_EDITOR:
    return action.editorState

  case types.TOGGLE_EDITOR_STYLE:
    return RichUtils.toggleInlineStyle(editorState, action.style)

  case types.EDITOR_KEY_COMMAND:
    return RichUtils.handleKeyCommand(editorState, action.command) || editorState

  case types.EDITOR_INSERT_LINK:
    return RichUtils.toggleLink(
      editorState,
      action.selection ? action.selection : editorState.getSelection(),
      Entity.create('LINK', 'IMMUTABLE', { url: action.url })
    )

  case types.EDITOR_REMOVE_LINK:

    return RichUtils.toggleLink(
      editorState,
      action.selection ? action.selection : editorState.getSelection(),
      null
    )
github ruhulamindev / samsung-notes-web / src / scenes / home / notes / note / note.jsx View on Github external
handleKeyCommand = (command, editorState) => {
        const newState = RichUtils.handleKeyCommand(editorState, command);
        if (newState) {
            this.setLocalState(newState, "note");
            return 'handled';
        }
        return 'not-handled';
    }
github strues / boldr / packages / frontend / BoldrText / BoldrText.js View on Github external
handleKeyCommand = (command: string) => {
    const newState = RichUtils.handleKeyCommand(this.state.editorState, command);

    if (newState) {
      this.onChange(newState);
      return 'handled';
    }

    return 'not-handled';
  };
github thibaudcolas / draftjs-filters / src / demo / components / FilterableEditor.js View on Github external
handleKeyCommand(command: string) {
    const { editorState } = this.state

    let newState = RichUtils.handleKeyCommand(editorState, command)

    if (newState) {
      this.onChange(newState)
      return "handled"
    }

    return "not-handled"
  }
github suyulin / Hommily-Editor / app / components / HommilyEditor / src / components / Editor.js View on Github external
_handleKeyCommand(command) {
    const {editorState} = this.state;
    const newState = RichUtils.handleKeyCommand(editorState, command);
    if (newState) {
      this.onChange(newState);
      return true;
    }
    return false;
  }
  _scrollBar() {