Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

refactor(FontManager): 优化字体的显示转换逻辑 - #917

Merged
kazukokawagawa merged 1 commit into
SPlayer-Dev:devfrom
MoYingJi:pr/f
Feb 22, 2026
Merged

kazukokawagawa merged 1 commit into
SPlayer-Dev:devfrom
MoYingJi:pr/f

Conversation

@MoYingJi

@MoYingJi MoYingJi commented Feb 20, 2026 •

Copy link
Copy Markdown
Collaborator

重构了一下代码,同时还修复了这个小问题

图片 图片
Copilot AI review requested due to automatic review settings February 20, 2026 23:02
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @MoYingJi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在优化应用程序中字体名称的显示和转换逻辑。通过在获取系统字体时禁用自动引用,并引入一套新的工具函数来处理字体名称的引用和格式化,确保了字体名称在用户界面和内部存储之间的一致性和准确性。这改进了字体选择的用户体验,并使相关代码更加健壮和易于维护。

Highlights

  • 系统字体获取优化: 在 Electron 主进程中获取系统字体时,禁用了字体名称的自动引用,确保获取到原始的字体名称。
  • 字体名称转换工具函数: 新增了 hasPairedQuotes、fontFamilyToDisplay 和 fontDisplayToFamily 等工具函数,用于更精确地处理字体名称中的引号和空格,统一了字体名称的显示和存储格式。
  • 字体选择组件重构: 重构了字体选择组件(n-select)的绑定逻辑,使其在单选和多选模式下均使用新的转换函数,提升了用户体验和代码一致性。
  • 简化现有字体处理函数: 简化了 fontFamilyToArray 和 fontArrayToFamily 函数的内部实现,通过复用新的转换函数提高了代码的可读性和维护性。
Changelog
  • electron/main/ipc/ipc-system.ts
    • 在调用 getFonts 函数时,添加了 disableQuoting: true 选项,以避免字体名称被自动引用。
  • src/components/Modal/Setting/FontManager.vue
    • 更新了多个 n-select 组件的 update:value 事件处理,以使用新引入的 fontFamilyToDisplay 和 fontDisplayToFamily 函数进行字体名称的显示和转换。
    • 新增了 hasPairedQuotes、fontFamilyToDisplay 和 fontDisplayToFamily 三个辅助函数,用于处理字体名称的引用和格式化。
    • 重构了 fontFamilyToArray 和 fontArrayToFamily 函数,使其内部逻辑调用新的 fontFamilyToDisplay 和 fontDisplayToFamily 函数,从而简化了代码。
Activity
  • 此拉取请求由 MoYingJi 创建,旨在优化字体显示转换逻辑。
  • 目前没有其他评论或审查活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors font display and conversion logic, introducing new utility functions hasPairedQuotes, fontFamilyToDisplay, and fontDisplayToFamily. These changes streamline how font family strings are handled, especially concerning quotes and comma/space separation, and integrate these new functions into the Vue component for single and multi-font selections. Additionally, the getFonts call in ipc-system.ts now uses disableQuoting: true for consistency. The changes improve code readability and maintainability by centralizing font string manipulation.

Comment thread electron/main/ipc/ipc-system.ts
Comment thread src/components/Modal/Setting/FontManager.vue Outdated
Comment thread src/components/Modal/Setting/FontManager.vue
Comment thread src/components/Modal/Setting/FontManager.vue

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the font display and conversion logic in the FontManager component by extracting inline transformation logic into reusable helper functions and improving the handling of font family strings with quotes.

Changes:

  • Extracted font family string transformation logic into three helper functions (hasPairedQuotes, fontFamilyToDisplay, fontDisplayToFamily)
  • Replaced v-model:value with explicit :value and @update:value bindings for single-font-selection mode, applying conversions to properly handle quoted font names
  • Unified parameter naming from value to val for consistency with codebase conventions
  • Added disableQuoting: true option to getFonts() call to receive font names without quotes from the system

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/components/Modal/Setting/FontManager.vue Refactored font family string conversion logic into reusable functions; updated template bindings to use explicit conversions for single-font mode; improved quote handling consistency
electron/main/ipc/ipc-system.ts Added disableQuoting: true option to getFonts() call to receive unquoted font names from the system
Comment on lines +284 to +288
if (s.startsWith('"')) {
if (s.indexOf('"', 1) === l - 1) return true;
} else if (s.startsWith("'")) {
if (s.indexOf("'", 1) === l - 1) return true;
}

Copilot AI Feb 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for detecting paired quotes has a bug. When checking for the closing quote, indexOf with start position 1 will find the first occurrence after position 0, which could be an escaped quote or a quote in the middle of the string, not necessarily the matching closing quote at the end. For example, "Font with \" quote" would incorrectly match.

The condition should check if the last character matches the first quote character, rather than using indexOf. Consider replacing lines 284-288 with:

const firstChar = s[0];
const lastChar = s[l - 1];
if ((firstChar === '"' || firstChar === "'") && firstChar === lastChar) {
  return true;
}

This ensures we only match when the opening and closing quotes are the same type and at the expected positions.

Suggested change
if (s.startsWith('"')) {
if (s.indexOf('"', 1) === l - 1) return true;
} else if (s.startsWith("'")) {
if (s.indexOf("'", 1) === l - 1) return true;
}
const firstChar = s[0];
const lastChar = s[l - 1];
if ((firstChar === '"' || firstChar === "'") && firstChar === lastChar) {
return true;
}
Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Noto Sans", "Noto Sans CJK SC" 会被错误去除为 Noto Sans", "Noto Sans CJK SC,但包含引号的字体...我没见过说实话

Comment on lines 325 to 332
const fontFamilyToArray = (fontFamily: string): string[] => {
if (!fontFamily) return [];
const regex = /"([^"]*)"|'([^']*)'|([^,]+)/g;
const matches = fontFamily.match(regex);
if (!matches) return [];

return matches
.map((s) => {
// 移除首尾空格
s = s.trim();
// 移除引号
if (s.match(/^"|^'/)) {
s = s.substring(1, s.length - 1);
}
return s.trim();
})
.filter(Boolean);
return matches.map(fontFamilyToDisplay).filter(Boolean);
};

Copilot AI Feb 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactoring changes the quote detection logic from the previous implementation. The old code in fontFamilyToArray used if (s.match(/^"|^'/)) which only checked if the string starts with a quote, without verifying a closing quote exists. The old fontArrayToFamily used /^["'].*["']$/ which checked for quotes at both ends but didn't ensure they were the same type.

The new hasPairedQuotes function attempts to verify that opening and closing quotes match types (both " or both '), which is more correct. However, due to the bug in the hasPairedQuotes implementation (see comment on that function), this may not work as intended.

Once the hasPairedQuotes bug is fixed, this will be an improvement over the old logic, but it's worth noting that it's a behavior change that could affect how existing font family values are processed.

Copilot uses AI. Check for mistakes.
@kazukokawagawa
kazukokawagawa merged commit d7f5b85 into SPlayer-Dev:dev Feb 22, 2026
@MoYingJi
MoYingJi deleted the pr/f branch February 24, 2026 00:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants