feat: 添加编辑器自定义字体功能
This commit is contained in:
@@ -58,6 +58,9 @@ const mapRowsToAppearanceSettings = (rows: DbAppearanceSettingsRow[]): Appearanc
|
||||
settings.terminalBackgroundOverlayOpacity = parseFloat(row.value);
|
||||
terminalBackgroundOverlayOpacityFound = true;
|
||||
break;
|
||||
case 'editorFontFamily':
|
||||
settings.editorFontFamily = row.value || null; // 如果为空字符串,则视为 null
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +72,7 @@ const mapRowsToAppearanceSettings = (rows: DbAppearanceSettingsRow[]): Appearanc
|
||||
terminalFontFamily: settings.terminalFontFamily ?? defaults.terminalFontFamily,
|
||||
terminalFontSize: settings.terminalFontSize ?? defaults.terminalFontSize,
|
||||
editorFontSize: settings.editorFontSize ?? defaults.editorFontSize,
|
||||
editorFontFamily: settings.editorFontFamily ?? defaults.editorFontFamily,
|
||||
terminalBackgroundImage: settings.terminalBackgroundImage ?? defaults.terminalBackgroundImage,
|
||||
pageBackgroundImage: settings.pageBackgroundImage ?? defaults.pageBackgroundImage,
|
||||
// 修改:只有当数据库中未找到记录时才使用默认值
|
||||
@@ -91,6 +95,7 @@ const getDefaultAppearanceSettings = (): Omit<AppearanceSettings, '_id'> => {
|
||||
terminalFontFamily: 'Consolas, "Courier New", monospace, "Microsoft YaHei", "微软雅黑"',
|
||||
terminalFontSize: 14,
|
||||
editorFontSize: 14,
|
||||
editorFontFamily: 'Consolas, "Noto Sans SC", "Microsoft YaHei"',
|
||||
terminalBackgroundImage: undefined,
|
||||
pageBackgroundImage: undefined,
|
||||
terminalBackgroundEnabled: true, // 默认启用
|
||||
@@ -117,6 +122,7 @@ export const ensureDefaultSettingsExist = async (db: sqlite3.Database): Promise<
|
||||
{ key: 'terminalFontFamily', value: defaults.terminalFontFamily },
|
||||
{ key: 'terminalFontSize', value: defaults.terminalFontSize },
|
||||
{ key: 'editorFontSize', value: defaults.editorFontSize },
|
||||
{ key: 'editorFontFamily', value: defaults.editorFontFamily },
|
||||
{ key: 'terminalBackgroundImage', value: defaults.terminalBackgroundImage ?? '' }, // 数据库中使用空字符串
|
||||
{ key: 'pageBackgroundImage', value: defaults.pageBackgroundImage ?? '' }, // 数据库中使用空字符串
|
||||
{ key: 'terminalBackgroundEnabled', value: defaults.terminalBackgroundEnabled },
|
||||
|
||||
@@ -69,6 +69,28 @@ export const updateSettings = async (settingsDto: UpdateAppearanceDto): Promise<
|
||||
settingsDto.editorFontSize = size;
|
||||
}
|
||||
|
||||
// 验证 editorFontFamily (如果提供了)
|
||||
if (settingsDto.hasOwnProperty('editorFontFamily')) {
|
||||
if (settingsDto.editorFontFamily === null) {
|
||||
// 允许用户将字体设置为空 (null),表示重置或使用默认
|
||||
// 无需额外操作,仓库层会处理 null
|
||||
} else if (typeof settingsDto.editorFontFamily === 'string') {
|
||||
const fontFamily = settingsDto.editorFontFamily;
|
||||
// 校验字体名称格式和长度
|
||||
if (fontFamily.length > 255) {
|
||||
throw new Error('编辑器字体名称过长,最多允许 255 个字符。');
|
||||
}
|
||||
|
||||
if (fontFamily.trim() === '' && fontFamily !== '') {
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// 如果提供了 editorFontFamily 但不是 string 或 null
|
||||
throw new Error('无效的编辑器字体名称类型,应为字符串或 null。');
|
||||
}
|
||||
}
|
||||
|
||||
// 验证 terminalBackgroundOverlayOpacity (如果提供了)
|
||||
if (settingsDto.terminalBackgroundOverlayOpacity !== undefined && settingsDto.terminalBackgroundOverlayOpacity !== null) {
|
||||
const opacity = Number(settingsDto.terminalBackgroundOverlayOpacity);
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface AppearanceSettings {
|
||||
terminalBackgroundImage?: string; // 终端背景图片 URL 或路径
|
||||
pageBackgroundImage?: string; // 页面背景图片 URL 或路径
|
||||
editorFontSize?: number; // 编辑器字体大小 (px)
|
||||
editorFontFamily?: string | null; // Monaco Editor 字体偏好
|
||||
terminalBackgroundEnabled?: boolean; // 终端背景是否启用
|
||||
terminalBackgroundOverlayOpacity?: number; // 终端背景蒙版透明度 (0-1)
|
||||
updatedAt?: number;
|
||||
|
||||
Reference in New Issue
Block a user