draft-js-code icon indicating copy to clipboard operation
draft-js-code copied to clipboard

Support Shift+Tab to remove tabs

Open avk opened this issue 8 years ago • 2 comments

Typing Shift+Tab should remove one set of spaces inserted by typing Tab. It currently continues to insert spaces rather than remove them.

In the mean time, it could least do what backspace currently does (i.e. remove all the spaces inserted by typing Tab).

avk avatar Aug 08 '16 23:08 avk

To support deleting tabs, I had to adapt my onTab handler to:

  handleTab(evt) {
    let newState;
    let { editorState } = this.state;

    if (evt.shiftKey) {
      // since backspace removes tabs in CodeUtils 
      // https://github.com/SamyPesse/draft-js-code/blob/9783c0f6bbedda6b7089712f9c657a72fdae636d/lib/handleKeyCommand.js#L11
      newState = CodeUtils.handleKeyCommand(editorState, 'backspace');
    } else {
      // let CodeUtils insert tabs
      newState = CodeUtils.handleTab(evt, editorState);
    }

    this.setState({
      editorState: newState,
    });
  }

This logic feels like it should live in CodeUtils.handleTab. Thoughts?

avk avatar Aug 08 '16 23:08 avk

Yep, this looks perfect! Mind submitting a PR? Thank you!

mxstbr avatar Sep 22 '17 19:09 mxstbr