Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow execution of highlighted subquery #3288

Merged
merged 9 commits into from
Jan 20, 2019
23 changes: 22 additions & 1 deletion client/app/components/QueryEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class QueryEditor extends React.Component {

onLoad = (editor) => {
// Release Cmd/Ctrl+L to the browser
this.editor = editor;
chang marked this conversation as resolved.
Show resolved Hide resolved
editor.commands.bindKey('Cmd+L', null);
editor.commands.bindKey('Ctrl+P', null);
editor.commands.bindKey('Ctrl+L', null);
Expand Down Expand Up @@ -181,6 +182,25 @@ class QueryEditor extends React.Component {
});
};

setFullUnhighlightedQuery = () => {
this.props.updateQuery(this.state.queryText);
}

updateQueryWithSelection = (selection) => {
const doc = this.editor.getSession().doc;
const highlightedQueryText = doc.getTextRange(selection.getRange());
if (highlightedQueryText.length > 1) {
this.props.updateQuery(highlightedQueryText);
} else {
this.setFullUnhighlightedQuery();
}
}

saveQuery = (customOptions, data) => {
this.setFullUnhighlightedQuery();
this.props.saveQuery(customOptions, data);
}

updateQuery = (queryText) => {
this.props.updateQuery(queryText);
this.setState({ queryText });
Expand Down Expand Up @@ -229,6 +249,7 @@ class QueryEditor extends React.Component {
onLoad={this.onLoad}
onPaste={this.onPaste}
onChange={this.updateQuery}
onSelectionChange={this.updateQueryWithSelection}
/>
</div>

Expand Down Expand Up @@ -269,7 +290,7 @@ class QueryEditor extends React.Component {
</select>
{this.props.canEdit ? (
<Tooltip placement="top" title={modKey + ' + S'}>
<button className="btn btn-default m-l-5" onClick={this.props.saveQuery} title="Save">
<button className="btn btn-default m-l-5" onClick={this.saveQuery} title="Save">
<span className="fa fa-floppy-o" />
<span className="hidden-xs m-l-5">Save</span>
{this.props.isDirty ? '*' : null}
Expand Down