mirror of
https://github.com/apache/superset.git
synced 2026-04-22 01:24:43 +00:00
Hotkeys in SQL Lab (#4680)
* Hotkeys * Making it work in AceEditor * Addressing comments
This commit is contained in:
committed by
GitHub
parent
deb211154d
commit
f510956da2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user