Skip to content

Commit

Permalink
feat(sqllab): add shortcut for run current sql (#24329)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Park <[email protected]>
  • Loading branch information
justinpark and Justin Park authored Jul 11, 2023
1 parent ae00489 commit 1473d97
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,66 @@ const SqlEditor = ({
}
},
},
{
name: 'runQuery3',
key: 'ctrl+shift+enter',
descr: t('Run current query'),
func: editor => {
if (!editor.getValue().trim()) {
return;
}
const session = editor.getSession();
const cursorPosition = editor.getCursorPosition();
const totalLine = session.getLength();
let end = editor.find(';', {
backwards: false,
skipCurrent: true,
start: cursorPosition,
})?.end;
if (!end || end.row < cursorPosition.row) {
end = {
row: totalLine + 1,
column: 0,
};
}
let start = editor.find(';', {
backwards: true,
skipCurrent: true,
start: cursorPosition,
})?.end;
let currentLine = editor.find(';', {
backwards: true,
skipCurrent: true,
start: cursorPosition,
})?.end?.row;
if (
!currentLine ||
currentLine > cursorPosition.row ||
(currentLine === cursorPosition.row &&
start?.column > cursorPosition.column)
) {
currentLine = 0;
}
let content =
currentLine === start?.row
? session.getLine(currentLine).slice(start.column).trim()
: session.getLine(currentLine).trim();
while (!content && currentLine < totalLine) {
currentLine += 1;
content = session.getLine(currentLine).trim();
}
if (currentLine !== start?.row) {
start = { row: currentLine, column: 0 };
}
editor.selection.setRange({
start: start ?? { row: 0, column: 0 },
end,
});
startQuery();
editor.selection.clearSelection();
editor.moveCursorToPosition(cursorPosition);
},
},
{
name: 'newTab',
key: userOS === 'Windows' ? 'ctrl+q' : 'ctrl+t',
Expand Down

0 comments on commit 1473d97

Please sign in to comment.