Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(AiAssistant): 增加输入框高度调整功能,AI 回答同时支持输入

二丫讲梵16f546ada10e
diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vue
index 6938c30798..d34fbabf65 100644
--- a/apps/desktop/src/components/editor/AiAssistant.vue
+++ b/apps/desktop/src/components/editor/AiAssistant.vue
@@ -148,17 +148,17 @@ function modelOptionSecondary(modelId: string, label = displayModelName(modelId)
/** Deferred context compaction info; applied after stream ends to avoid shifting assistantIdx. */
const pendingCompaction = ref<{ summary: string; compactedMessages: number } | null>(null);
-// 新增:输入框拖拽调整相关常量
-const AI_TEXTAREA_MIN_ROWS = 3;
-const AI_TEXTAREA_MAX_ROWS = 8;
-const AI_TEXTAREA_LINE_HEIGHT_PX = 20;
-const AI_TEXTAREA_ROWS_STORAGE_KEY = "dbx-ai-textarea-rows";
-
-// 新增:输入框拖拽调整相关状态
-const textareaRows = ref<number>(AI_TEXTAREA_MIN_ROWS);
+const AI_TEXTAREA_MIN_HEIGHT_PX = 64;
+const AI_TEXTAREA_MAX_PANEL_RATIO = 0.5;
+const AI_TEXTAREA_HEIGHT_STORAGE_KEY = "dbx-ai-textarea-height";
+
+const textareaHeight = ref<number>(AI_TEXTAREA_MIN_HEIGHT_PX);
+const assistantRootRef = ref<HTMLElement | null>(null);
+const promptPanelRef = ref<HTMLElement | null>(null);
const isResizing = ref<boolean>(false);
let resizeStartY = 0;
-let resizeStartRows = 0;
+let resizeStartHeight = 0;
+let promptPanelResizeObserver: ResizeObserver | undefined;
interface AiMentionCandidate {
schema?: string;
@@ -606,7 +606,7 @@ function filterMentionCandidates(candidates: AiMentionCandidate[], tableFilter:
function refreshMentionState() {
clearTimeout(mentionTimer);
const mention = activeMentionAtCursor();
- if (!mention || !props.connection || !props.tab?.database || isGenerating.value) {
+ if (!mention || !props.connection || !props.tab?.database) {
mentionOpen.value = false;
return;
}
@@ -917,16 +917,14 @@ function startNewChat() {
}
onMounted(async () => {
- // 新增:恢复用户偏好的输入框行数
- const savedRows = localStorage.getItem(AI_TEXTAREA_ROWS_STORAGE_KEY);
- if (savedRows) {
- const rows = parseInt(savedRows, 10);
- if (!isNaN(rows) && rows >= AI_TEXTAREA_MIN_ROWS && rows <= AI_TEXTAREA_MAX_ROWS) {
- textareaRows.value = rows;
+ const savedHeight = localStorage.getItem(AI_TEXTAREA_HEIGHT_STORAGE_KEY);
+ if (savedHeight) {
+ const height = parseInt(savedHeight, 10);
+ if (!isNaN(height)) {
+ textareaHeight.value = clampTextareaHeight(height);
}
}
- // 现有代码
conversations.value = await loadAiConversations().catch(() => []);
shikiCodeHighlighter.value = await createAiShikiCodeHighlighter({
appearance: () => aiCodeAppearance.value,
@@ -934,13 +932,35 @@ onMounted(async () => {
// Load available AI models for inline selector
fetchModelOptions();
+
+ window.addEventListener("resize", handlePanelResize);
+ if (typeof ResizeObserver !== "undefined" && assistantRootRef.value) {
+ promptPanelResizeObserver = new ResizeObserver(handlePanelResize);
+ promptPanelResizeObserver.observe(assistantRootRef.value);
+ }
});
+function maxTextareaHeight() {
+ const panelHeight = assistantRootRef.value?.clientHeight || window.innerHeight || 0;
+ const promptPanelHeight = promptPanelRef.value?.offsetHeight || 0;
+ const currentTextareaHeight = promptTextareaRef.value?.offsetHeight || textareaHeight.value;
+ const promptPanelChromeHeight = Math.max(0, promptPanelHeight - currentTextareaHeight);
+ return Math.max(AI_TEXTAREA_MIN_HEIGHT_PX, Math.floor(panelHeight * AI_TEXTAREA_MAX_PANEL_RATIO - promptPanelChromeHeight));
+}
+
+function clampTextareaHeight(height: number) {
+ return Math.max(AI_TEXTAREA_MIN_HEIGHT_PX, Math.min(maxTextareaHeight(), Math.round(height)));
+}
+
+function handlePanelResize() {
+ textareaHeight.value = clampTextareaHeight(textareaHeight.value);
+}
+
function startResize(event: MouseEvent) {
event.preventDefault();
isResizing.value = true;
resizeStartY = event.clientY;
- resizeStartRows = textareaRows.value;
+ resizeStartHeight = textareaHeight.value;
document.addEventListener("mousemove", handleResize);
document.addEventListener("mouseup", stopResize);
@@ -953,10 +973,7 @@ function handleResize(event: MouseEvent) {
if (!isResizing.value) return;
const deltaY = resizeStartY - event.clientY;
- const deltaRows = Math.round(deltaY / AI_TEXTAREA_LINE_HEIGHT_PX);
-
- const newRows = Math.max(AI_TEXTAREA_MIN_ROWS, Math.min(AI_TEXTAREA_MAX_ROWS, resizeStartRows + deltaRows));
- textareaRows.value = newRows;
+ textareaHeight.value = clampTextareaHeight(resizeStartHeight + deltaY);
}
function stopResize() {
@@ -970,7 +987,7 @@ function stopResize() {
document.body.style.userSelect = "";
document.body.style.cursor = "";
- localStorage.setItem(AI_TEXTAREA_ROWS_STORAGE_KEY, textareaRows.value.toString());
+ localStorage.setItem(AI_TEXTAREA_HEIGHT_STORAGE_KEY, clampTextareaHeight(textareaHeight.value).toString());
}
onUnmounted(() => {
@@ -982,6 +999,8 @@ onUnmounted(() => {
// 若卸载时仍在拖拽,复位 body 样式,避免全局残留
document.body.style.userSelect = "";
document.body.style.cursor = "";
+ window.removeEventListener("resize", handlePanelResize);
+ promptPanelResizeObserver?.disconnect();
});
function triggerAction(action: AiAction, instruction?: string) {
@@ -1021,7 +1040,7 @@ const messageRenderer = computed(() => {
</script>
<template>
- <div class="flex h-full min-h-0 flex-col overflow-hidden">
+ <div ref="assistantRootRef" class="flex h-full min-h-0 flex-col overflow-hidden">
<div class="flex items-center gap-2 border-b px-3 shrink-0" :class="settings.editorSettings.appLayout === 'classic' ? 'h-9' : 'h-10'">
<span class="flex flex-1 self-stretch items-center truncate text-xs font-medium" data-tauri-drag-region>
{{ chatTitle }}
@@ -1172,7 +1191,7 @@ const messageRenderer = computed(() => {
</ScrollArea>
<div class="p-2">
- <div class="relative rounded-lg border bg-background">
+ <div ref="promptPanelRef" class="relative rounded-lg border bg-background">
<div class="resize-handle" @mousedown="startResize"></div>
<div class="px-2 pb-2 pt-1">
<div v-if="connectionStore.connections.length" class="flex items-center gap-1 mb-1 text-xs text-foreground/80">
@@ -1269,10 +1288,9 @@ const messageRenderer = computed(() => {
<textarea
ref="promptTextareaRef"
v-model="prompt"
- :rows="textareaRows"
+ :style="{ height: `${textareaHeight}px`, maxHeight: `${maxTextareaHeight()}px` }"
class="w-full resize-none bg-transparent text-xs outline-none placeholder:text-muted-foreground mb-1"
:placeholder="activePlaceholder"
- :disabled="isGenerating"
@input="refreshMentionState"
@click="refreshMentionState"
@keyup="refreshMentionState"