Skip to content

Fixes #5099 - Preserve filename on FileDialog table navigation#5408

Merged
tig merged 3 commits into
developfrom
copilot/fix-filedialog-preserve-filename-bug
May 25, 2026
Merged

Fixes #5099 - Preserve filename on FileDialog table navigation#5408
tig merged 3 commits into
developfrom
copilot/fix-filedialog-preserve-filename-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 25, 2026

Proposed Changes/Todos

  • Keep PreserveFilenameOnDirectoryChanges intact when TableView navigation triggers an internal PushState.
    • Guard TableViewOnValueChanged while _pushingState is active so table refreshes do not overwrite the typed filename with the first file in the newly opened directory.
  • Add a regression test for the reported SaveDialog scenario with an active file-type filter.
    • Verifies Enter on a directory row preserves the filename.
    • Verifies the following Enter on .. navigates back to the parent directory instead of closing the dialog.
var ofd = new SaveDialog ()
{
    AllowedTypes = [new AllowedType ("C# File", ".cs")],
    Path = "hello.cs",
};
ofd.Style.PreserveFilenameOnDirectoryChanges = true;

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

Copilot AI changed the title [WIP] Fix FileDialog PreserveFilenameOnDirectoryChanges behavior Preserve filename on FileDialog table navigation May 25, 2026
Copilot AI requested a review from tig May 25, 2026 01:34
Copilot finished work on behalf of tig May 25, 2026 01:34
@tig tig marked this pull request as ready for review May 25, 2026 03:28
@tig tig requested a review from Copilot May 25, 2026 03:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates FileDialog’s TableView navigation to avoid overwriting a user-typed filename when directory changes trigger an internal PushState, particularly when PreserveFilenameOnDirectoryChanges is enabled.

Changes:

  • Guard TableViewOnValueChanged with _pushingState to prevent re-entrant/refresh-driven selection changes from rewriting Path.
  • Add an integration regression test covering “Enter on directory” and then “Enter on ..” navigation while preserving the typed filename.

Reviewed changes

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

File Description
Tests/IntegrationTests/FluentTests/FileDialogTests.cs Adds a regression integration test for SaveDialog TableView Enter navigation + filename preservation.
Terminal.Gui/Views/FileDialogs/FileDialog.TableView.cs Prevents ValueChanged side effects during internal state pushes by checking _pushingState.

Comment thread Tests/IntegrationTests/FluentTests/FileDialogTests.cs Outdated
@tig tig changed the title Preserve filename on FileDialog table navigation Fixes #5099 - Preserve filename on FileDialog table navigation May 25, 2026
Move AllowedTypes and PreserveFilenameOnDirectoryChanges assignments into
the factory lambda so they are set before EndInit() initializes CurrentFilter
and the type dropdown. Previously these were set in .Then() which runs after
EndInit(), meaning the filter was never applied to the initial listing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tig tig requested review from BDisp and tznind May 25, 2026 19:20
@tig
Copy link
Copy Markdown
Member

tig commented May 25, 2026

This needs @tznind's approval since he reported it.

@tznind
Copy link
Copy Markdown
Collaborator

tznind commented May 25, 2026

It would be good if the copilot first committed test so we could see failure then did fix in followup commit to see it fixed with no further test change. Even if the pr were then squashed

Looks good though.

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.

FileDialog PreserveFilenameOnDirectoryChanges broken with latest changes

5 participants