Skip to content

Commit

Permalink
[sqllab] bind alt+enter shortcut in AceEditor to run a query (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Nov 9, 2016
1 parent bad7676 commit a475551
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ 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,
};

const defaultProps = {
onBlur: () => {},
onAltEnter: () => {},
tables: [],
};

Expand Down Expand Up @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions caravel/assets/javascripts/SqlLab/components/SqlEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -225,11 +229,12 @@ class SqlEditor extends React.PureComponent {
<Col md={this.props.hideLeftBar ? 12 : 9}>
<div className="scrollbar">
<AceEditorWrapper
tables={this.props.tables}
actions={this.props.actions}
onBlur={this.setQueryEditorSql.bind(this)}
queryEditor={this.props.queryEditor}
onAltEnter={this.runQuery.bind(this)}
sql={this.props.queryEditor.sql}
onBlur={this.setQueryEditorSql.bind(this)}
tables={this.props.tables}
/>
{editorBottomBar}
<br />
Expand Down
3 changes: 3 additions & 0 deletions docs/sqllab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Feature Overview
`Jinja templating language <http://jinja.pocoo.org/docs/dev/>`_
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
---------------------
Expand Down

0 comments on commit a475551

Please sign in to comment.