diff --git a/package.json b/package.json index 36ec8706..6e958982 100644 --- a/package.json +++ b/package.json @@ -78,4 +78,4 @@ "@lumino/virtualdom": "^2.0.0-beta.0", "@lumino/widgets": "^2.0.0-beta.1" } -} \ No newline at end of file +} diff --git a/packages/collaboration-extension/package.json b/packages/collaboration-extension/package.json index 09e5a8f7..55f488a8 100644 --- a/packages/collaboration-extension/package.json +++ b/packages/collaboration-extension/package.json @@ -59,6 +59,7 @@ "@jupyterlab/coreutils": "^6.0.0-alpha.19", "@jupyterlab/filebrowser": "^4.0.0-alpha.19", "@jupyterlab/services": "^7.0.0-alpha.19", + "@jupyterlab/settingregistry": "^4.0.0-alpha.19", "@jupyterlab/statedb": "^4.0.0-alpha.19", "@jupyterlab/translation": "^4.0.0-alpha.19", "@jupyterlab/ui-components": "^4.0.0-alpha.34", diff --git a/packages/collaboration-extension/src/filebrowser.ts b/packages/collaboration-extension/src/filebrowser.ts index 000ee55d..7626199f 100644 --- a/packages/collaboration-extension/src/filebrowser.ts +++ b/packages/collaboration-extension/src/filebrowser.ts @@ -10,6 +10,7 @@ import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; import { ITranslator } from '@jupyterlab/translation'; +import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { CommandRegistry } from '@lumino/commands'; @@ -29,14 +30,20 @@ export const defaultFileBrowser: JupyterFrontEndPlugin = { id: '@jupyter/collaboration-extension:defaultFileBrowser', provides: IDefaultFileBrowser, requires: [IFileBrowserFactory, ITranslator], - optional: [IRouter, JupyterFrontEnd.ITreeResolver, ILabShell], + optional: [ + IRouter, + JupyterFrontEnd.ITreeResolver, + ILabShell, + ISettingRegistry + ], activate: async ( app: JupyterFrontEnd, fileBrowserFactory: IFileBrowserFactory, translator: ITranslator, router: IRouter | null, tree: JupyterFrontEnd.ITreeResolver | null, - labShell: ILabShell | null + labShell: ILabShell | null, + settingRegistry: ISettingRegistry | null ): Promise => { console.debug( '@jupyter/collaboration-extension:defaultFileBrowser: activated' @@ -60,6 +67,29 @@ export const defaultFileBrowser: JupyterFrontEndPlugin = { tree, labShell ); + + // Fetch settings if possible. + if (settingRegistry) { + settingRegistry + .load('@jupyterlab/notebook-extension:tracker') + .then(settings => { + const updateSettings = (settings: ISettingRegistry.ISettings) => { + const enableDocWideUndo = settings?.get( + 'experimentalEnableDocumentWideUndoRedo' + ).composite as boolean; + + drive.sharedModelFactory.setDocumentOptions('notebook', { + disableDocumentWideUndoRedo: !enableDocWideUndo ?? true + }); + }; + + updateSettings(settings); + settings.changed.connect((settings: ISettingRegistry.ISettings) => + updateSettings(settings) + ); + }); + } + return defaultBrowser; } }; diff --git a/packages/docprovider/src/ydrive.ts b/packages/docprovider/src/ydrive.ts index f1cc00e9..8e9e9c07 100644 --- a/packages/docprovider/src/ydrive.ts +++ b/packages/docprovider/src/ydrive.ts @@ -40,7 +40,7 @@ export class YDrive extends Drive { /** * SharedModel factory for the YDrive. */ - readonly sharedModelFactory: Contents.ISharedFactory; + readonly sharedModelFactory: SharedModelFactory; /** * Delete a file. @@ -189,18 +189,29 @@ export class YDrive extends Drive { * Yjs sharedModel factory for real-time collaboration. */ class SharedModelFactory implements Contents.ISharedFactory { + private _documentOptions: Map>; + constructor( private _onCreate: ( options: Contents.ISharedFactoryOptions, sharedModel: YDocument ) => void - ) {} + ) { + this._documentOptions = new Map(); + this._documentOptions.set('notebook', { + disableDocumentWideUndoRedo: true + }); + } /** * Whether the IDrive supports real-time collaboration or not. */ readonly collaborative = true; + setDocumentOptions(type: Contents.ContentType, value: Record) { + this._documentOptions.set(type, value); + } + /** * Create a new `ISharedDocument` instance. * @@ -224,7 +235,7 @@ class SharedModelFactory implements Contents.ISharedFactory { sharedModel = new YFile(); break; case 'notebook': - sharedModel = new YNotebook(); + sharedModel = new YNotebook(this._documentOptions.get('notebook')); break; //default: // FIXME we should request a registry for the proper sharedModel diff --git a/packages/docprovider/src/yprovider.ts b/packages/docprovider/src/yprovider.ts index 52bcf541..6ba7fbaa 100644 --- a/packages/docprovider/src/yprovider.ts +++ b/packages/docprovider/src/yprovider.ts @@ -128,7 +128,11 @@ export class WebSocketProvider implements IDocumentProvider { ), [Dialog.okButton({ label: this._trans.__('Reload') })] ) - .then(r => window.location.reload()) + .then((r: any) => { + if (r.button.accept) { + window.location.reload(); + } + }) .catch(e => window.location.reload()); // Dispose shared model immediately. Better break the document model,