SamyPesse / draft-js-prism

Code highlighting for DraftJS using Prism
http://samypesse.github.io/draft-js-prism/
Apache License 2.0
274 stars 36 forks source link

Registering tab as N spaces (or literal tab) #2

Closed rgbkrk closed 8 years ago

rgbkrk commented 8 years ago

Tab is the default behavior currently, it would be great to have this as space insertion similar to codemirror.

SamyPesse commented 8 years ago

I agree, but this is not the goal of this module, draftjs-prism should only provide the code highlighting decorator, not the keyboard handling.

Since I'm going to work on this for our application at GitBook, I'll probably publish a module like draftjs-code to provide helpers for this.

Something like this, which can be composed with other keyboard handling:

var CodeUtils = require('draftjs-code')

render() {
  return (
    <Editor
      editorState={this.state.editorState}
      handleKeyCommand={CodeUtils.handleKeyCommand}
      keyBindingFn={CodeUtils.keyBinding}
      ...
    />
  );
}
SamyPesse commented 8 years ago

@rgbkrk I'm working on draft-js-code to do this, take a look at the demo: http://samypesse.github.io/draft-js-code/

rgbkrk commented 8 years ago

That's a great demo! Thanks.