fix(editor): wrap generated SQL templates

This commit is contained in:
Melody Ruch authored and GitHub committed 2026-08-13 19:27:37 +08:00
1 parent 84beec5136
commit 68c22e878b
5 files changed
+55 -2

No files matched your search

@@ -1060,6 +1060,7 @@ defineExpose({ focusSearch, refreshData, refreshQueryEditorCompletionCache, hand
:statement-execution-markers="activeStatementExecutionMarkers"
:initial-viewport="activeTab.editorViewport"
:initial-selection="activeTab.editorSelection"
:force-word-wrap="activeTab.forceWordWrap"
@update:model-value="emit('editorUpdate', activeTab.id, $event)"
@selection-change="emit('editorSelectionChange', $event)"
@send-selection-to-ai="emit('sendSelectionToAi', $event)"
@@ -1529,7 +1529,7 @@ async function loadTemplateContext(allowView = false) {
}
function openSqlTemplateTab(connectionId: string, database: string, schema: string | undefined, catalog: string | undefined, sql: string, title?: string) {
const tabId = queryStore.createTab(connectionId, database, title, "query", schema, undefined, catalog);
const tabId = queryStore.createTab(connectionId, database, title, "query", schema, undefined, catalog, { forceWordWrap: true });
queryStore.updateSql(tabId, sql);
}
@@ -0,0 +1,49 @@
import { readFileSync } from "node:fs";
import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, it, vi } from "vitest";
describe("queryStore createTab forceWordWrap", () => {
beforeEach(() => {
vi.resetModules();
vi.unstubAllGlobals();
vi.stubGlobal("localStorage", {
getItem: vi.fn(() => null),
setItem: vi.fn(),
removeItem: vi.fn(),
});
setActivePinia(createPinia());
});
it("defaults new tabs to no forced word wrap", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const queryStore = useQueryStore();
const tabId = queryStore.createTab("pg-1", "app", "Query");
const tab = queryStore.tabs.find((t) => t.id === tabId);
expect(tab?.forceWordWrap).toBeFalsy();
});
it("marks a tab as force-wrapped when requested via options", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const queryStore = useQueryStore();
const tabId = queryStore.createTab("pg-1", "app", "SELECT users", "query", undefined, undefined, undefined, { forceNew: true, forceWordWrap: true });
const tab = queryStore.tabs.find((t) => t.id === tabId);
expect(tab?.forceWordWrap).toBe(true);
});
});
describe("Generate SQL template tabs wire forceWordWrap end to end (issue #6038)", () => {
const sidebarSource = readFileSync(new URL("../../components/sidebar/SidebarTreeRuntimeHost.vue", import.meta.url), "utf8");
const contentAreaSource = readFileSync(new URL("../../components/layout/ContentArea.vue", import.meta.url), "utf8");
it("openSqlTemplateTab requests forceWordWrap when creating the tab", () => {
expect(sidebarSource).toMatch(/function openSqlTemplateTab\([^)]*\)\s*{[\s\S]*?createTab\([^)]*forceWordWrap:\s*true[^)]*\)/);
});
it("ContentArea forwards the tab's forceWordWrap flag into QueryEditor", () => {
expect(contentAreaSource).toMatch(/<QueryEditor[\s\S]*?:force-word-wrap="activeTab\.forceWordWrap"/);
});
});
+2 -1
View File
@@ -1607,7 +1607,7 @@ export const useQueryStore = defineStore("query", () => {
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || "") && (tab.catalog || "") === (catalog || ""));
}
function createTab(connectionId: string, database: string, title?: string, mode: QueryTab["mode"] = "query", schema?: string, initialSql?: string, catalog?: string, options: { forceNew?: boolean; activate?: boolean } = {}) {
function createTab(connectionId: string, database: string, title?: string, mode: QueryTab["mode"] = "query", schema?: string, initialSql?: string, catalog?: string, options: { forceNew?: boolean; activate?: boolean; forceWordWrap?: boolean } = {}) {
if (title && !options.forceNew) {
const existing = findTabByIdentity(connectionId, database, title, mode, schema, catalog);
if (existing) {
@@ -1621,6 +1621,7 @@ export const useQueryStore = defineStore("query", () => {
id,
title: title || `query_${tabs.value.length + 1}`,
customTitle: mode === "query" && !!title ? true : undefined,
forceWordWrap: options.forceWordWrap,
connectionId,
database,
schema,
+2
View File
@@ -1078,6 +1078,8 @@ export interface QueryTab {
id: string;
title: string;
customTitle?: boolean;
/** Force the editor to word-wrap regardless of the global setting, e.g. for auto-generated single-line templates. */
forceWordWrap?: boolean;
connectionId: string;
database: string;
schema?: string;