Skip to content

Fix overflow in unsaved document list in Close All dialog - #4617

Merged
TrueDoctor merged 4 commits into
GraphiteEditor:masterfrom
shubhtrek:fix-close-all-dialog-overflow
Sep 30, 2026
Merged

TrueDoctor merged 4 commits into
GraphiteEditor:masterfrom
shubhtrek:fix-close-all-dialog-overflow

Conversation

@shubhtrek

@shubhtrek shubhtrek commented Sep 27, 2026 •

Copy link
Copy Markdown

Fixed the overflow in the "Close all documents" dialog when many documents are open.

The dialog now handles a large number of open documents without overflowing.

Closes #4601

I reproduced the issue locally to understand the problem first. After making the fix, I tested it again with multiple open documents to confirm the overflow is resolved.

Before

Screenshot 2026-09-27 202001

After

Screenshot 2026-09-27 204035

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread editor/src/messages/dialog/simple_dialogs/close_all_documents_dialog.rs Outdated

@0HyperCube 0HyperCube left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution; this seems like a reasonable fix.

let remaining = self.unsaved_document_names.len().saturating_sub(max_docs_to_show);
if remaining > 0 {
let s = if remaining == 1 { "" } else { "s" };
unsaved_list.push_str(&format!("\n... and {remaining} more document{s}"));

@0HyperCube 0HyperCube Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The format allocates a new string which is then immediately converted to &str. Consider the write!() macro.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’ve changed it to use write!() as suggested

impl LayoutHolder for CloseAllDocumentsDialog {
fn layout(&self) -> Layout {
let unsaved_list = "• ".to_string() + &self.unsaved_document_names.join("\n• ");
let max_docs_to_show = 5;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A lot of constants for the editor are stored in consts.rs. Consider doing the same here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’ve moved the constant to consts.rs

@TrueDoctor TrueDoctor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, if you want to make any more edits please let me know otherwise I'll merge this soon, the code is fine as it is

Comment on lines +43 to +44
let mut truncated: String = name.chars().take(MAX_DOCUMENT_NAME_LENGTH_IN_DIALOG).collect();
truncated.push('…');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is completely irrelevant perf wise since this code is executed once, but you could theoretically also write something like this to make the code a bit shorter and avoid the intermediate alloc:
name.chars().take(MAX_DOCUMENT_NAME_LENGTH_IN_DIALOG).chain(std::iter::once('…')).collect()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated!

truncated.push('…');
truncated
} else {
name.clone()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Once again irrelevant perf wise, but by wrapping the outputs of the branches in Cow::Borrowed() and Cow::Owned(), you could avoid the .clone().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done! Switched to Cow to avoid cloning the unchanged names

@shubhtrek

Copy link
Copy Markdown
Author

@TrueDoctor Done! as you said. PTAL

@TrueDoctor TrueDoctor changed the title Fix #4601: Limit unsaved document list in Close All dialog to prevent… Fix overflow in unsaved document list in Close All dialog Sep 30, 2026
@TrueDoctor
TrueDoctor added this pull request to the merge queue Sep 30, 2026
Merged via the queue into GraphiteEditor:master with commit c26f9ce Sep 30, 2026
10 checks passed
Keavon pushed a commit that referenced this pull request Sep 30, 2026
* Fix #4601: Limit unsaved document list in Close All dialog to prevent overflow

* Truncate individual long document names in Close All dialog

* Address review comments: move dialog constants to consts.rs and use write! macro

* Use Cow and iterator chaining in Close All dialog layout
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.

Close all documents dialogue overflows with many open documents

3 participants