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): keep select all inside cell details

t8y27c0fd73f7d93
diff --git a/apps/desktop/src/composables/__tests__/useCellDetailEditor.spec.ts b/apps/desktop/src/composables/__tests__/useCellDetailEditor.spec.ts
new file mode 100644
index 0000000000..b0b1329d06
--- /dev/null
+++ b/apps/desktop/src/composables/__tests__/useCellDetailEditor.spec.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it, vi } from "vitest";
+import { EditorState } from "@codemirror/state";
+import { selectAllCellDetailText } from "@/lib/dataGrid/cellDetailSelection";
+
+describe("selectAllCellDetailText", () => {
+ it("selects the entire cell detail document", () => {
+ const state = EditorState.create({ doc: '{"name":"收入合同"}' });
+ const dispatch = vi.fn();
+
+ expect(selectAllCellDetailText({ state, dispatch } as any)).toBe(true);
+ expect(dispatch).toHaveBeenCalledWith({ selection: { anchor: 0, head: state.doc.length } });
+ });
+
+ it("handles empty cell values", () => {
+ const state = EditorState.create({ doc: "" });
+ const dispatch = vi.fn();
+
+ selectAllCellDetailText({ state, dispatch } as any);
+ expect(dispatch).toHaveBeenCalledWith({ selection: { anchor: 0, head: 0 } });
+ });
+});
diff --git a/apps/desktop/src/composables/useCellDetailEditor.ts b/apps/desktop/src/composables/useCellDetailEditor.ts
index a63ae1c5be..6d116bedbf 100644
--- a/apps/desktop/src/composables/useCellDetailEditor.ts
+++ b/apps/desktop/src/composables/useCellDetailEditor.ts
@@ -15,6 +15,7 @@ import i18n from "@/i18n";
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
import type { EditorTheme } from "@/stores/settingsStore";
import type { AppThemeAppearance, AppThemePalette } from "@/lib/app/appTheme";
+import { selectAllCellDetailText } from "@/lib/dataGrid/cellDetailSelection";
export interface UseCellDetailEditorOptions {
onChange?: (value: string) => void;
@@ -198,6 +199,10 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
themeComp.of(theme),
fontThemeComp.of(fontTheme),
keymap.of([
+ {
+ key: "Mod-a",
+ run: selectAllCellDetailText,
+ },
{
key: "Escape",
run: () => {
@@ -227,6 +232,9 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
}),
EditorState.readOnly.of(!!options.readOnly),
EditorView.editable.of(!options.readOnly),
+ // Read-only CodeMirror content is not editable or focusable by default.
+ // Keep it keyboard-focusable so selection shortcuts stay inside the detail value.
+ EditorView.contentAttributes.of(options.readOnly ? { tabindex: "0" } : {}),
],
});
diff --git a/apps/desktop/src/lib/dataGrid/cellDetailSelection.ts b/apps/desktop/src/lib/dataGrid/cellDetailSelection.ts
new file mode 100644
index 0000000000..cb40b2c18d
--- /dev/null
+++ b/apps/desktop/src/lib/dataGrid/cellDetailSelection.ts
@@ -0,0 +1,9 @@
+interface CellDetailSelectionEditor {
+ state: { doc: { length: number } };
+ dispatch(spec: { selection: { anchor: number; head: number } }): void;
+}
+
+export function selectAllCellDetailText(editor: CellDetailSelectionEditor): boolean {
+ editor.dispatch({ selection: { anchor: 0, head: editor.state.doc.length } });
+ return true;
+}