Browse Source

Use disableDocumentWideUndoRedo instead of enableDocumentWideUndoRedo (#11215)

* Use disableDocumentWideUndoRedo instead of enableDocumentWideUndoRedo

* NotebookModelFactory test to use disableDocumentWideUndoRedo
Eric Charles 3 years ago
parent
commit
de948d1c6a

+ 3 - 3
packages/notebook-extension/schema/tracker.json

@@ -818,11 +818,11 @@
       "type": "number",
       "default": 50
     },
-    "experimentalEnableDocumentWideUndoRedo": {
+    "experimentalDisableDocumentWideUndoRedo": {
       "title": "Experimental settings to enable the undo/redo on the notebook document level.",
-      "description": "Enable the undo/redo on the notebook document level, so actions like cells move, change... can have history. The undo/redo never applies on the outputs, in other words, outputs don't have history.",
+      "description": "Disable the undo/redo on the notebook document level, so actions independent cells can have their own history. The undo/redo never applies on the outputs, in other words, outputs don't have history. A moved cell completely looses history capability for now.",
       "type": "boolean",
-      "default": true
+      "default": false
     }
   },
   "additionalProperties": false,

+ 6 - 6
packages/notebook-extension/src/index.ts

@@ -1117,8 +1117,8 @@ function activateNotebookHandler(
 
   const registry = app.docRegistry;
   const modelFactory = new NotebookModelFactory({
-    enableDocumentWideUndoRedo:
-      factory.notebookConfig.enableDocumentWideUndoRedo
+    disableDocumentWideUndoRedo:
+      factory.notebookConfig.disableDocumentWideUndoRedo
   });
   registry.addModelFactory(modelFactory);
 
@@ -1189,15 +1189,15 @@ function activateNotebookHandler(
       observedBottomMargin: settings.get('observedBottomMargin')
         .composite as string,
       maxNumberOutputs: settings.get('maxNumberOutputs').composite as number,
-      enableDocumentWideUndoRedo: settings.get(
-        'experimentalEnableDocumentWideUndoRedo'
+      disableDocumentWideUndoRedo: settings.get(
+        'experimentalDisableDocumentWideUndoRedo'
       ).composite as boolean
     };
     factory.shutdownOnClose = settings.get('kernelShutdown')
       .composite as boolean;
 
-    modelFactory.enableDocumentWideUndoRedo = settings.get(
-      'experimentalEnableDocumentWideUndoRedo'
+    modelFactory.disableDocumentWideUndoRedo = settings.get(
+      'experimentalDisableDocumentWideUndoRedo'
     ).composite as boolean;
 
     updateTracker({

+ 2 - 2
packages/notebook/src/model.ts

@@ -90,7 +90,7 @@ export class NotebookModel implements INotebookModel {
       this.modelDB = new ModelDB();
     }
     this.sharedModel = models.YNotebook.create(
-      options.enableDocumentWideUndoRedo || false
+      options.disableDocumentWideUndoRedo || false
     ) as models.ISharedNotebook;
     this._isInitialized = options.isInitialized === false ? false : true;
     const factory =
@@ -565,7 +565,7 @@ export namespace NotebookModel {
     /**
      * Defines if the document can be undo/redo.
      */
-    enableDocumentWideUndoRedo?: boolean;
+    disableDocumentWideUndoRedo?: boolean;
   }
 
   /**

+ 8 - 8
packages/notebook/src/modelfactory.ts

@@ -16,8 +16,8 @@ export class NotebookModelFactory
    * Construct a new notebook model factory.
    */
   constructor(options: NotebookModelFactory.IOptions) {
-    this._enableDocumentWideUndoRedo =
-      options.enableDocumentWideUndoRedo || false;
+    this._disableDocumentWideUndoRedo =
+      options.disableDocumentWideUndoRedo || false;
     const codeCellContentFactory = options.codeCellContentFactory;
     this.contentFactory =
       options.contentFactory ||
@@ -30,10 +30,10 @@ export class NotebookModelFactory
   readonly contentFactory: NotebookModel.IContentFactory;
 
   /**
-   * Define the enableDocumentWideUndoRedo property.
+   * Define the disableDocumentWideUndoRedo property.
    */
-  set enableDocumentWideUndoRedo(enableDocumentWideUndoRedo: boolean) {
-    this._enableDocumentWideUndoRedo = enableDocumentWideUndoRedo;
+  set disableDocumentWideUndoRedo(disableDocumentWideUndoRedo: boolean) {
+    this._disableDocumentWideUndoRedo = disableDocumentWideUndoRedo;
   }
 
   /**
@@ -89,7 +89,7 @@ export class NotebookModelFactory
       contentFactory,
       modelDB,
       isInitialized,
-      enableDocumentWideUndoRedo: this._enableDocumentWideUndoRedo
+      disableDocumentWideUndoRedo: this._disableDocumentWideUndoRedo
     });
   }
 
@@ -103,7 +103,7 @@ export class NotebookModelFactory
   /**
    * Defines if the document can be undo/redo.
    */
-  private _enableDocumentWideUndoRedo: boolean;
+  private _disableDocumentWideUndoRedo: boolean;
 
   private _disposed = false;
 }
@@ -119,7 +119,7 @@ export namespace NotebookModelFactory {
     /**
      * Defines if the document can be undo/redo.
      */
-    enableDocumentWideUndoRedo?: boolean;
+    disableDocumentWideUndoRedo?: boolean;
 
     /**
      * The factory for code cell content.

+ 2 - 2
packages/notebook/src/widget.ts

@@ -964,7 +964,7 @@ export namespace StaticNotebook {
     /**
      * Defines if the document can be undo/redo.
      */
-    enableDocumentWideUndoRedo: boolean;
+    disableDocumentWideUndoRedo: boolean;
   }
 
   /**
@@ -979,7 +979,7 @@ export namespace StaticNotebook {
     observedTopMargin: '1000px',
     observedBottomMargin: '1000px',
     maxNumberOutputs: 50,
-    enableDocumentWideUndoRedo: true
+    disableDocumentWideUndoRedo: false
   };
 
   /**

+ 1 - 1
packages/notebook/test/actions.spec.ts

@@ -63,7 +63,7 @@ describe('@jupyterlab/notebook', () => {
         mimeTypeService: utils.mimeTypeService
       });
       const model = new NotebookModel({
-        enableDocumentWideUndoRedo: true
+        disableDocumentWideUndoRedo: true
       });
       model.fromJSON(utils.DEFAULT_CONTENT);
       widget.model = model;

+ 2 - 2
packages/notebook/test/model.spec.ts

@@ -73,7 +73,7 @@ describe('@jupyterlab/notebook', () => {
 
       it('should allow undoing a change', () => {
         const model = new NotebookModel({
-          enableDocumentWideUndoRedo: true
+          disableDocumentWideUndoRedo: true
         });
         const cell = model.contentFactory.createCodeCell({});
         cell.value.text = 'foo';
@@ -381,7 +381,7 @@ describe('@jupyterlab/notebook', () => {
 
       it('should clear undo state', () => {
         const model = new NotebookModel({
-          enableDocumentWideUndoRedo: true
+          disableDocumentWideUndoRedo: true
         });
         const cell = model.contentFactory.createCodeCell({});
         cell.value.text = 'foo';

+ 1 - 1
packages/notebook/test/widget.spec.ts

@@ -42,7 +42,7 @@ const notebookConfig = {
   observedTopMargin: '1000px',
   observedBottomMargin: '1000px',
   maxNumberOutputs: 50,
-  enableDocumentWideUndoRedo: true
+  disableDocumentWideUndoRedo: true
 };
 
 const options: Notebook.IOptions = {

+ 1 - 1
packages/shared-models/src/api.ts

@@ -225,7 +225,7 @@ export namespace ISharedNotebook {
      * Wether the the undo/redo logic should be
      * considered on the full document across all cells.
      */
-    enableDocumentWideUndoRedo: boolean;
+    disableDocumentWideUndoRedo: boolean;
   }
 }
 

+ 16 - 13
packages/shared-models/src/ymodels.ts

@@ -201,7 +201,7 @@ export class YNotebook
   implements models.ISharedNotebook {
   constructor(options: ISharedNotebook.IOptions) {
     super();
-    this._enableDocumentWideUndoRedo = options.enableDocumentWideUndoRedo;
+    this._disableDocumentWideUndoRedo = options.disableDocumentWideUndoRedo;
     this.ycells.observe(this._onYCellsChanged);
     this.cells = this.ycells.toArray().map(ycell => {
       if (!this._ycellMapping.has(ycell)) {
@@ -275,7 +275,7 @@ export class YNotebook
   insertCells(index: number, cells: YCellType[]): void {
     cells.forEach(cell => {
       this._ycellMapping.set(cell.ymodel, cell);
-      if (this.enableDocumentWideUndoRedo) {
+      if (!this.disableDocumentWideUndoRedo) {
         cell.undoManager = this.undoManager;
       }
     });
@@ -357,19 +357,19 @@ export class YNotebook
    * Create a new YNotebook.
    */
   public static create(
-    enableDocumentWideUndoRedo: boolean
+    disableDocumentWideUndoRedo: boolean
   ): models.ISharedNotebook {
-    return new YNotebook({ enableDocumentWideUndoRedo });
+    return new YNotebook({ disableDocumentWideUndoRedo });
   }
 
   /**
    * Wether the the undo/redo logic should be
    * considered on the full document across all cells.
    *
-   * @return The enableDocumentWideUndoRedo setting.
+   * @return The disableDocumentWideUndoRedo setting.
    */
-  get enableDocumentWideUndoRedo(): boolean {
-    return this._enableDocumentWideUndoRedo;
+  get disableDocumentWideUndoRedo(): boolean {
+    return this._disableDocumentWideUndoRedo;
   }
 
   /**
@@ -384,7 +384,7 @@ export class YNotebook
       }
       const cell = this._ycellMapping.get(type) as any;
       cell._notebook = this;
-      if (this.enableDocumentWideUndoRedo) {
+      if (!this.disableDocumentWideUndoRedo) {
         cell._undoManager = this.undoManager;
       } else {
         cell._undoManager = new Y.UndoManager([cell.ymodel], {});
@@ -460,7 +460,7 @@ export class YNotebook
   public undoManager = new Y.UndoManager([this.ycells], {
     trackedOrigins: new Set([this])
   });
-  private _enableDocumentWideUndoRedo: boolean;
+  private _disableDocumentWideUndoRedo: boolean;
   private _ycellMapping: Map<Y.Map<any>, YCellType> = new Map();
   public cells: YCellType[];
 }
@@ -530,9 +530,12 @@ export class YBaseCell<Metadata extends models.ISharedBaseCellMetadata>
    * The notebook that this cell belongs to.
    */
   get undoManager(): Y.UndoManager | null {
-    return this.notebook?.enableDocumentWideUndoRedo
-      ? this.notebook.undoManager
-      : this._undoManager;
+    if (!this.notebook) {
+      return this._undoManager;
+    }
+    return this.notebook?.disableDocumentWideUndoRedo
+      ? this._undoManager
+      : this.notebook.undoManager;
   }
 
   /**
@@ -640,7 +643,7 @@ export class YBaseCell<Metadata extends models.ISharedBaseCellMetadata>
     ymodel.set('id', this.getId());
     const Self: any = this.constructor;
     const clone = new Self(ymodel);
-    // TODO The assignmenet of the undoManager does not work for a clone.
+    // TODO The assignment of the undoManager does not work for a clone.
     // See https://github.com/jupyterlab/jupyterlab/issues/11035
     clone._undoManager = this.undoManager;
     return clone;

+ 1 - 1
testutils/src/common.ts

@@ -385,7 +385,7 @@ namespace Private {
   export const textFactory = new TextModelFactory();
 
   export const notebookFactory = new NotebookModelFactory({
-    enableDocumentWideUndoRedo: true
+    disableDocumentWideUndoRedo: false
   });
 
   /**