diff --git a/src/notebook.manager.ts b/src/notebook.manager.ts index 24cf1ec..e2165f9 100644 --- a/src/notebook.manager.ts +++ b/src/notebook.manager.ts @@ -203,6 +203,9 @@ export class NotebookManager implements INotebookManager { // add a notebook to the favorites stored in global state let collectionNotebooks: Notebook[] = notebookTreeDataProvider.context.globalState.get(notebookCollectionKey); + if (collectionNotebooks === undefined) { + collectionNotebooks = []; + } collectionNotebooks.push(notebook); notebookTreeDataProvider.context.globalState.update(notebookCollectionKey, collectionNotebooks); break; diff --git a/src/views/notebook.view.ts b/src/views/notebook.view.ts index d997962..6fc19ee 100644 --- a/src/views/notebook.view.ts +++ b/src/views/notebook.view.ts @@ -232,6 +232,10 @@ export class NotebookView { // loads notebook view this.refresh(); break; + case 'toggleFavorite': + // update favorite collection + this.toggleFavorite(message.uri); + break; case 'loadView': // launch new view this.loadView(message.viewName, message.uri); @@ -384,6 +388,14 @@ export class NotebookView { } } // end of refreshView() + /** + * Updates favorite collection. + * @param notebookUrl Notebook url to add/remove from favorite notebooks collection. + */ + public async toggleFavorite(notebookUrl: string) { + notebookManager.addNotebook('favorite', this._notebook); + } + /** * Saves notebook in requested file formats. * @param fileType Notebook file type to save.