Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/common/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const shortcutEvents: Record<string, { i18n: string; i18nParam?: string | number; context?: 'tab' | 'main' }> = {
'run-or-reload': { i18n: 'application.runOrReload', context: 'tab' },
'run-query-at-cursor': { i18n: 'application.runQueryAtCursor', context: 'tab' },
'open-new-tab': { i18n: 'application.openNewTab', context: 'tab' },
'close-tab': { i18n: 'application.closeTab', context: 'tab' },
'format-query': { i18n: 'database.formatQuery', context: 'tab' },
Expand Down Expand Up @@ -43,6 +44,11 @@ const shortcuts: ShortcutRecord[] = [
keys: ['F5'],
os: ['darwin', 'linux', 'win32']
},
{
event: 'run-query-at-cursor',
keys: ['CommandOrControl+Enter'],
os: ['darwin', 'linux', 'win32']
},
{
event: 'setFullScreen',
isFunction: true,
Expand Down
45 changes: 44 additions & 1 deletion src/renderer/components/WorkspaceTabQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
<script setup lang="ts">
import { getCurrentWindow, Menu } from '@electron/remote';
import { Ace } from 'ace-builds';
import { ConnectionParams } from 'common/interfaces/antares';
import { ClientCode, ConnectionParams } from 'common/interfaces/antares';
import { querySplitter } from 'common/libs/sqlUtils';
import { uidGen } from 'common/libs/uidGen';
import { ipcRenderer } from 'electron';
import { storeToRefs } from 'pinia';
Expand Down Expand Up @@ -372,6 +373,37 @@ const isChanged = computed(() => {
return filePath.value && lastSavedQuery.value !== query.value;
});

const getCurrentQueryAtCursor = () => {
if (!queryEditor.value?.editor) return '';

const editorInstance = queryEditor.value.editor;
const session = editorInstance.session as Ace.EditSession & {
doc: {
positionToIndex: (position: Ace.Point) => number;
};
};
const cursorPosition = editorInstance.getCursorPosition();
const cursorIndex = session.doc.positionToIndex(cursorPosition);
const allQueries = querySplitter(query.value, workspace.value.client as ClientCode);

if (!allQueries.length) return '';

let currentStart = 0;
for (const localQuery of allQueries) {
const localIndex = query.value.indexOf(localQuery, currentStart);
if (localIndex === -1) continue;

const localEnd = localIndex + localQuery.length;
const isInsideQuery = cursorIndex >= localIndex && cursorIndex <= localEnd;
if (isInsideQuery)
return localQuery;

currentStart = localEnd;
}

return '';
};

watch(query, (val) => {
clearTimeout(debounceTimeout.value);

Expand Down Expand Up @@ -674,6 +706,15 @@ const reloadListener = () => {
runQuery(query.value);
};

const runQueryAtCursorListener = () => {
const hasModalOpen = !!document.querySelectorAll('.modal.active').length;
if (!props.isSelected || hasModalOpen) return;

const queryAtCursor = getCurrentQueryAtCursor();
if (queryAtCursor)
runQuery(queryAtCursor);
};

const formatListener = () => {
const hasModalOpen = !!document.querySelectorAll('.modal.active').length;
if (props.isSelected && !hasModalOpen)
Expand Down Expand Up @@ -777,6 +818,7 @@ onMounted(() => {
const localResizer = resizer.value;

ipcRenderer.on('run-or-reload', reloadListener);
ipcRenderer.on('run-query-at-cursor', runQueryAtCursorListener);
ipcRenderer.on('format-query', formatListener);
ipcRenderer.on('kill-query', killQueryListener);
ipcRenderer.on('clear-query', clearQueryListener);
Expand Down Expand Up @@ -869,6 +911,7 @@ onBeforeUnmount(() => {
Schema.destroyConnectionToCommit(params);

ipcRenderer.removeListener('run-or-reload', reloadListener);
ipcRenderer.removeListener('run-query-at-cursor', runQueryAtCursorListener);
ipcRenderer.removeListener('format-query', formatListener);
ipcRenderer.removeListener('kill-query', killQueryListener);
ipcRenderer.removeListener('clear-query', clearQueryListener);
Expand Down
1 change: 1 addition & 0 deletions src/renderer/i18n/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export const enUS = {
openAllConnections: 'Open all connections',
openSettings: 'Open settings',
runOrReload: 'Run or reload',
runQueryAtCursor: 'Run query at cursor',
openFilter: 'Open filter',
nextResultsPage: 'Next results page',
previousResultsPage: 'Previous results page',
Expand Down
1 change: 1 addition & 0 deletions src/renderer/i18n/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export const ptBR = {
openSettings: 'Abrir Configurações',
openScratchpad: 'Abrir scratchpad',
runOrReload: 'Executar ou recarregar',
runQueryAtCursor: 'Executar consulta da linha do cursor',
openFilter: 'Abrir Filtro',
nextResultsPage: 'Próxima página de resultados',
previousResultsPage: 'Página de resultados anterior',
Expand Down