draft-js-code
draft-js-code copied to clipboard
Support Shift+Tab to remove tabs
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).
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?
Yep, this looks perfect! Mind submitting a PR? Thank you!