feat(grid): support custom result grid font

This commit is contained in:
t8y2 committed 2026-07-22 19:10:23 +08:00
1 parent bd81c8f52e
commit ae7c368c4a
15 files changed
+163 -32

No files matched your search

@@ -264,6 +264,7 @@ function createEmptyTableColumnTemplateRow(): TableColumnTemplateGridRow {
// Local edit state // Local edit state
const editFontFamily = ref(settingsStore.editorSettings.fontFamily); const editFontFamily = ref(settingsStore.editorSettings.fontFamily);
const editFontSize = ref(settingsStore.editorSettings.fontSize); const editFontSize = ref(settingsStore.editorSettings.fontSize);
const editTableFontFamily = ref(settingsStore.editorSettings.tableFontFamily);
const editUiFontFamily = ref(settingsStore.editorSettings.uiFontFamily); const editUiFontFamily = ref(settingsStore.editorSettings.uiFontFamily);
const editUiScale = ref(settingsStore.editorSettings.uiScale); const editUiScale = ref(settingsStore.editorSettings.uiScale);
const editTheme = ref(settingsStore.editorSettings.theme); const editTheme = ref(settingsStore.editorSettings.theme);
@@ -418,6 +419,7 @@ function currentEditorSettingsDraft(): EditorSettingsDraft {
return { return {
fontFamily: editFontFamily.value, fontFamily: editFontFamily.value,
fontSize: editFontSize.value, fontSize: editFontSize.value,
tableFontFamily: editTableFontFamily.value,
uiFontFamily: editUiFontFamily.value, uiFontFamily: editUiFontFamily.value,
uiScale: editUiScale.value, uiScale: editUiScale.value,
theme: editTheme.value, theme: editTheme.value,
@@ -651,6 +653,7 @@ const systemFontOptions = computed(() => {
const options = new Set(FONT_FAMILIES.map((font) => font.value)); const options = new Set(FONT_FAMILIES.map((font) => font.value));
for (const font of systemFonts.value) options.add(cssFontFamilyForName(font)); for (const font of systemFonts.value) options.add(cssFontFamilyForName(font));
if (editFontFamily.value) options.add(editFontFamily.value); if (editFontFamily.value) options.add(editFontFamily.value);
if (editTableFontFamily.value) options.add(editTableFontFamily.value);
return [...options]; return [...options];
}); });
@@ -698,6 +701,7 @@ async function loadSystemFontOptions() {
function syncEditorSettingsDraftFromStore() { function syncEditorSettingsDraftFromStore() {
editFontFamily.value = settingsStore.editorSettings.fontFamily; editFontFamily.value = settingsStore.editorSettings.fontFamily;
editFontSize.value = settingsStore.editorSettings.fontSize; editFontSize.value = settingsStore.editorSettings.fontSize;
editTableFontFamily.value = settingsStore.editorSettings.tableFontFamily;
editUiFontFamily.value = settingsStore.editorSettings.uiFontFamily; editUiFontFamily.value = settingsStore.editorSettings.uiFontFamily;
editUiScale.value = settingsStore.editorSettings.uiScale; editUiScale.value = settingsStore.editorSettings.uiScale;
editTheme.value = settingsStore.editorSettings.theme; editTheme.value = settingsStore.editorSettings.theme;
@@ -915,6 +919,7 @@ function resetDefaultsForTab(tab: SettingsCategory) {
editSqlFormatter.value = normalizeSqlFormatterSettings(DEFAULT_EDITOR_SETTINGS.sqlFormatter); editSqlFormatter.value = normalizeSqlFormatterSettings(DEFAULT_EDITOR_SETTINGS.sqlFormatter);
sqlFormatterConfigValid.value = true; sqlFormatterConfigValid.value = true;
} else if (tab === "appearance") { } else if (tab === "appearance") {
editTableFontFamily.value = DEFAULT_EDITOR_SETTINGS.tableFontFamily;
editUiFontFamily.value = DEFAULT_EDITOR_SETTINGS.uiFontFamily; editUiFontFamily.value = DEFAULT_EDITOR_SETTINGS.uiFontFamily;
editUiScale.value = DEFAULT_EDITOR_SETTINGS.uiScale; editUiScale.value = DEFAULT_EDITOR_SETTINGS.uiScale;
editTheme.value = DEFAULT_EDITOR_SETTINGS.theme; editTheme.value = DEFAULT_EDITOR_SETTINGS.theme;
@@ -973,6 +978,7 @@ function resetDefaultsForTab(tab: SettingsCategory) {
function resetAllDefaults() { function resetAllDefaults() {
editFontFamily.value = DEFAULT_EDITOR_SETTINGS.fontFamily; editFontFamily.value = DEFAULT_EDITOR_SETTINGS.fontFamily;
editFontSize.value = DEFAULT_EDITOR_SETTINGS.fontSize; editFontSize.value = DEFAULT_EDITOR_SETTINGS.fontSize;
editTableFontFamily.value = DEFAULT_EDITOR_SETTINGS.tableFontFamily;
editUiFontFamily.value = DEFAULT_EDITOR_SETTINGS.uiFontFamily; editUiFontFamily.value = DEFAULT_EDITOR_SETTINGS.uiFontFamily;
editUiScale.value = DEFAULT_EDITOR_SETTINGS.uiScale; editUiScale.value = DEFAULT_EDITOR_SETTINGS.uiScale;
editTheme.value = DEFAULT_EDITOR_SETTINGS.theme; editTheme.value = DEFAULT_EDITOR_SETTINGS.theme;
@@ -1174,6 +1180,10 @@ function onFontFamilyChange(v: any) {
if (typeof v === "string") editFontFamily.value = v; if (typeof v === "string") editFontFamily.value = v;
} }
function onTableFontFamilyChange(v: any) {
if (typeof v === "string") editTableFontFamily.value = v;
}
function onUiFontFamilyChange(v: any) { function onUiFontFamilyChange(v: any) {
if (typeof v === "string") editUiFontFamily.value = v; if (typeof v === "string") editUiFontFamily.value = v;
} }
@@ -3430,7 +3440,7 @@ onUnmounted(cleanupPreviewEditor);
<SqlFormatterSettingsPanel v-model="editSqlFormatter" @validity-change="(value: boolean) => (sqlFormatterConfigValid = value)" /> <SqlFormatterSettingsPanel v-model="editSqlFormatter" @validity-change="(value: boolean) => (sqlFormatterConfigValid = value)" />
</section> </section>
<section v-else-if="activeSettingsTab === 'appearance'" class="settings-appearance-section flex flex-col gap-5 py-2"> <section v-else-if="activeSettingsTab === 'appearance'" class="settings-appearance-section flex flex-col gap-4 py-2">
<div class="settings-appearance-top-grid"> <div class="settings-appearance-top-grid">
<div class="settings-appearance-field min-w-0"> <div class="settings-appearance-field min-w-0">
<div class="flex h-9 items-end"> <div class="flex h-9 items-end">
@@ -3485,7 +3495,36 @@ onUnmounted(cleanupPreviewEditor);
</div> </div>
<div class="settings-appearance-field min-w-0"> <div class="settings-appearance-field min-w-0">
<div class="flex h-9 items-end gap-1"> <div class="flex h-9 items-end">
<div class="flex min-w-0 items-center gap-1">
<Label class="min-w-0 whitespace-normal leading-tight">{{ t("settings.uiScale") }}</Label>
<HelpTooltip :label="t('settings.uiScale')" trigger-class="[&_svg]:h-3 [&_svg]:w-3" content-class="max-w-64">
<p>{{ t("settings.uiScaleDescription") }}</p>
</HelpTooltip>
</div>
</div>
<Select
:model-value="String(editUiScale)"
@update:model-value="
(value: any) => {
const next = Number(value);
if (Number.isFinite(next)) editUiScale = next;
}
"
>
<SelectTrigger class="h-8 w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="scale in uiScaleOptions" :key="scale" :value="String(scale)" class="pl-2.5"> {{ Math.round(scale * 100) }}% </SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div class="grid gap-3 md:grid-cols-2">
<div class="settings-appearance-field min-w-0">
<div class="flex min-w-0 items-center gap-1">
<Label class="min-w-0 whitespace-normal leading-tight">{{ t("settings.uiFontFamily") }}</Label> <Label class="min-w-0 whitespace-normal leading-tight">{{ t("settings.uiFontFamily") }}</Label>
<HelpTooltip :label="t('settings.uiFontFamily')" trigger-class="[&_svg]:h-3 [&_svg]:w-3" content-class="max-w-64"> <HelpTooltip :label="t('settings.uiFontFamily')" trigger-class="[&_svg]:h-3 [&_svg]:w-3" content-class="max-w-64">
<p>{{ t("settings.uiFontFamilyDescription") }}</p> <p>{{ t("settings.uiFontFamilyDescription") }}</p>
@@ -3524,28 +3563,42 @@ onUnmounted(cleanupPreviewEditor);
</div> </div>
<div class="settings-appearance-field min-w-0"> <div class="settings-appearance-field min-w-0">
<div class="flex h-9 items-end gap-1"> <div class="flex min-w-0 items-center gap-1">
<Label class="min-w-0 whitespace-normal leading-tight">{{ t("settings.uiScale") }}</Label> <Label class="min-w-0 whitespace-normal leading-tight">{{ t("settings.dataGridFontFamily") }}</Label>
<HelpTooltip :label="t('settings.uiScale')" trigger-class="[&_svg]:h-3 [&_svg]:w-3" content-class="max-w-64"> <HelpTooltip :label="t('settings.dataGridFontFamily')" trigger-class="[&_svg]:h-3 [&_svg]:w-3" content-class="max-w-64">
<p>{{ t("settings.uiScaleDescription") }}</p> <p>{{ t("settings.dataGridFontFamilyDescription") }}</p>
</HelpTooltip> </HelpTooltip>
</div> </div>
<Select <SearchableSelect
:model-value="String(editUiScale)" :model-value="editTableFontFamily"
@update:model-value=" :options="systemFontOptions"
(value: any) => { :placeholder="t('settings.selectFont')"
const next = Number(value); :search-placeholder="t('settings.searchFont')"
if (Number.isFinite(next)) editUiScale = next; :empty-text="t('settings.noFontsFound')"
} :loading-text="t('settings.loadingFonts')"
" allow-custom
:display-name="displayFontFamily"
:normalize-custom="normalizeCustomFontFamilyInput"
:trigger-class="appearanceFontSearchTriggerClass"
:trigger-icon-class="appearanceFontSearchTriggerIconClass"
content-class="w-[var(--reka-popover-trigger-width)] min-w-[260px]"
@update:model-value="onTableFontFamilyChange"
@update:open="(open: boolean) => open && loadSystemFontOptions()"
> >
<SelectTrigger class="h-8 w-full"> <template #trigger-label="{ label, loading }">
<SelectValue /> <span class="truncate" :style="{ fontFamily: editTableFontFamily }">
</SelectTrigger> {{ loading ? t("settings.loadingFonts") : label }}
<SelectContent> </span>
<SelectItem v-for="scale in uiScaleOptions" :key="scale" :value="String(scale)" class="pl-2.5"> {{ Math.round(scale * 100) }}% </SelectItem> </template>
</SelectContent> <template #option-label="{ option, label }">
</Select> <span class="truncate" :style="fontOptionStyle(option, editTableFontFamily)">{{ label }}</span>
</template>
<template #custom-option-label="{ value }">
<span class="truncate" :style="{ fontFamily: value }">
{{ t("settings.useCustomFont", { font: readableFontFamily(value) }) }}
</span>
</template>
</SearchableSelect>
</div> </div>
</div> </div>
@@ -5712,13 +5765,9 @@ onUnmounted(cleanupPreviewEditor);
box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.45) !important; box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.45) !important;
} }
.settings-appearance-section > * + * {
margin-top: 1.25rem;
}
.settings-appearance-top-grid { .settings-appearance-top-grid {
display: grid; display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-columns: repeat(3, minmax(0, 1fr));
column-gap: 0.75rem; column-gap: 0.75rem;
row-gap: 1rem; row-gap: 1rem;
} }
@@ -1785,9 +1785,10 @@ function scrollToColumnIndex(columnIndex: number) {
// --- Column resize composable --- // --- Column resize composable ---
const columnWidthDensity = computed(() => settingsStore.editorSettings.columnWidthDensity); const columnWidthDensity = computed(() => settingsStore.editorSettings.columnWidthDensity);
const tableFontFamily = computed(() => settingsStore.editorSettings.tableFontFamily);
const columnWidthCacheKey = computed(() => props.cacheKey?.trim() || undefined); const columnWidthCacheKey = computed(() => props.cacheKey?.trim() || undefined);
const columnStructureSignature = computed(() => createDataGridColumnStructureSignature(props.result.columns, props.result.column_types)); const columnStructureSignature = computed(() => createDataGridColumnStructureSignature(props.result.columns, props.result.column_types));
const columnHeaderMeasurementKey = computed(() => [tableFontSize.value, settingsStore.editorSettings.fontFamily]); const columnHeaderMeasurementKey = computed(() => [tableFontSize.value, tableFontFamily.value]);
let columnHeaderMeasureContext: CanvasRenderingContext2D | null | undefined; let columnHeaderMeasureContext: CanvasRenderingContext2D | null | undefined;
function measureColumnHeaderText(text: string): number | undefined { function measureColumnHeaderText(text: string): number | undefined {
@@ -1795,8 +1796,7 @@ function measureColumnHeaderText(text: string): number | undefined {
if (columnHeaderMeasureContext === undefined) columnHeaderMeasureContext = document.createElement("canvas").getContext("2d"); if (columnHeaderMeasureContext === undefined) columnHeaderMeasureContext = document.createElement("canvas").getContext("2d");
if (!columnHeaderMeasureContext) return undefined; if (!columnHeaderMeasureContext) return undefined;
// Match the rendered semibold header font instead of estimating proportional glyphs by character count. // Match the rendered semibold header font instead of estimating proportional glyphs by character count.
const fontFamily = getComputedStyle(gridRef.value ?? document.body).fontFamily || "sans-serif"; columnHeaderMeasureContext.font = `600 ${tableFontSize.value}px ${tableFontFamily.value}`;
columnHeaderMeasureContext.font = `600 ${tableFontSize.value}px ${fontFamily}`;
return Math.ceil(columnHeaderMeasureContext.measureText(text).width); return Math.ceil(columnHeaderMeasureContext.measureText(text).width);
} }
@@ -1816,6 +1816,7 @@ const gridStyle = computed(() => ({
"--header-total-w": dataGridHeaderContentWidth("var(--total-w)", gridScrollbarGutter.value), "--header-total-w": dataGridHeaderContentWidth("var(--total-w)", gridScrollbarGutter.value),
"--grid-scrollbar-gutter": `${gridScrollbarGutter.value}px`, "--grid-scrollbar-gutter": `${gridScrollbarGutter.value}px`,
[EDITOR_FONT_FAMILY_CSS_VAR]: settingsStore.editorSettings.fontFamily, [EDITOR_FONT_FAMILY_CSS_VAR]: settingsStore.editorSettings.fontFamily,
"--dbx-data-grid-font-family": tableFontFamily.value,
"--dbx-table-font-size": `${tableFontSize.value}px`, "--dbx-table-font-size": `${tableFontSize.value}px`,
})); }));
const gridHorizontalScrollLeft = ref(0); const gridHorizontalScrollLeft = ref(0);
@@ -4384,7 +4385,7 @@ const canvasSurfaceWidth = computed(() => {
if (vw <= 0) return total; if (vw <= 0) return total;
return Math.min(vw, total); return Math.min(vw, total);
}); });
const canvasRenderStyleKey = computed(() => `${settingsStore.editorSettings.theme}:${settingsStore.editorSettings.uiScale}:${canvasBackingPixelRatio.value}:${isDark.value}:${themePalette.value}:${settingsStore.editorSettings.fontFamily}:${tableFontSize.value}`); const canvasRenderStyleKey = computed(() => `${settingsStore.editorSettings.theme}:${settingsStore.editorSettings.uiScale}:${canvasBackingPixelRatio.value}:${isDark.value}:${themePalette.value}:${tableFontFamily.value}:${tableFontSize.value}`);
const CANVAS_MOUSE_WHEEL_SCROLL_MULTIPLIER = 1.5; const CANVAS_MOUSE_WHEEL_SCROLL_MULTIPLIER = 1.5;
const CANVAS_TRACKPAD_DELTA_THRESHOLD = 40; const CANVAS_TRACKPAD_DELTA_THRESHOLD = 40;
let canvasPixelRatioMediaQuery: MediaQueryList | null = null; let canvasPixelRatioMediaQuery: MediaQueryList | null = null;
+2
View File
@@ -3640,6 +3640,8 @@ export default {
securityTab: "Security", securityTab: "Security",
aboutTab: "About", aboutTab: "About",
fontFamily: "Font Family", fontFamily: "Font Family",
dataGridFontFamily: "Result Grid Font",
dataGridFontFamilyDescription: "Applies to query results, table data, column headers, and inline cell editors.",
uiFontFamily: "Interface Font", uiFontFamily: "Interface Font",
uiFontAppDefault: "DBX Default", uiFontAppDefault: "DBX Default",
uiFontSystemDefault: "System Default", uiFontSystemDefault: "System Default",
+2
View File
@@ -3418,6 +3418,8 @@ export default withEnglishFallback({
securityTab: "Seguridad", securityTab: "Seguridad",
aboutTab: "Acerca de", aboutTab: "Acerca de",
fontFamily: "Familia tipográfica", fontFamily: "Familia tipográfica",
dataGridFontFamily: "Fuente de la cuadrícula de resultados",
dataGridFontFamilyDescription: "Se aplica a resultados de consultas, datos de tablas, encabezados de columnas y editores dentro de las celdas.",
uiFontFamily: "Fuente de la interfaz", uiFontFamily: "Fuente de la interfaz",
uiFontAppDefault: "Predeterminada de DBX", uiFontAppDefault: "Predeterminada de DBX",
uiFontSystemDefault: "Predeterminada del sistema", uiFontSystemDefault: "Predeterminada del sistema",
+2
View File
@@ -3416,6 +3416,8 @@ export default withEnglishFallback({
securityTab: "Sicurezza", securityTab: "Sicurezza",
aboutTab: "Informazioni", aboutTab: "Informazioni",
fontFamily: "Famiglia Carattere (Font)", fontFamily: "Famiglia Carattere (Font)",
dataGridFontFamily: "Font della griglia risultati",
dataGridFontFamilyDescription: "Si applica ai risultati delle query, ai dati delle tabelle, alle intestazioni delle colonne e agli editor nelle celle.",
uiFontFamily: "Carattere interfaccia", uiFontFamily: "Carattere interfaccia",
uiFontAppDefault: "Predefinito DBX", uiFontAppDefault: "Predefinito DBX",
uiFontSystemDefault: "Predefinito di sistema", uiFontSystemDefault: "Predefinito di sistema",
+2
View File
@@ -3417,6 +3417,8 @@ export default withEnglishFallback({
securityTab: "セキュリティ", securityTab: "セキュリティ",
aboutTab: "バージョン情報", aboutTab: "バージョン情報",
fontFamily: "フォントファミリー", fontFamily: "フォントファミリー",
dataGridFontFamily: "結果グリッドのフォント",
dataGridFontFamilyDescription: "クエリ結果、テーブルデータ、列ヘッダー、セル内エディターに適用します。",
uiFontFamily: "インターフェイスフォント", uiFontFamily: "インターフェイスフォント",
uiFontAppDefault: "DBX デフォルト", uiFontAppDefault: "DBX デフォルト",
uiFontSystemDefault: "システムデフォルト", uiFontSystemDefault: "システムデフォルト",
+2
View File
@@ -3418,6 +3418,8 @@ export default withEnglishFallback({
securityTab: "Segurança", securityTab: "Segurança",
aboutTab: "Sobre", aboutTab: "Sobre",
fontFamily: "Família da fonte", fontFamily: "Família da fonte",
dataGridFontFamily: "Fonte da grade de resultados",
dataGridFontFamilyDescription: "Aplica-se aos resultados de consultas, dados de tabelas, cabeçalhos de colunas e editores dentro das células.",
uiFontFamily: "Fonte da interface", uiFontFamily: "Fonte da interface",
uiFontAppDefault: "Padrão do DBX", uiFontAppDefault: "Padrão do DBX",
uiFontSystemDefault: "Padrão do sistema", uiFontSystemDefault: "Padrão do sistema",
+2
View File
@@ -3630,6 +3630,8 @@ export default withEnglishFallback({
securityTab: "安全", securityTab: "安全",
aboutTab: "关于我们", aboutTab: "关于我们",
fontFamily: "字体", fontFamily: "字体",
dataGridFontFamily: "查询结果网格字体",
dataGridFontFamilyDescription: "用于查询结果、表数据、列标题和单元格内编辑器。",
uiFontFamily: "界面字体", uiFontFamily: "界面字体",
uiFontAppDefault: "DBX 默认", uiFontAppDefault: "DBX 默认",
uiFontSystemDefault: "系统默认", uiFontSystemDefault: "系统默认",
+2
View File
@@ -3234,6 +3234,8 @@ export default withEnglishFallback({
tunnelsSocksConnectRejected: "SOCKS 代理連線被拒(代碼 {code})", tunnelsSocksConnectRejected: "SOCKS 代理連線被拒(代碼 {code})",
tunnelsSocksUnsupportedAddrType: "不支援的 SOCKS 綁定位址類型:{type}", tunnelsSocksUnsupportedAddrType: "不支援的 SOCKS 綁定位址類型:{type}",
fontFamily: "字型", fontFamily: "字型",
dataGridFontFamily: "查詢結果網格字型",
dataGridFontFamilyDescription: "套用於查詢結果、資料表資料、欄位標題及儲存格內編輯器。",
uiFontFamily: "介面字型", uiFontFamily: "介面字型",
uiFontAppDefault: "DBX 預設", uiFontAppDefault: "DBX 預設",
uiFontSystemDefault: "系統預設", uiFontSystemDefault: "系統預設",
+2
View File
@@ -2,5 +2,7 @@ export const APP_FONT_SANS_CSS_VAR = "--font-sans";
export const DEFAULT_UI_FONT_FAMILY = `"Geist Variable", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif`; export const DEFAULT_UI_FONT_FAMILY = `"Geist Variable", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif`;
export const DEFAULT_DATA_GRID_FONT_FAMILY = `"Geist Variable Tabular", "Geist Variable", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif`;
// Native-feeling UI option without DBX's bundled/brand font at the front of the stack. // Native-feeling UI option without DBX's bundled/brand font at the front of the stack.
export const SYSTEM_UI_FONT_FAMILY = `system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`; export const SYSTEM_UI_FONT_FAMILY = `system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`;
@@ -4,6 +4,7 @@ import { normalizeResultPageSize } from "@/lib/dataGrid/paginationPageSize";
export const EDITOR_SETTINGS_DRAFT_KEYS = [ export const EDITOR_SETTINGS_DRAFT_KEYS = [
"fontFamily", "fontFamily",
"fontSize", "fontSize",
"tableFontFamily",
"uiFontFamily", "uiFontFamily",
"uiScale", "uiScale",
"theme", "theme",
+5 -1
View File
@@ -14,7 +14,7 @@ import type { SqlSnippet } from "@/types/database";
import { DEFAULT_SQL_SNIPPETS } from "@/lib/sql/sqlCompletion"; import { DEFAULT_SQL_SNIPPETS } from "@/lib/sql/sqlCompletion";
import { setDebugLoggingEnabled } from "@/lib/backend/debugLog"; import { setDebugLoggingEnabled } from "@/lib/backend/debugLog";
import { DEFAULT_TABLE_COLUMN_TEMPLATE_FIELDS, normalizeTableColumnTemplateFields } from "@/lib/table/tableColumnTemplates"; import { DEFAULT_TABLE_COLUMN_TEMPLATE_FIELDS, normalizeTableColumnTemplateFields } from "@/lib/table/tableColumnTemplates";
import { DEFAULT_UI_FONT_FAMILY } from "@/lib/app/appFonts"; import { DEFAULT_DATA_GRID_FONT_FAMILY, DEFAULT_UI_FONT_FAMILY } from "@/lib/app/appFonts";
import { safeLocalStorageGet, safeLocalStorageRemove } from "@/lib/backend/safeStorage"; import { safeLocalStorageGet, safeLocalStorageRemove } from "@/lib/backend/safeStorage";
import type { AiProvider, AiApiStyle, AiAuthMethod, AiEffortLevel, AiReasoningLevel, AiConfiguredModel, AiConfig, AiTestConnectionResult, AiConfigItem } from "@/types/ai"; import type { AiProvider, AiApiStyle, AiAuthMethod, AiEffortLevel, AiReasoningLevel, AiConfiguredModel, AiConfig, AiTestConnectionResult, AiConfigItem } from "@/types/ai";
@@ -417,6 +417,7 @@ export interface EditorSettings {
dataGridSearchMode: DataGridSearchMode; dataGridSearchMode: DataGridSearchMode;
dataGridMultiRowTranspose: boolean; dataGridMultiRowTranspose: boolean;
dataGridHideNullColumns: boolean; dataGridHideNullColumns: boolean;
tableFontFamily: string;
tableFontSize: number; tableFontSize: number;
structureEditorDensity: StructureEditorDensity; structureEditorDensity: StructureEditorDensity;
tableInfoDrawerWidth: number; tableInfoDrawerWidth: number;
@@ -587,6 +588,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
dataGridSearchMode: "filter", dataGridSearchMode: "filter",
dataGridMultiRowTranspose: false, dataGridMultiRowTranspose: false,
dataGridHideNullColumns: false, dataGridHideNullColumns: false,
tableFontFamily: DEFAULT_DATA_GRID_FONT_FAMILY,
tableFontSize: TABLE_FONT_SIZE_DEFAULT, tableFontSize: TABLE_FONT_SIZE_DEFAULT,
structureEditorDensity: "compact", structureEditorDensity: "compact",
tableInfoDrawerWidth: 320, tableInfoDrawerWidth: 320,
@@ -848,6 +850,7 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
dataGridSearchMode: normalizeDataGridSearchMode(settings.dataGridSearchMode), dataGridSearchMode: normalizeDataGridSearchMode(settings.dataGridSearchMode),
dataGridMultiRowTranspose: settings.dataGridMultiRowTranspose === true, dataGridMultiRowTranspose: settings.dataGridMultiRowTranspose === true,
dataGridHideNullColumns: settings.dataGridHideNullColumns === true, dataGridHideNullColumns: settings.dataGridHideNullColumns === true,
tableFontFamily: normalizeFontFamily(settings.tableFontFamily, DEFAULT_EDITOR_SETTINGS.tableFontFamily),
tableFontSize: normalizeTableFontSize(settings.tableFontSize), tableFontSize: normalizeTableFontSize(settings.tableFontSize),
structureEditorDensity: normalizeStructureEditorDensity(settings.structureEditorDensity), structureEditorDensity: normalizeStructureEditorDensity(settings.structureEditorDensity),
tableInfoDrawerWidth: normalizeDrawerWidth(settings.tableInfoDrawerWidth, 240, DEFAULT_EDITOR_SETTINGS.tableInfoDrawerWidth), tableInfoDrawerWidth: normalizeDrawerWidth(settings.tableInfoDrawerWidth, 240, DEFAULT_EDITOR_SETTINGS.tableInfoDrawerWidth),
@@ -1207,6 +1210,7 @@ export const useSettingsStore = defineStore("settings", () => {
if (partial.dataGridSearchMode !== undefined) editorSettings.value.dataGridSearchMode = normalizeDataGridSearchMode(partial.dataGridSearchMode); if (partial.dataGridSearchMode !== undefined) editorSettings.value.dataGridSearchMode = normalizeDataGridSearchMode(partial.dataGridSearchMode);
if (partial.dataGridMultiRowTranspose !== undefined) editorSettings.value.dataGridMultiRowTranspose = partial.dataGridMultiRowTranspose === true; if (partial.dataGridMultiRowTranspose !== undefined) editorSettings.value.dataGridMultiRowTranspose = partial.dataGridMultiRowTranspose === true;
if (partial.dataGridHideNullColumns !== undefined) editorSettings.value.dataGridHideNullColumns = partial.dataGridHideNullColumns === true; if (partial.dataGridHideNullColumns !== undefined) editorSettings.value.dataGridHideNullColumns = partial.dataGridHideNullColumns === true;
if (partial.tableFontFamily !== undefined) editorSettings.value.tableFontFamily = normalizeFontFamily(partial.tableFontFamily, DEFAULT_EDITOR_SETTINGS.tableFontFamily);
if (partial.tableFontSize !== undefined) editorSettings.value.tableFontSize = normalizeTableFontSize(partial.tableFontSize); if (partial.tableFontSize !== undefined) editorSettings.value.tableFontSize = normalizeTableFontSize(partial.tableFontSize);
if (partial.structureEditorDensity !== undefined) editorSettings.value.structureEditorDensity = normalizeStructureEditorDensity(partial.structureEditorDensity); if (partial.structureEditorDensity !== undefined) editorSettings.value.structureEditorDensity = normalizeStructureEditorDensity(partial.structureEditorDensity);
if (partial.tableInfoDrawerWidth !== undefined) editorSettings.value.tableInfoDrawerWidth = normalizeDrawerWidth(partial.tableInfoDrawerWidth, 240, DEFAULT_EDITOR_SETTINGS.tableInfoDrawerWidth); if (partial.tableInfoDrawerWidth !== undefined) editorSettings.value.tableInfoDrawerWidth = normalizeDrawerWidth(partial.tableInfoDrawerWidth, 240, DEFAULT_EDITOR_SETTINGS.tableInfoDrawerWidth);
+36
View File
@@ -0,0 +1,36 @@
import { strict as assert } from "node:assert";
import { readFileSync } from "node:fs";
import { test } from "vitest";
const dataGridSource = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8");
const settingsDialogSource = readFileSync("apps/desktop/src/components/editor/EditorSettingsDialog.vue", "utf8");
test("applies the configured result grid font to DOM and canvas renderers", () => {
assert.match(dataGridSource, /const tableFontFamily = computed\(\(\) => settingsStore\.editorSettings\.tableFontFamily\)/);
assert.match(dataGridSource, /"--dbx-data-grid-font-family": tableFontFamily\.value/);
assert.match(dataGridSource, /class="canvas-grid-surface dbx-data-grid-font-family/);
assert.match(dataGridSource, /class="data-grid-scroller dbx-data-grid-font-family/);
});
test("invalidates grid measurements and canvas rendering when the result font changes", () => {
assert.match(dataGridSource, /columnHeaderMeasurementKey = computed\(\(\) => \[tableFontSize\.value, tableFontFamily\.value\]\)/);
assert.match(dataGridSource, /columnHeaderMeasureContext\.font = `600 \$\{tableFontSize\.value\}px \$\{tableFontFamily\.value\}`/);
assert.match(dataGridSource, /canvasRenderStyleKey = computed\(\(\) => `[^`]*\$\{tableFontFamily\.value\}:\$\{tableFontSize\.value\}`\)/);
});
test("places the result grid font beside the interface font in appearance settings", () => {
const editorSectionStart = settingsDialogSource.indexOf(`activeSettingsTab === 'editor'`);
const appearanceSectionStart = settingsDialogSource.indexOf(`activeSettingsTab === 'appearance'`);
const resultGridFontField = settingsDialogSource.indexOf(`<Label class="min-w-0 whitespace-normal leading-tight">{{ t("settings.dataGridFontFamily") }}</Label>`);
assert.ok(editorSectionStart >= 0);
assert.ok(appearanceSectionStart > editorSectionStart);
assert.ok(resultGridFontField > appearanceSectionStart);
assert.equal(settingsDialogSource.slice(editorSectionStart, appearanceSectionStart).includes(`settings.dataGridFontFamily`), false);
});
test("keeps appearance section spacing and help icons aligned without stacked margins", () => {
assert.doesNotMatch(settingsDialogSource, /\.settings-appearance-section > \* \+ \*/);
assert.match(settingsDialogSource, /activeSettingsTab === 'appearance'" class="settings-appearance-section flex flex-col gap-4 py-2"/);
assert.match(settingsDialogSource, /<div class="flex min-w-0 items-center gap-1">\s*<Label class="min-w-0 whitespace-normal leading-tight">\{\{ t\("settings\.dataGridFontFamily"\) \}\}<\/Label>/);
});
+15
View File
@@ -25,3 +25,18 @@ test("keeps a loaded editor font when an old appearance draft only changes the U
assert.equal(store.editorSettings.fontFamily, savedEditorFont); assert.equal(store.editorSettings.fontFamily, savedEditorFont);
assert.equal(store.editorSettings.uiFontFamily, staleDraft.uiFontFamily); assert.equal(store.editorSettings.uiFontFamily, staleDraft.uiFontFamily);
}); });
test("applies a result grid font without overwriting editor or interface fonts", () => {
setActivePinia(createPinia());
const store = useSettingsStore();
const draftBase = editorSettingsDraftFromSettings(store.editorSettings);
const tableFontFamily = `"IBM Plex Mono", monospace`;
const patch = editorSettingsPatchFromDraft({ ...draftBase, tableFontFamily }, draftBase);
store.updateEditorSettings(patch);
assert.equal(patch.fontFamily, undefined);
assert.equal(patch.uiFontFamily, undefined);
assert.equal(patch.tableFontFamily, tableFontFamily);
assert.equal(store.editorSettings.tableFontFamily, tableFontFamily);
});
+10 -1
View File
@@ -4,7 +4,7 @@ import { readFileSync } from "node:fs";
import { createPinia, setActivePinia } from "pinia"; import { createPinia, setActivePinia } from "pinia";
import { DEFAULT_SQL_FORMATTER_SETTINGS } from "../../apps/desktop/src/lib/sql/sqlFormatterConfig.ts"; import { DEFAULT_SQL_FORMATTER_SETTINGS } from "../../apps/desktop/src/lib/sql/sqlFormatterConfig.ts";
import { DEFAULT_TABLE_COLUMN_TEMPLATE_FIELDS } from "../../apps/desktop/src/lib/table/tableColumnTemplates.ts"; import { DEFAULT_TABLE_COLUMN_TEMPLATE_FIELDS } from "../../apps/desktop/src/lib/table/tableColumnTemplates.ts";
import { DEFAULT_UI_FONT_FAMILY, SYSTEM_UI_FONT_FAMILY } from "../../apps/desktop/src/lib/app/appFonts.ts"; import { DEFAULT_DATA_GRID_FONT_FAMILY, DEFAULT_UI_FONT_FAMILY, SYSTEM_UI_FONT_FAMILY } from "../../apps/desktop/src/lib/app/appFonts.ts";
import { tableOpenPageLimit } from "../../apps/desktop/src/lib/table/tableOpenPageLimit.ts"; import { tableOpenPageLimit } from "../../apps/desktop/src/lib/table/tableOpenPageLimit.ts";
import { AI_PROVIDER_PRESETS, DEFAULT_EDITOR_SETTINGS, EXECUTE_MODE_CURRENT_DEFAULT_VERSION, normalizeAiConfig, normalizeEditorSettings, useSettingsStore } from "../../apps/desktop/src/stores/settingsStore.ts"; import { AI_PROVIDER_PRESETS, DEFAULT_EDITOR_SETTINGS, EXECUTE_MODE_CURRENT_DEFAULT_VERSION, normalizeAiConfig, normalizeEditorSettings, useSettingsStore } from "../../apps/desktop/src/stores/settingsStore.ts";
@@ -165,6 +165,15 @@ test("keeps saved UI font family", () => {
assert.equal(normalizeEditorSettings({ uiFontFamily: SYSTEM_UI_FONT_FAMILY } as any).uiFontFamily, SYSTEM_UI_FONT_FAMILY); assert.equal(normalizeEditorSettings({ uiFontFamily: SYSTEM_UI_FONT_FAMILY } as any).uiFontFamily, SYSTEM_UI_FONT_FAMILY);
}); });
test("defaults result grid font family without changing saved custom fonts", () => {
const tableFontFamily = `"IBM Plex Mono", monospace`;
assert.equal(DEFAULT_EDITOR_SETTINGS.tableFontFamily, DEFAULT_DATA_GRID_FONT_FAMILY);
assert.equal(normalizeEditorSettings({}).tableFontFamily, DEFAULT_DATA_GRID_FONT_FAMILY);
assert.equal(normalizeEditorSettings({ tableFontFamily: "" as any }).tableFontFamily, DEFAULT_DATA_GRID_FONT_FAMILY);
assert.equal(normalizeEditorSettings({ tableFontFamily }).tableFontFamily, tableFontFamily);
});
test("defaults dangerous SQL confirmation to enabled", () => { test("defaults dangerous SQL confirmation to enabled", () => {
assert.equal(DEFAULT_EDITOR_SETTINGS.confirmDangerousSqlExecution, true); assert.equal(DEFAULT_EDITOR_SETTINGS.confirmDangerousSqlExecution, true);
assert.equal(normalizeEditorSettings({}).confirmDangerousSqlExecution, true); assert.equal(normalizeEditorSettings({}).confirmDangerousSqlExecution, true);