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(grid): auto-fold super long single-line cell values

弈秋d9f57be5316a
diff --git a/apps/desktop/src/components/grid/__tests__/DataGridCellDetailWordWrap.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridCellDetailWordWrap.spec.ts
index 27dde284a6..b0f31ecde8 100644
--- a/apps/desktop/src/components/grid/__tests__/DataGridCellDetailWordWrap.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/DataGridCellDetailWordWrap.spec.ts
@@ -128,6 +128,69 @@ describe("DataGrid cell editor and value editor word wrap (#10506)", () => {
host.remove();
});
+ it("auto-wraps a super long single-line value even when wordWrap is off (#12320)", async () => {
+ const settingsStore = useSettingsStore();
+ settingsStore.editorSettings.wordWrap = false;
+
+ const host = document.createElement("div");
+ document.body.append(host);
+
+ const editor = useCellDetailEditor({
+ editorTheme: () => "default",
+ appAppearance: () => "light",
+ appPalette: () => ({}) as any,
+ fontSize: () => 13,
+ fontFamily: () => "monospace",
+ });
+
+ await editor.create(host, "z".repeat(400));
+ const cmContent = host.querySelector(".cm-content");
+ expect(cmContent).not.toBeNull();
+ expect(cmContent?.classList.contains("cm-lineWrapping")).toBe(true);
+
+ // Shortening the value below the threshold releases the automatic fold.
+ editor.setValue("z".repeat(40));
+ await nextTick();
+ expect(cmContent?.classList.contains("cm-lineWrapping")).toBe(false);
+
+ // Growing it back into a super long single line folds it again.
+ editor.setValue("z".repeat(400));
+ await nextTick();
+ expect(cmContent?.classList.contains("cm-lineWrapping")).toBe(true);
+
+ editor.destroy();
+ host.remove();
+ });
+
+ it("keeps multi-line documents under the user's wrap choice even when long", async () => {
+ const settingsStore = useSettingsStore();
+ settingsStore.editorSettings.wordWrap = false;
+
+ const host = document.createElement("div");
+ document.body.append(host);
+
+ const editor = useCellDetailEditor({
+ editorTheme: () => "default",
+ appAppearance: () => "light",
+ appPalette: () => ({}) as any,
+ fontSize: () => 13,
+ fontFamily: () => "monospace",
+ });
+
+ await editor.create(host, `{"payload":"${"v".repeat(300)}"}\ntrailing`);
+ const cmContent = host.querySelector(".cm-content");
+ expect(cmContent).not.toBeNull();
+ expect(cmContent?.classList.contains("cm-lineWrapping")).toBe(false);
+
+ // Explicit toggle still wins for multi-line content.
+ settingsStore.editorSettings.wordWrap = true;
+ await nextTick();
+ expect(cmContent?.classList.contains("cm-lineWrapping")).toBe(true);
+
+ editor.destroy();
+ host.remove();
+ });
+
it("renders word wrap toggle button in DataGridCellDetailHeader and updates settingsStore", async () => {
const settingsStore = useSettingsStore();
settingsStore.editorSettings.wordWrap = false;
diff --git a/apps/desktop/src/composables/useCellDetailEditor.ts b/apps/desktop/src/composables/useCellDetailEditor.ts
index f66044b34d..b08731601d 100644
--- a/apps/desktop/src/composables/useCellDetailEditor.ts
+++ b/apps/desktop/src/composables/useCellDetailEditor.ts
@@ -19,6 +19,7 @@ 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";
+import { shouldAutoWrapLongSingleLine } from "@/lib/dataGrid/cellDetailWordWrap";
import { selectLineEnds } from "@/lib/editor/selectLineEnds";
import { preserveSourceHistory, rawSourceField, restoreRawSource } from "@/lib/editor/preserveTextLineEndings";
@@ -92,6 +93,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
let destroyed = false;
let synchronizingValue = false;
let currentIsJson = false;
+ let appliedLineWrapping: boolean | null = null;
let liveFontSize = clampEditorFontSize(options.fontSize());
let gestureStartFontSize = liveFontSize;
let isGestureZooming = false;
@@ -121,6 +123,22 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
return typeof options.lineWrapping === "function" ? options.lineWrapping() : settingsStore.editorSettings.wordWrap;
}
+ /**
+ * Effective wrapping for the current document: the caller's explicit wrap
+ * choice, plus automatic folding of super long single-line values (#12320)
+ * so they are readable without dragging the horizontal scrollbar.
+ */
+ function shouldWrapDoc(doc: string): boolean {
+ return isLineWrapping() || shouldAutoWrapLongSingleLine(doc);
+ }
+
+ function applyLineWrapping(doc: string): boolean {
+ const wrap = shouldWrapDoc(doc);
+ if (wrap === appliedLineWrapping) return false;
+ appliedLineWrapping = wrap;
+ return true;
+ }
+
function readOnlyExtensions(readOnly: boolean) {
return [EditorState.readOnly.of(readOnly), EditorView.editable.of(!readOnly), EditorView.contentAttributes.of(readOnly ? { tabindex: "0" } : {})];
}
@@ -188,10 +206,12 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
watch(
() => isLineWrapping(),
- (lineWrapping) => {
+ () => {
const editor = view.value;
if (!editor || destroyed) return;
- editor.dispatch({ effects: lineWrappingComp.reconfigure(lineWrapping ? EditorView.lineWrapping : []) });
+ const doc = editor.state.doc.toString();
+ if (!applyLineWrapping(doc)) return;
+ editor.dispatch({ effects: lineWrappingComp.reconfigure(appliedLineWrapping ? EditorView.lineWrapping : []) });
},
);
@@ -224,6 +244,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
liveFontSize = clampEditorFontSize(options.fontSize());
const fontTheme = editorFontTheme(EditorView, liveFontSize, options.fontFamily(), { fixedHeight: true, scrollable: true });
const shortcuts = settingsStore.editorSettings.shortcuts;
+ appliedLineWrapping = shouldWrapDoc(doc);
const state = EditorState.create({
doc,
@@ -274,7 +295,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
]),
]),
languageComp.of(currentIsJson ? json() : []),
- lineWrappingComp.of(isLineWrapping() ? EditorView.lineWrapping : []),
+ lineWrappingComp.of(shouldWrapDoc(doc) ? EditorView.lineWrapping : []),
readOnlyComp.of(readOnlyExtensions(isReadOnly())),
themeComp.of(theme),
fontThemeComp.of(fontTheme),
@@ -295,11 +316,17 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
]),
EditorView.updateListener.of((update) => {
if (update.docChanged) {
+ const nextDoc = update.state.doc.toString();
+ // Auto-wrap (#12320) flips with the document itself: a single long
+ // line folds, then un-folds again as soon as the user breaks it up.
+ if (applyLineWrapping(nextDoc)) {
+ update.view.dispatch({ effects: lineWrappingComp.reconfigure(appliedLineWrapping ? EditorView.lineWrapping : []) });
+ }
if (options.preserveLineEndings) {
if (synchronizingValue) return;
options.onChange?.(update.state.field(rawSourceField));
} else {
- options.onChange?.(update.state.doc.toString());
+ options.onChange?.(nextDoc);
}
}
}),
diff --git a/apps/desktop/src/lib/dataGrid/__tests__/cellDetailWordWrap.spec.ts b/apps/desktop/src/lib/dataGrid/__tests__/cellDetailWordWrap.spec.ts
new file mode 100644
index 0000000000..142ae3945a
--- /dev/null
+++ b/apps/desktop/src/lib/dataGrid/__tests__/cellDetailWordWrap.spec.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from "vitest";
+import { CELL_DETAIL_AUTO_WRAP_MIN_LENGTH, shouldAutoWrapLongSingleLine } from "../cellDetailWordWrap";
+
+describe("shouldAutoWrapLongSingleLine (#12320)", () => {
+ it("wraps a single-line value that exceeds the viewport threshold", () => {
+ expect(shouldAutoWrapLongSingleLine("x".repeat(CELL_DETAIL_AUTO_WRAP_MIN_LENGTH))).toBe(true);
+ expect(shouldAutoWrapLongSingleLine("y".repeat(500))).toBe(true);
+ });
+
+ it("keeps short single-line values unwrapped so the toggle semantics stay intact", () => {
+ expect(shouldAutoWrapLongSingleLine("")).toBe(false);
+ expect(shouldAutoWrapLongSingleLine("short value")).toBe(false);
+ expect(shouldAutoWrapLongSingleLine("x".repeat(CELL_DETAIL_AUTO_WRAP_MIN_LENGTH - 1))).toBe(false);
+ });
+
+ it("never forces wrapping on multi-line documents", () => {
+ const longPrefix = "x".repeat(CELL_DETAIL_AUTO_WRAP_MIN_LENGTH);
+ expect(shouldAutoWrapLongSingleLine(`${longPrefix}\nnext line`)).toBe(false);
+ expect(shouldAutoWrapLongSingleLine(`${longPrefix}\r\nnext line`)).toBe(false);
+ // Pretty-printed JSON is multi-line; users who want it folded still have the global toggle.
+ expect(shouldAutoWrapLongSingleLine(`{\n "k": "${"v".repeat(300)}"\n}`)).toBe(false);
+ });
+
+ it("wraps a minified single-line JSON blob", () => {
+ expect(shouldAutoWrapLongSingleLine(`{"payload":"${"v".repeat(300)}"}`)).toBe(true);
+ });
+});
diff --git a/apps/desktop/src/lib/dataGrid/cellDetailWordWrap.ts b/apps/desktop/src/lib/dataGrid/cellDetailWordWrap.ts
new file mode 100644
index 0000000000..aa3129fc73
--- /dev/null
+++ b/apps/desktop/src/lib/dataGrid/cellDetailWordWrap.ts
@@ -0,0 +1,17 @@
+/**
+ * Automatic word wrap for the cell-detail value editor (#12320).
+ *
+ * The global `editorSettings.wordWrap` toggle already wraps everything when
+ * enabled, but it defaults to off, so a super long single-line value still
+ * forces horizontal scrolling. When wrap is off, fold any single-line document
+ * that is long enough to exceed a comfortable viewport width.
+ *
+ * Multi-line documents (including pretty-printed JSON) keep the user's choice
+ * untouched so the toggle semantics stay predictable.
+ */
+export const CELL_DETAIL_AUTO_WRAP_MIN_LENGTH = 160;
+
+export function shouldAutoWrapLongSingleLine(doc: string): boolean {
+ if (doc.length < CELL_DETAIL_AUTO_WRAP_MIN_LENGTH) return false;
+ return !doc.includes("\n") && !doc.includes("\r");
+}