Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/widgets/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,13 @@ 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 on disk, redirecting to Save As";
if (!saveAsFile()) {
qWarning() << "Save as file cancelled or failed, keep tab open";
return false;
}
Comment on lines +1108 to +1111

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Saved tab stays open

When the source file is missing and Save As succeeds while closing the tab, closeTab() proceeds past successful saveAsFile() without calling removeWrapper() or m_tabbar->closeCurrentTab(), then returns true; callers such as closeAllFiles() count the tab as closed even though it remains open.

Run the normal successful-save cleanup after saveAsFile() succeeds.

Prompt for AI agents
In `src/widgets/window.cpp` at lines 1108-1111:

**Saved tab stays open**

When the source file is missing and Save As succeeds while closing the tab, `closeTab()` proceeds past successful `saveAsFile()` without calling `removeWrapper()` or `m_tabbar->closeCurrentTab()`, then returns true; callers such as `closeAllFiles()` count the tab as closed even though it remains open.

Run the normal successful-save cleanup after `saveAsFile()` succeeds.

} else if (wrapper->saveFile()) {
qDebug() << "File saved, removing wrapper and closing tab";
removeWrapper(filePath, true);
m_tabbar->closeCurrentTab(filePath);
Expand Down Expand Up @@ -1557,7 +1563,9 @@ 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()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Save As recreates deleted file

When the source is deleted, its parent directory still exists, and the configured save location resolves to that parent, saveAsFileToDisk() leaves the dialog in the source's parent directory and dialog.selectFile(fileInfo.fileName()) preselects the original pathname; accepting the default saves back to that path and recreates the deleted file.

For a missing source, choose a fallback directory and avoid preselecting the deleted file's original pathname.

Also at src/widgets/window.cpp:1567-1570.

Prompt for AI agents
In `src/widgets/window.cpp` at line 1566:

**Save As recreates deleted file**

When the source is deleted, its parent directory still exists, and the configured save location resolves to that parent, `saveAsFileToDisk()` leaves the dialog in the source's parent directory and `dialog.selectFile(fileInfo.fileName())` preselects the original pathname; accepting the default saves back to that path and recreates the deleted file.

For a missing source, choose a fallback directory and avoid preselecting the deleted file's original pathname.

Also at `src/widgets/window.cpp:1567-1570`.

dialog.setDirectory(fileInfo.dir());
}
dialog.selectFile(fileInfo.fileName());
qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName();
}
Expand Down Expand Up @@ -1685,7 +1693,9 @@ 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();
}
Expand Down Expand Up @@ -1734,7 +1744,9 @@ 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();
}
Expand Down
Loading