Skip to content

Commit

Permalink
Add keyboard shortcut for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ydlamba committed Jun 6, 2018
1 parent 651acc8 commit b0795b1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/components/input-panel/spec-editor/renderer.tsx
Expand Up @@ -97,7 +97,22 @@ interface Props {
updateVegaSpec: (val: any) => void;
}

const KEYCODES = {
B: 66,
};

class Editor extends React.Component<Props, {}> {
constructor(props) {
super(props);
this.handleKeydown = this.handleKeydown.bind(this);
this.handleEditorChange = this.handleEditorChange.bind(this);
this.editorWillMount = this.editorWillMount.bind(this);
}
public handleKeydown(e) {
if (e.keyCode === KEYCODES.B && e.ctrlKey && !this.props.autoParse) {
this.props.parseSpec(true);
}
}
public editorDidMount(editor) {
editor.focus();
}
Expand Down Expand Up @@ -139,6 +154,12 @@ class Editor extends React.Component<Props, {}> {
this.props.parseSpec(false);
}
}
public componentDidMount() {
document.addEventListener('keydown', this.handleKeydown);
}
public componentWillUnmount() {
document.removeEventListener('keydown', this.handleKeydown);
}
public manualParseSpec() {
if (!this.props.autoParse) {
return (
Expand Down Expand Up @@ -210,8 +231,8 @@ class Editor extends React.Component<Props, {}> {
wordWrap: 'on',
}}
value={this.props.value}
onChange={debounce(this.handleEditorChange, 700).bind(this)}
editorWillMount={this.editorWillMount.bind(this)}
onChange={debounce(this.handleEditorChange, 700)}
editorWillMount={this.editorWillMount}
editorDidMount={this.editorDidMount}
/>
</div>
Expand Down

0 comments on commit b0795b1

Please sign in to comment.