Skip to content

Commit

Permalink
Fixes experimental document-wide undo/redo flag (#117)
Browse files Browse the repository at this point in the history
* Adds disable document wide undo/redo setting

* Prevent reloading page without user consent

* pre-commit

* Review
  • Loading branch information
hbcarlos authored Mar 7, 2023
1 parent cdbde52 commit 0d7d5e8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@
"@lumino/virtualdom": "^2.0.0-beta.0",
"@lumino/widgets": "^2.0.0-beta.1"
}
}
}
1 change: 1 addition & 0 deletions packages/collaboration-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 32 additions & 2 deletions packages/collaboration-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IFileBrowserFactory
} from '@jupyterlab/filebrowser';
import { ITranslator } from '@jupyterlab/translation';
import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { CommandRegistry } from '@lumino/commands';

Expand All @@ -29,14 +30,20 @@ export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
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<IDefaultFileBrowser> => {
console.debug(
'@jupyter/collaboration-extension:defaultFileBrowser: activated'
Expand All @@ -60,6 +67,29 @@ export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
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;
}
};
Expand Down
17 changes: 14 additions & 3 deletions packages/docprovider/src/ydrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class YDrive extends Drive {
/**
* SharedModel factory for the YDrive.
*/
readonly sharedModelFactory: Contents.ISharedFactory;
readonly sharedModelFactory: SharedModelFactory;

/**
* Delete a file.
Expand Down Expand Up @@ -189,18 +189,29 @@ export class YDrive extends Drive {
* Yjs sharedModel factory for real-time collaboration.
*/
class SharedModelFactory implements Contents.ISharedFactory {
private _documentOptions: Map<Contents.ContentType, Record<string, any>>;

constructor(
private _onCreate: (
options: Contents.ISharedFactoryOptions,
sharedModel: YDocument<DocumentChange>
) => 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<string, any>) {
this._documentOptions.set(type, value);
}

/**
* Create a new `ISharedDocument` instance.
*
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion packages/docprovider/src/yprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0d7d5e8

Please sign in to comment.