Repository navigation
fix: prevent file recreation at original path after deletion #680
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1103,7 +1103,14 @@ bool Window::closeTab(const QString &filePath) | |
| } | ||
| } else { | ||
| qDebug() << "File is not a backup file, saving normally"; | ||
| if (wrapper->saveFile()) { | ||
| // 源文件可能已被外部删除(如移入回收站),需先检查文件是否存在 | ||
| if (!fileInfo.exists()) { | ||
| qDebug() << "File no longer exists, using Save As instead"; | ||
| if (!saveAsFile()) { | ||
| qWarning() << "Save as file cancelled or failed, keep tab open"; | ||
| return false; | ||
| } | ||
|
Comment on lines
+1109
to
+1112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Saved tab remains open When a deleted file is being closed and Save As succeeds, After Save As succeeds, remove the wrapper and close the requested tab before reporting success. Prompt for AI agentsIn `src/widgets/window.cpp` at lines 1109-1112:
**Saved tab remains open**
When a deleted file is being closed and Save As succeeds, `closeTab()` returns success without removing the wrapper or closing the tab, so callers such as `closeAllFiles()` count it as closed while it remains visible.
After Save As succeeds, remove the wrapper and close the requested tab before reporting success. |
||
| } else if (wrapper->saveFile()) { | ||
| qDebug() << "File saved, removing wrapper and closing tab"; | ||
| removeWrapper(filePath, true); | ||
| m_tabbar->closeCurrentTab(filePath); | ||
|
|
@@ -1557,7 +1564,10 @@ QString Window::saveAsFileToDisk() | |
| dialog.selectFile(match.captured(0) + ".txt"); | ||
| qDebug() << "Setting dialog file name to draft file name:" << match.captured(0) + ".txt"; | ||
| } else { | ||
| dialog.setDirectory(fileInfo.dir()); | ||
| // 源文件已被删除(如移入回收站)时,使用默认保存路径而非原始文件目录 | ||
| if (fileInfo.exists()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Save As recreates deleted file When the source is deleted and the configured Save As directory still points to its existing parent, When the source no longer exists, use the default Save As directory and avoid preselecting the deleted file’s original path. Also at Prompt for AI agentsIn `src/widgets/window.cpp` at line 1568:
**Save As recreates deleted file**
When the source is deleted and the configured Save As directory still points to its existing parent, `saveAsFileToDisk()` keeps the directory selected by `getCurrentOpenFilePath()`, and `selectFile()` preselects the original filename. Accepting the defaults therefore saves to the deleted file’s original path and recreates it.
When the source no longer exists, use the default Save As directory and avoid preselecting the deleted file’s original path.
Also at `src/widgets/window.cpp:1569-1570`. |
||
| dialog.setDirectory(fileInfo.dir()); | ||
| } | ||
| dialog.selectFile(fileInfo.fileName()); | ||
| qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName(); | ||
| } | ||
|
|
@@ -1685,7 +1695,10 @@ QString Window::saveBlankFileToDisk() | |
| dialog.selectFile(match.captured(0) + ".txt"); | ||
| qDebug() << "Setting dialog file name to draft file name:" << match.captured(0) + ".txt"; | ||
| } else { | ||
| dialog.setDirectory(fileInfo.dir()); | ||
| // 源文件已被删除(如移入回收站)时,使用默认保存路径而非原始文件目录 | ||
| if (fileInfo.exists()) { | ||
| dialog.setDirectory(fileInfo.dir()); | ||
| } | ||
| dialog.selectFile(fileInfo.fileName()); | ||
| qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName(); | ||
| } | ||
|
|
@@ -1734,7 +1747,10 @@ bool Window::saveAsOtherTabFile(EditWrapper *wrapper) | |
| dialog.selectFile(match.captured(0) + ".txt"); | ||
| qDebug() << "Setting dialog file name to draft file name:" << match.captured(0) + ".txt"; | ||
| } else { | ||
| dialog.setDirectory(fileInfo.dir()); | ||
| // 源文件已被删除(如移入回收站)时,使用默认保存路径而非原始文件目录 | ||
| if (fileInfo.exists()) { | ||
| dialog.setDirectory(fileInfo.dir()); | ||
| } | ||
| dialog.selectFile(fileInfo.fileName()); | ||
| qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName(); | ||
| } | ||
|
|
||
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.
🟡 Medium · Preview save recreates deleted file
When the source of an edited invalid-character preview is deleted and the user chooses “Save Anyway”, the preview branch in
closeTab()callsforceSaveInvalidCharFile()before the existence check, so it writes directly to the original path and recreates the deleted file.Route “Save Anyway” through a path that checks for a missing source and does not write to its original path.
Prompt for AI agents