mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 16:13:58 +00:00
ai assistant UX
This commit is contained in:
@@ -73,7 +73,7 @@
|
|||||||
import useEditorData from '../query/useEditorData';
|
import useEditorData from '../query/useEditorData';
|
||||||
import { currentEditorWrapEnabled, extensions } from '../stores';
|
import { currentEditorWrapEnabled, extensions } from '../stores';
|
||||||
import applyScriptTemplate from '../utility/applyScriptTemplate';
|
import applyScriptTemplate from '../utility/applyScriptTemplate';
|
||||||
import { changeTab, markTabUnsaved } from '../utility/common';
|
import { changeTab, markTabUnsaved, sleep } from '../utility/common';
|
||||||
import { getDatabaseInfo, useConnectionInfo } from '../utility/metadataLoaders';
|
import { getDatabaseInfo, useConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import SocketMessageView from '../query/SocketMessageView.svelte';
|
import SocketMessageView from '../query/SocketMessageView.svelte';
|
||||||
import useEffect from '../utility/useEffect';
|
import useEffect from '../utility/useEffect';
|
||||||
@@ -150,6 +150,7 @@
|
|||||||
let domToolStrip;
|
let domToolStrip;
|
||||||
let intervalId;
|
let intervalId;
|
||||||
let isAiAssistantVisible = isProApp() && localStorage.getItem(`tabdata_isAiAssistantVisible_${tabid}`) == 'true';
|
let isAiAssistantVisible = isProApp() && localStorage.getItem(`tabdata_isAiAssistantVisible_${tabid}`) == 'true';
|
||||||
|
let domAiAssistant;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
intervalId = setInterval(() => {
|
intervalId = setInterval(() => {
|
||||||
@@ -405,6 +406,26 @@
|
|||||||
errorMessages = errors;
|
errorMessages = errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleKeyDown(event) {
|
||||||
|
if (isProApp()) {
|
||||||
|
if (event.code == 'Space' && event.shiftKey && !isAiAssistantVisible) {
|
||||||
|
event.preventDefault();
|
||||||
|
toggleAiAssistant();
|
||||||
|
await sleep(100);
|
||||||
|
if (domAiAssistant) {
|
||||||
|
domAiAssistant.handleCompleteOnCursor();
|
||||||
|
domEditor?.getEditor()?.focus();
|
||||||
|
}
|
||||||
|
} else if (event.code == 'Space' && event.shiftKey && isAiAssistantVisible && domAiAssistant) {
|
||||||
|
event.preventDefault();
|
||||||
|
domAiAssistant.handleCompleteOnCursor();
|
||||||
|
} else if (event.code?.startsWith('Digit') && event.altKey && isAiAssistantVisible && domAiAssistant) {
|
||||||
|
event.preventDefault();
|
||||||
|
domAiAssistant.insertCompletion(parseInt(event.code.substring(5)) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
return [
|
return [
|
||||||
{ command: 'query.execute' },
|
{ command: 'query.execute' },
|
||||||
@@ -482,6 +503,7 @@
|
|||||||
bind:this={domEditor}
|
bind:this={domEditor}
|
||||||
onExecuteFragment={(sql, startLine) => executeCore(sql, startLine)}
|
onExecuteFragment={(sql, startLine) => executeCore(sql, startLine)}
|
||||||
{errorMessages}
|
{errorMessages}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<AceEditor
|
<AceEditor
|
||||||
@@ -521,6 +543,7 @@
|
|||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
<svelte:fragment slot="2">
|
<svelte:fragment slot="2">
|
||||||
<QueryAiAssistant
|
<QueryAiAssistant
|
||||||
|
bind:this={domAiAssistant}
|
||||||
{conid}
|
{conid}
|
||||||
{database}
|
{database}
|
||||||
{driver}
|
{driver}
|
||||||
|
|||||||
Reference in New Issue
Block a user