Skip to content

Commit 1473d97

Browse files
justinparkJustin Park
and
Justin Park
authored
feat(sqllab): add shortcut for run current sql (apache#24329)
Co-authored-by: Justin Park <[email protected]>
1 parent ae00489 commit 1473d97

File tree

1 file changed

+60
-0
lines changed
  • superset-frontend/src/SqlLab/components/SqlEditor

1 file changed

+60
-0
lines changed

superset-frontend/src/SqlLab/components/SqlEditor/index.jsx

+60
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,66 @@ const SqlEditor = ({
332332
}
333333
},
334334
},
335+
{
336+
name: 'runQuery3',
337+
key: 'ctrl+shift+enter',
338+
descr: t('Run current query'),
339+
func: editor => {
340+
if (!editor.getValue().trim()) {
341+
return;
342+
}
343+
const session = editor.getSession();
344+
const cursorPosition = editor.getCursorPosition();
345+
const totalLine = session.getLength();
346+
let end = editor.find(';', {
347+
backwards: false,
348+
skipCurrent: true,
349+
start: cursorPosition,
350+
})?.end;
351+
if (!end || end.row < cursorPosition.row) {
352+
end = {
353+
row: totalLine + 1,
354+
column: 0,
355+
};
356+
}
357+
let start = editor.find(';', {
358+
backwards: true,
359+
skipCurrent: true,
360+
start: cursorPosition,
361+
})?.end;
362+
let currentLine = editor.find(';', {
363+
backwards: true,
364+
skipCurrent: true,
365+
start: cursorPosition,
366+
})?.end?.row;
367+
if (
368+
!currentLine ||
369+
currentLine > cursorPosition.row ||
370+
(currentLine === cursorPosition.row &&
371+
start?.column > cursorPosition.column)
372+
) {
373+
currentLine = 0;
374+
}
375+
let content =
376+
currentLine === start?.row
377+
? session.getLine(currentLine).slice(start.column).trim()
378+
: session.getLine(currentLine).trim();
379+
while (!content && currentLine < totalLine) {
380+
currentLine += 1;
381+
content = session.getLine(currentLine).trim();
382+
}
383+
if (currentLine !== start?.row) {
384+
start = { row: currentLine, column: 0 };
385+
}
386+
editor.selection.setRange({
387+
start: start ?? { row: 0, column: 0 },
388+
end,
389+
});
390+
startQuery();
391+
editor.selection.clearSelection();
392+
editor.moveCursorToPosition(cursorPosition);
393+
},
394+
},
335395
{
336396
name: 'newTab',
337397
key: userOS === 'Windows' ? 'ctrl+q' : 'ctrl+t',

0 commit comments

Comments
 (0)