feat(sqllab): add shortcut for run current sql (#24329)

Co-authored-by: Justin Park <justinpark@apache.org>
This commit is contained in:
JUST.in DO IT
2023-07-11 13:19:52 -07:00
committed by GitHub
parent ae00489779
commit 1473d97055

View File

@@ -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',