style: 优化字体栈设置与选择器匹配逻辑

This commit is contained in:
2026-04-21 10:23:18 +08:00
parent e35059b200
commit bb2ae9c139
3 changed files with 18 additions and 8 deletions

View File

@@ -1199,13 +1199,22 @@
// 更新颜色选择器
colorPicker.value = rgbToHex(color);
// 更新字体选择器
// 更新字体选择器 - 匹配字体栈中的主要字体
let matched = false;
for (let option of fontPicker.options) {
if (option.value === fontFamily || fontFamily.includes(option.value)) {
const optionFonts = option.value.toLowerCase().split(',').map(f => f.trim());
const currentFonts = fontFamily.toLowerCase().split(',').map(f => f.trim());
// 检查是否有主要字体匹配
if (optionFonts.some(of => currentFonts.includes(of))) {
fontPicker.value = option.value;
matched = true;
break;
}
}
// 如果没有匹配,默认选择第一个(系统默认)
if (!matched && fontPicker.options.length > 0) {
fontPicker.value = fontPicker.options[0].value;
}
// 更新字号选择器
const fontSizeValueEl = fontSizePicker.querySelector('.roller-value');
@@ -1730,7 +1739,7 @@
fontPicker.addEventListener('change', () => {
const targetInput = editingInput || selectedInput;
if (!targetInput) return;
targetInput.style.fontFamily = fontPicker.value + ', sans-serif';
targetInput.style.fontFamily = fontPicker.value;
});
// 字号选择器 - 密码锁式滚轮