Add support for reordering document tabs (#3999)

* Add support for reordering document tabs

* Fix tab bar scrolling

* Close tab without activating it on pointerdown
This commit is contained in:
Keavon Chambers
2026-04-03 06:35:52 -07:00
committed by GitHub
parent 55115d89d5
commit b52bf7b7d4
7 changed files with 207 additions and 8 deletions
@@ -126,6 +126,10 @@ pub enum PortfolioMessage {
layers: Vec<LayerNodeIdentifier>,
},
PrevDocument,
ReorderDocument {
document_id: DocumentId,
new_index: usize,
},
RequestWelcomeScreenButtonsLayout,
RequestStatusBarInfoLayout,
SetActivePanel {
@@ -1053,6 +1053,24 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
responses.add(PortfolioMessage::SelectDocument { document_id: prev_id });
}
}
PortfolioMessage::ReorderDocument { document_id, new_index } => {
let new_index = new_index.min(self.document_ids.len().saturating_sub(1));
let Some(current_index) = self.document_ids.iter().position(|&id| id == document_id) else {
return;
};
if new_index != current_index {
self.document_ids.remove(current_index);
self.document_ids.insert(new_index, document_id);
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
// Re-send the active document so the frontend recalculates the active tab index after reordering
if let Some(active_document_id) = self.active_document_id {
responses.add(FrontendMessage::UpdateActiveDocument { document_id: active_document_id });
}
}
}
PortfolioMessage::RequestWelcomeScreenButtonsLayout => {
let donate = "https://graphite.art/donate/";