Skip to content

Support Shift+Tab to remove tabs #6

Open

Description

@avk

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).

Activity

  1. avk commented on Aug 8, 2016

    @avk
    ContributorAuthor

    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?

  2. mxstbr commented on Sep 22, 2017

    @mxstbr
    Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions