Skip to content

Fix file rename: pre-fill dialog and actually delete old file#1038

Merged
dail8859 merged 1 commit intodail8859:masterfrom
saberoueslati:fix/rename-bug
May 2, 2026
Merged

Fix file rename: pre-fill dialog and actually delete old file#1038
dail8859 merged 1 commit intodail8859:masterfrom
saberoueslati:fix/rename-bug

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

Fixes #1034

Problem

Two bugs caused the rename feature (right-click tab → Rename) to misbehave:

  1. Dialog opened with no pre-filled name. MainWindow::renameFile() passed only the default directory to FileDialogHelpers::getSaveFileName. QFileDialog only pre-fills the filename field when given a full file path, so the field was always empty.

  2. Old file was never deleted. ScintillaNext::rename() checked if (saveCopyAs(newFilePath)) to decide whether to remove the original. saveCopyAs returns QFileDevice::FileError, where NoError == 0 (falsy). The condition was inverted — it entered the block only on error, so on success the QFile::remove was skipped and the old file was left on disk.

The combination made it appear as if the file was "renamed" in the tab but the original remained untouched and a second copy appeared at the destination.

Video of the manual test below :

Screencast.from.2026-05-02.00-56-33.webm

Changes

src/dialogs/MainWindow.cpp

Pass editor->getFilePath() (the current file's full path) to getSaveFileName instead of the default directory. QFileDialog now navigates to the file's directory and pre-fills its name.

src/ScintillaNext.cpp

Change the save-success check from if (saveCopyAs(newFilePath)) to if (saveCopyAs(newFilePath) == QFileDevice::NoError). The old file is now correctly removed after a successful copy.

@dail8859 dail8859 merged commit 6c364ce into dail8859:master May 2, 2026
11 checks passed
@dail8859
Copy link
Copy Markdown
Owner

dail8859 commented May 2, 2026

Awesome! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename bug

2 participants