Hotkeys in SQL Lab (#4680)

* Hotkeys

* Making it work in AceEditor

* Addressing comments
This commit is contained in:
Maxime Beauchemin
2018-03-27 15:54:54 -07:00
committed by GitHub
parent deb211154d
commit f510956da2
4 changed files with 118 additions and 21 deletions

View File

@@ -28,16 +28,19 @@ const sqlWords = sqlKeywords.map(s => ({
const propTypes = {
actions: PropTypes.object.isRequired,
onBlur: PropTypes.func,
onAltEnter: PropTypes.func,
sql: PropTypes.string.isRequired,
tables: PropTypes.array,
queryEditor: PropTypes.object.isRequired,
height: PropTypes.string,
hotkeys: PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string.isRequired,
descr: PropTypes.string.isRequired,
func: PropTypes.func.isRequired,
})),
};
const defaultProps = {
onBlur: () => {},
onAltEnter: () => {},
tables: [],
};
@@ -67,7 +70,6 @@ class AceEditorWrapper extends React.PureComponent {
}
onAltEnter() {
this.props.onBlur(this.state.sql);
this.props.onAltEnter();
}
onEditorLoad(editor) {
editor.commands.addCommand({
@@ -77,6 +79,13 @@ class AceEditorWrapper extends React.PureComponent {
this.onAltEnter();
},
});
this.props.hotkeys.forEach((keyConfig) => {
editor.commands.addCommand({
name: keyConfig.name,
bindKey: { win: keyConfig.key, mac: keyConfig.key },
exec: keyConfig.func,
});
});
editor.$blockScrolling = Infinity; // eslint-disable-line no-param-reassign
editor.selection.on('changeSelection', () => {
const selectedText = editor.getSelectedText();