From a475551b23d5830ab2945f615328f31d48df36ca Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 9 Nov 2016 08:42:13 -0800 Subject: [PATCH] [sqllab] bind alt+enter shortcut in AceEditor to run a query (#1554) --- .../SqlLab/components/AceEditorWrapper.jsx | 9 +++++++++ .../javascripts/SqlLab/components/SqlEditor.jsx | 11 ++++++++--- docs/sqllab.rst | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/caravel/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx b/caravel/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx index cd7069498c9f7..f41730d6a3d86 100644 --- a/caravel/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx +++ b/caravel/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx @@ -11,6 +11,7 @@ const langTools = ace.acequire('ace/ext/language_tools'); const propTypes = { actions: React.PropTypes.object.isRequired, onBlur: React.PropTypes.func, + onAltEnter: React.PropTypes.func, sql: React.PropTypes.string.isRequired, tables: React.PropTypes.array, queryEditor: React.PropTypes.object.isRequired, @@ -18,6 +19,7 @@ const propTypes = { const defaultProps = { onBlur: () => {}, + onAltEnter: () => {}, tables: [], }; @@ -48,6 +50,13 @@ class AceEditorWrapper extends React.PureComponent { callback(null, this.state.words); } onEditorLoad(editor) { + editor.commands.addCommand({ + name: 'runQuery', + bindKey: { win: 'Alt-enter', mac: 'Alt-enter' }, + exec: () => { + this.props.onAltEnter(); + }, + }); editor.$blockScrolling = Infinity; // eslint-disable-line no-param-reassign editor.selection.on('changeSelection', () => { this.props.actions.queryEditorSetSelectedText( diff --git a/caravel/assets/javascripts/SqlLab/components/SqlEditor.jsx b/caravel/assets/javascripts/SqlLab/components/SqlEditor.jsx index 9979963b56d6a..231a146f1de47 100644 --- a/caravel/assets/javascripts/SqlLab/components/SqlEditor.jsx +++ b/caravel/assets/javascripts/SqlLab/components/SqlEditor.jsx @@ -59,7 +59,11 @@ class SqlEditor extends React.PureComponent { } } runQuery(runAsync = false) { - this.startQuery(runAsync); + let effectiveRunAsync = runAsync; + if (!this.props.database.allow_run_sync) { + effectiveRunAsync = true; + } + this.startQuery(effectiveRunAsync); } startQuery(runAsync = false, ctas = false) { const qe = this.props.queryEditor; @@ -225,11 +229,12 @@ class SqlEditor extends React.PureComponent {
{editorBottomBar}
diff --git a/docs/sqllab.rst b/docs/sqllab.rst index dfd587d039ca4..43afbf99ec418 100644 --- a/docs/sqllab.rst +++ b/docs/sqllab.rst @@ -21,6 +21,9 @@ Feature Overview `Jinja templating language `_ which allows for using macros in your SQL code +Extra features +-------------- +- Hit ``alt + enter`` as a keyboard shortcut to run your query Templating with Jinja ---------------------