diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 9482d2f2a8..11361f032e 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -994,10 +994,8 @@ impl PortfolioMessageHandler { responses.add(PortfolioMessage::LoadDocumentResources { document_id }); responses.add(PortfolioMessage::UpdateDocumentWidgets); responses.add(ToolMessage::InitTools); - responses.add(NodeGraphMessage::Init); responses.add(NavigationMessage::CanvasPan { delta: (0., 0.).into() }); responses.add(PropertiesPanelMessage::Clear); - responses.add(NodeGraphMessage::UpdateNewNodeGraph); } /// Returns an iterator over the open documents in order. diff --git a/frontend/src/io-managers/persistence.ts b/frontend/src/io-managers/persistence.ts index 812176e1ce..33493fb777 100644 --- a/frontend/src/io-managers/persistence.ts +++ b/frontend/src/io-managers/persistence.ts @@ -16,6 +16,17 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta await set("documents_tab_order", documentOrder, graphiteStore); } + async function storeCurrentDocumentIndex() { + const documentIndex = getFromStore(portfolio).activeDocumentIndex; + const documentId = getFromStore(portfolio).documents[documentIndex].id; + + await storeCurrentDocumentByID(String(documentId)); + } + + async function storeCurrentDocumentByID(documentId: string) { + await set("current_document_id", String(documentId), graphiteStore); + } + async function storeDocument(autoSaveDocument: TriggerIndexedDbWriteDocument) { await update>( "documents", @@ -28,6 +39,7 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta ); await storeDocumentOrder(); + await storeCurrentDocumentByID(autoSaveDocument.details.id); } async function removeDocument(id: string) { @@ -41,12 +53,20 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta graphiteStore, ); + const documentCount = getFromStore(portfolio).documents.length; + if (documentCount > 0) { + await storeCurrentDocumentIndex(); + } else { + await del("current_document_id", graphiteStore); + } + await storeDocumentOrder(); } async function loadDocuments() { const previouslySavedDocuments = await get>("documents", graphiteStore); const documentOrder = await get("documents_tab_order", graphiteStore); + const currentDocumentId = await get("current_document_id", graphiteStore); if (!previouslySavedDocuments || !documentOrder) return; const orderedSavedDocuments = documentOrder.flatMap((id) => (previouslySavedDocuments[id] ? [previouslySavedDocuments[id]] : [])); @@ -54,6 +74,9 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta orderedSavedDocuments?.forEach(async (doc: TriggerIndexedDbWriteDocument) => { editor.handle.openAutoSavedDocument(BigInt(doc.details.id), doc.details.name, doc.details.isSaved, doc.document); }); + if (currentDocumentId) { + editor.handle.selectDocument(BigInt(currentDocumentId)); + } } // PREFERENCES @@ -91,5 +114,6 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta export async function wipeDocuments() { await del("documents_tab_order", graphiteStore); + await del("current_document_id", graphiteStore); await del("documents", graphiteStore); }