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。

fix(grid): preserve drawer widths and copy ddl

t8y2396b168a9c5f
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 6351a3fffb..747b45fc5a 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -332,7 +332,7 @@ const rowDetailDialogOpen = ref(false);
const rowDetailDialogRowId = ref<number | null>(null);
const columnDetailDialogOpen = ref(false);
const columnDetailDialogColumnIndex = ref<number | null>(null);
-const detailWidth = ref(320);
+const detailWidth = ref(settingsStore.editorSettings.cellDetailDrawerWidth);
const isResizingDetail = ref(false);
const imagePreviewOpen = ref(false);
const imagePreviewSrc = ref("");
@@ -2845,9 +2845,23 @@ function openImagePreview(src: string, title: string) {
imagePreviewOpen.value = true;
}
+function selectionNodeElement(node: Node | null): Element | null {
+ if (!node) return null;
+ return node instanceof Element ? node : node.parentElement;
+}
+
+function hasNativeClipboardSelection(): boolean {
+ const selection = window.getSelection();
+ if (!selection || selection.isCollapsed) return false;
+ const anchorRegion = selectionNodeElement(selection.anchorNode)?.closest("[data-native-clipboard]");
+ const focusRegion = selectionNodeElement(selection.focusNode)?.closest("[data-native-clipboard]");
+ return !!anchorRegion && anchorRegion === focusRegion;
+}
+
function eventTargetAllowsNativeClipboard(event: KeyboardEvent): boolean {
const target = event.target as HTMLElement | null;
- return !!target?.closest("input, textarea, [contenteditable='true'], [role='textbox']");
+ if (target?.closest("input, textarea, [contenteditable='true'], [role='textbox']")) return true;
+ return clipboardShortcut(event, "c") && hasNativeClipboardSelection();
}
function clipboardShortcut(event: KeyboardEvent, key: string): boolean {
@@ -3590,11 +3604,14 @@ const sqlOneLiner = computed(() => props.sql?.replace(/\s+/g, " ").trim() || "")
type TableInfoTab = "columns" | "indexes" | "foreignKeys" | "triggers" | "ddl";
+const TABLE_INFO_DRAWER_MIN_WIDTH = 240;
+const CELL_DETAIL_DRAWER_MIN_WIDTH = 260;
+const DRAWER_MAX_WIDTH = 900;
const showTableInfo = globalDdlOpen;
const activeTableInfoTab = ref<TableInfoTab>("columns");
const ddlContent = ref("");
const ddlLoading = ref(false);
-const ddlWidth = ref(320);
+const ddlWidth = ref(settingsStore.editorSettings.tableInfoDrawerWidth);
const ddlWrap = ref(true);
const isResizingDdl = ref(false);
let ddlResizeStartX = 0;
@@ -3619,6 +3636,20 @@ watch(activeTableInfoTab, () => {
searchQuery.value = "";
});
+watch(
+ () => settingsStore.editorSettings.tableInfoDrawerWidth,
+ (width) => {
+ if (!isResizingDdl.value) ddlWidth.value = width;
+ },
+);
+
+watch(
+ () => settingsStore.editorSettings.cellDetailDrawerWidth,
+ (width) => {
+ if (!isResizingDetail.value) detailWidth.value = width;
+ },
+);
+
const ddlDrawerStyle = computed(() => ({
width: `${ddlWidth.value}px`,
}));
@@ -3823,10 +3854,13 @@ function onDdlResizeStart(event: MouseEvent) {
function onDdlResizeMove(event: MouseEvent) {
if (!isResizingDdl.value) return;
const nextWidth = ddlResizeStartWidth + ddlResizeStartX - event.clientX;
- ddlWidth.value = Math.min(Math.max(nextWidth, 240), 900);
+ ddlWidth.value = Math.min(Math.max(nextWidth, TABLE_INFO_DRAWER_MIN_WIDTH), DRAWER_MAX_WIDTH);
}
function onDdlResizeEnd() {
+ if (isResizingDdl.value) {
+ settingsStore.updateEditorSettings({ tableInfoDrawerWidth: ddlWidth.value });
+ }
isResizingDdl.value = false;
document.body.classList.remove("select-none", "cursor-col-resize");
window.removeEventListener("mousemove", onDdlResizeMove);
@@ -3845,10 +3879,13 @@ function onDetailResizeStart(event: MouseEvent) {
function onDetailResizeMove(event: MouseEvent) {
if (!isResizingDetail.value) return;
const nextWidth = detailResizeStartWidth + detailResizeStartX - event.clientX;
- detailWidth.value = Math.min(Math.max(nextWidth, 260), 900);
+ detailWidth.value = Math.min(Math.max(nextWidth, CELL_DETAIL_DRAWER_MIN_WIDTH), DRAWER_MAX_WIDTH);
}
function onDetailResizeEnd() {
+ if (isResizingDetail.value) {
+ settingsStore.updateEditorSettings({ cellDetailDrawerWidth: detailWidth.value });
+ }
isResizingDetail.value = false;
document.body.classList.remove("select-none", "cursor-col-resize");
window.removeEventListener("mousemove", onDetailResizeMove);
@@ -5515,8 +5552,17 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
<div class="flex items-center gap-2 px-3 py-1.5 border-b shrink-0 bg-muted/20">
<TableProperties class="w-3.5 h-3.5 text-muted-foreground" />
<span class="text-xs font-medium flex-1 min-w-0 truncate">{{ tableMeta?.tableName }}</span>
- <Button v-if="activeTableInfoTab === 'ddl'" variant="ghost" size="icon" class="h-5 w-5" @click="copyDdl">
+ <Button
+ v-if="activeTableInfoTab === 'ddl'"
+ variant="ghost"
+ size="sm"
+ class="h-6 px-2 text-xs"
+ :title="t('grid.copyDdl')"
+ :aria-label="t('grid.copyDdl')"
+ @click="copyDdl"
+ >
<Copy class="w-3 h-3" />
+ <span>{{ t("grid.copyDdl") }}</span>
</Button>
<Button
v-if="activeTableInfoTab === 'ddl'"
@@ -5689,6 +5735,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
<pre
v-else-if="activeTableInfoTab === 'ddl' && !ddlLoading"
+ data-native-clipboard
class="flex-1 min-w-0 text-xs font-mono p-3 overflow-auto ddl-code leading-5 select-text"
:class="ddlWrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre'"
v-html="filteredDdlContent"
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index a15f796da9..315cdadf9d 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -389,6 +389,7 @@ export default {
noFilteredRows: "No rows match the filter",
noFilteredRowsDescription: "Adjust the search text or row status filter.",
copy: "Copy",
+ copyDdl: "Copy DDL",
copyCell: "Copy Cell",
copyRow: "Copy Row (JSON)",
copyColumnJson: "Copy Column (JSON)",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 142766ce1c..5da148763a 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -387,6 +387,7 @@ export default {
noFilteredRows: "Ninguna fila coincide con el filtro",
noFilteredRowsDescription: "Ajusta el texto de búsqueda o el filtro de estado de filas.",
copy: "Copiar",
+ copyDdl: "Copiar DDL",
copyCell: "Copiar celda",
copyRow: "Copiar fila (JSON)",
copyColumnJson: "Copiar columna (JSON)",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 973ca9bfcb..c16a0f923b 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -385,6 +385,7 @@ export default {
noFilteredRows: "没有符合条件的行",
noFilteredRowsDescription: "调整搜索词或状态筛选试试。",
copy: "复制",
+ copyDdl: "复制 DDL",
copyCell: "复制单元格",
copyRow: "复制行 (JSON)",
copyColumnJson: "复制列 (JSON)",
diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.ts
index 9aa105527b..b4fad69df5 100644
--- a/apps/desktop/src/stores/settingsStore.ts
+++ b/apps/desktop/src/stores/settingsStore.ts
@@ -183,6 +183,8 @@ export interface EditorSettings {
mongoViewMode: "document" | "table";
showColumnCommentsInHeader: boolean;
compactColumnHeaderActions: boolean;
+ tableInfoDrawerWidth: number;
+ cellDetailDrawerWidth: number;
shortcuts: ShortcutSettings;
sidebarActivation: SidebarActivation;
sidebarObjectDisplay: "grouped" | "simple";
@@ -233,6 +235,8 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
mongoViewMode: "document",
showColumnCommentsInHeader: false,
compactColumnHeaderActions: true,
+ tableInfoDrawerWidth: 320,
+ cellDetailDrawerWidth: 320,
shortcuts: normalizeShortcutSettings(),
sidebarActivation: "single",
sidebarObjectDisplay: "grouped",
@@ -254,6 +258,11 @@ function normalizeUiScale(value: unknown): number {
return Math.min(MAX_UI_SCALE, Math.max(MIN_UI_SCALE, Math.round(value * 100) / 100));
}
+function normalizeDrawerWidth(value: unknown, min: number, fallback: number): number {
+ if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
+ return Math.min(900, Math.max(min, Math.round(value)));
+}
+
function normalizeColumnFormatters(value: unknown): Record<string, ColumnFormatterConfig> {
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
const formatters: Record<string, ColumnFormatterConfig> = {};
@@ -317,6 +326,16 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
settings.showColumnCommentsInHeader ?? DEFAULT_EDITOR_SETTINGS.showColumnCommentsInHeader,
compactColumnHeaderActions:
settings.compactColumnHeaderActions ?? DEFAULT_EDITOR_SETTINGS.compactColumnHeaderActions,
+ tableInfoDrawerWidth: normalizeDrawerWidth(
+ settings.tableInfoDrawerWidth,
+ 240,
+ DEFAULT_EDITOR_SETTINGS.tableInfoDrawerWidth,
+ ),
+ cellDetailDrawerWidth: normalizeDrawerWidth(
+ settings.cellDetailDrawerWidth,
+ 260,
+ DEFAULT_EDITOR_SETTINGS.cellDetailDrawerWidth,
+ ),
shortcuts: normalizeShortcutSettings(settings.shortcuts),
sidebarActivation:
settings.sidebarActivation === "single" || settings.sidebarActivation === "double"
@@ -447,6 +466,10 @@ export const useSettingsStore = defineStore("settings", () => {
editorSettings.value.showColumnCommentsInHeader = partial.showColumnCommentsInHeader;
if (partial.compactColumnHeaderActions !== undefined)
editorSettings.value.compactColumnHeaderActions = partial.compactColumnHeaderActions;
+ if (partial.tableInfoDrawerWidth !== undefined)
+ editorSettings.value.tableInfoDrawerWidth = normalizeDrawerWidth(partial.tableInfoDrawerWidth, 240, 320);
+ if (partial.cellDetailDrawerWidth !== undefined)
+ editorSettings.value.cellDetailDrawerWidth = normalizeDrawerWidth(partial.cellDetailDrawerWidth, 260, 320);
if (partial.shortcuts !== undefined) editorSettings.value.shortcuts = normalizeShortcutSettings(partial.shortcuts);
if (partial.sidebarActivation !== undefined) editorSettings.value.sidebarActivation = partial.sidebarActivation;
if (partial.sidebarObjectDisplay !== undefined)
diff --git a/packages/app-tests/settingsStore.test.ts b/packages/app-tests/settingsStore.test.ts
index 75d26563df..b499ccc84e 100644
--- a/packages/app-tests/settingsStore.test.ts
+++ b/packages/app-tests/settingsStore.test.ts
@@ -93,6 +93,17 @@ test("keeps saved data grid header display settings", () => {
assert.equal(settings.compactColumnHeaderActions, false);
});
+test("normalizes grid drawer widths", () => {
+ assert.equal(DEFAULT_EDITOR_SETTINGS.tableInfoDrawerWidth, 320);
+ assert.equal(DEFAULT_EDITOR_SETTINGS.cellDetailDrawerWidth, 320);
+ assert.equal(normalizeEditorSettings({}).tableInfoDrawerWidth, 320);
+ assert.equal(normalizeEditorSettings({}).cellDetailDrawerWidth, 320);
+ assert.equal(normalizeEditorSettings({ tableInfoDrawerWidth: 200 } as any).tableInfoDrawerWidth, 240);
+ assert.equal(normalizeEditorSettings({ cellDetailDrawerWidth: 200 } as any).cellDetailDrawerWidth, 260);
+ assert.equal(normalizeEditorSettings({ tableInfoDrawerWidth: 1000 } as any).tableInfoDrawerWidth, 900);
+ assert.equal(normalizeEditorSettings({ cellDetailDrawerWidth: 456.7 } as any).cellDetailDrawerWidth, 457);
+});
+
test("keeps saved active tab sidebar selection", () => {
assert.equal(normalizeEditorSettings({ autoSelectActiveSidebarNode: true } as any).autoSelectActiveSidebarNode, true);
});