-
-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add incremental save button #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @HardyNLee, 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!
This pull request implements a new 'incremental save' functionality, enhancing data safety by allowing users to create numbered backups of their currently active file. This feature aims to provide a temporary recovery solution, mitigating potential data loss in cases of original file corruption. The changes encompass updates to the user interface, new API definitions, and robust backend file system operations, along with comprehensive localization support.
Highlights
- New Feature: Incremental Save Button: A new 'Incremental Save' button has been added to the
TagsManager
in the editor UI, providing users with an easy way to create backups. - API Integration for File Operations: A new API endpoint (
/api/assets/copyFileWithIncrement
) has been introduced to facilitate the incremental file saving process from the frontend to the backend. - Robust Backend File Management: The backend now includes a dedicated utility to copy files with an intelligent incremental naming convention (e.g.,
filename_001.ext
,filename_002.ext
), designed to prevent data loss from accidental file corruption. - Localization Support: New strings for the incremental save feature and its descriptive tooltip have been added to English, Japanese, and Simplified Chinese localization files, ensuring a consistent user experience across different languages.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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
-
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. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
这个 PR 新增了增量保存功能,这是一个非常实用的特性,可以有效防止数据丢失。整体实现思路清晰,前端和后端代码都比较完善。我发现了一些可以改进的地方,主要涉及类型安全和代码健壮性,具体请看我的评论。修改这些问题后,代码质量会更高。
// 读取目录下所有文件 | ||
const files = await fs.readdir(dir); | ||
// 匹配类似 xxx_序号.txt 的文件 | ||
const regex = new RegExp(`^${base}_(\\d+)${ext.replace('.', '\\.')}$`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在构建正则表达式时,base
变量(即不带扩展名的文件名)没有被转义。如果文件名包含正则表达式的特殊字符(例如 (
, )
, .
等),这可能会导致 new RegExp
抛出错误或产生意外的匹配行为。为了增强健壮性,建议对 base
变量进行转义。
const regex = new RegExp(`^${base}_(\\d+)${ext.replace('.', '\\.')}$`); | |
const escapedBase = base.replace(/[.*+?^${}()|[\\\]]/g, '\\$&'); | |
const regex = new RegExp(`^${escapedBase}_(\\d+)${ext.replace('.', '\\.')}$`); |
onMouseDown={(event: any) => { | ||
if (event.button === 1) { | ||
closeTag(event, item); | ||
} | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event
参数的类型是 any
。为了更好的类型安全和代码可读性,建议使用更具体的 React.MouseEvent
类型。另外,closeTag
函数期望一个原生的 MouseEvent
,所以应该传递 event.nativeEvent
。
onMouseDown={(event: any) => { | |
if (event.button === 1) { | |
closeTag(event, item); | |
} | |
}} | |
onMouseDown={(event: React.MouseEvent) => { | |
if (event.button === 1) { | |
closeTag(event.nativeEvent, item); | |
} | |
}} |
<div> | ||
{item.name} | ||
</div> | ||
<div className={styles.closeIcon} onClick={(event: any) => closeTag(event, item)}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event
参数的类型是 any
。为了更好的类型安全和代码可读性,建议使用更具体的 React.MouseEvent
类型。另外,closeTag
函数期望一个原生的 MouseEvent
,所以应该传递 event.nativeEvent
。
<div className={styles.closeIcon} onClick={(event: any) => closeTag(event, item)}> | |
<div className={styles.closeIcon} onClick={(event: React.MouseEvent) => closeTag(event.nativeEvent, item)}> |
介绍
新增 增量保存 按钮, 防止因原文件损坏而丢失整个文件的数据, 算是一种临时补救方案

严格来说, 原理是复制当前活动文件, 并加一个序号后缀
主要更改
TagsManager
最右边新增一个 增量保存 按钮