瀏覽代碼

Make notebook scrollPastEnd setting a configuration option.

Jason Grout 6 年之前
父節點
當前提交
7778852896

+ 6 - 0
packages/notebook-extension/schema/tracker.json

@@ -101,6 +101,12 @@
         "tabSize": 4,
         "wordWrapColumn": 80
       }
+    },
+    "scrollPastEnd": {
+      "title": "Scroll past last cell",
+      "description": "Whether to be able to scroll so the last cell is at the top of the panel",
+      "type": "boolean",
+      "default": true
     }
   },
   "additionalProperties": false,

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

@@ -465,6 +465,7 @@ function activateNotebookHandler(
   const services = app.serviceManager;
   // An object for tracking the current notebook settings.
   let editorConfig = StaticNotebook.defaultEditorConfig;
+  let notebookConfig = StaticNotebook.defaultNotebookConfig;
   const factory = new NotebookWidgetFactory({
     name: FACTORY,
     fileTypes: ['notebook'],
@@ -475,6 +476,7 @@ function activateNotebookHandler(
     rendermime: rendermime,
     contentFactory,
     editorConfig,
+    notebookConfig,
     mimeTypeService: editorServices.mimeTypeService
   });
   const { commands, restored } = app;
@@ -544,6 +546,9 @@ function activateNotebookHandler(
           : cached[key];
     });
     factory.editorConfig = editorConfig = { code, markdown, raw };
+    factory.notebookConfig = notebookConfig = {
+      scrollPastEnd: settings.get('scrollPastEnd').composite as boolean
+    };
   }
 
   /**
@@ -552,6 +557,7 @@ function activateNotebookHandler(
   function updateTracker(): void {
     tracker.forEach(widget => {
       widget.content.editorConfig = editorConfig;
+      widget.content.notebookConfig = notebookConfig;
     });
   }
 

+ 45 - 0
packages/notebook/src/widget.ts

@@ -169,6 +169,8 @@ export class StaticNotebook extends Widget {
       options.contentFactory || StaticNotebook.defaultContentFactory;
     this.editorConfig =
       options.editorConfig || StaticNotebook.defaultEditorConfig;
+    this.notebookConfig =
+      options.notebookConfig || StaticNotebook.defaultNotebookConfig;
     this._mimetypeService = options.mimeTypeService;
   }
 
@@ -261,6 +263,17 @@ export class StaticNotebook extends Widget {
     this._updateEditorConfig();
   }
 
+  /**
+   * A configuration object for notebook settings.
+   */
+  get notebookConfig(): StaticNotebook.INotebookConfig {
+    return this._notebookConfig;
+  }
+  set notebookConfig(value: StaticNotebook.INotebookConfig) {
+    this._notebookConfig = value;
+    this._updateNotebookConfig();
+  }
+
   /**
    * Dispose of the resources held by the widget.
    */
@@ -558,7 +571,18 @@ export class StaticNotebook extends Widget {
     }
   }
 
+  /**
+   * Update editor settings for notebook.
+   */
+  private _updateNotebookConfig() {
+    this.toggleClass(
+      'jp-mod-scrollPastEnd',
+      this._notebookConfig.scrollPastEnd
+    );
+  }
+
   private _editorConfig = StaticNotebook.defaultEditorConfig;
+  private _notebookConfig = StaticNotebook.defaultNotebookConfig;
   private _mimetype = 'text/plain';
   private _model: INotebookModel = null;
   private _mimetypeService: IEditorMimeTypeService;
@@ -594,6 +618,11 @@ export namespace StaticNotebook {
      */
     editorConfig?: IEditorConfig;
 
+    /**
+     * A configuration object for notebook settings.
+     */
+    notebookConfig?: INotebookConfig;
+
     /**
      * The service used to look up mime types.
      */
@@ -673,6 +702,22 @@ export namespace StaticNotebook {
     }
   };
 
+  /**
+   * A config object for the notebook widget
+   */
+  export interface INotebookConfig {
+    /**
+     * Enable scrolling past the last cell
+     */
+    scrollPastEnd: boolean;
+  }
+  /**
+   * Default configuration options for notebooks.
+   */
+  export const defaultNotebookConfig: INotebookConfig = {
+    scrollPastEnd: true
+  };
+
   /**
    * The default implementation of an `IContentFactory`.
    */

+ 20 - 1
packages/notebook/src/widgetfactory.ts

@@ -35,6 +35,8 @@ export class NotebookWidgetFactory extends ABCWidgetFactory<
     this.mimeTypeService = options.mimeTypeService;
     this._editorConfig =
       options.editorConfig || StaticNotebook.defaultEditorConfig;
+    this._notebookConfig =
+      options.notebookConfig || StaticNotebook.defaultNotebookConfig;
   }
 
   /*
@@ -62,6 +64,16 @@ export class NotebookWidgetFactory extends ABCWidgetFactory<
     this._editorConfig = value;
   }
 
+  /**
+   * A configuration object for notebook settings.
+   */
+  get notebookConfig(): StaticNotebook.INotebookConfig {
+    return this._notebookConfig;
+  }
+  set notebookConfig(value: StaticNotebook.INotebookConfig) {
+    this._notebookConfig = value;
+  }
+
   /**
    * Create a new widget.
    *
@@ -77,7 +89,8 @@ export class NotebookWidgetFactory extends ABCWidgetFactory<
       rendermime,
       contentFactory: this.contentFactory,
       mimeTypeService: this.mimeTypeService,
-      editorConfig: this._editorConfig
+      editorConfig: this._editorConfig,
+      notebookConfig: this._notebookConfig
     };
     let content = this.contentFactory.createNotebook(nbOptions);
 
@@ -94,6 +107,7 @@ export class NotebookWidgetFactory extends ABCWidgetFactory<
   }
 
   private _editorConfig: StaticNotebook.IEditorConfig;
+  private _notebookConfig: StaticNotebook.INotebookConfig;
 }
 
 /**
@@ -124,5 +138,10 @@ export namespace NotebookWidgetFactory {
      * The notebook cell editor configuration.
      */
     editorConfig?: StaticNotebook.IEditorConfig;
+
+    /**
+     * The notebook configuration.
+     */
+    notebookConfig?: StaticNotebook.INotebookConfig;
   }
 }

+ 1 - 1
packages/notebook/style/index.css

@@ -41,7 +41,7 @@
   background: var(--jp-layout-color0);
 }
 
-.jp-Notebook::after {
+.jp-Notebook.jp-mod-scrollPastEnd::after {
   display: block;
   content: '';
   min-height: var(--jp-notebook-scroll-padding);

+ 4 - 1
packages/theme-dark-extension/style/variables.css

@@ -286,7 +286,10 @@ all of MD as it is not optimized for dense, information rich UIs.
   pixel so that no scrollbar appears if we have just one single-line cell in the
   notebook. This padding is to enable a 'scroll past end' feature in a notebook.
   */
-  --jp-notebook-scroll-padding: calc(100% - var(--jp-code-font-size)*var(--jp-code-line-height) - var(--jp-code-padding) - var(--jp-cell-padding) - 1px);
+  --jp-notebook-scroll-padding: calc(
+    100% - var(--jp-code-font-size) * var(--jp-code-line-height) -
+      var(--jp-code-padding) - var(--jp-cell-padding) - 1px
+  );
 
   /* Rendermime styles */
 

+ 4 - 1
packages/theme-light-extension/style/variables.css

@@ -283,7 +283,10 @@ all of MD as it is not optimized for dense, information rich UIs.
   pixel so that no scrollbar appears if we have just one single-line cell in the
   notebook. This padding is to enable a 'scroll past end' feature in a notebook.
   */
-  --jp-notebook-scroll-padding: calc(100% - var(--jp-code-font-size)*var(--jp-code-line-height) - var(--jp-code-padding) - var(--jp-cell-padding) - 1px);
+  --jp-notebook-scroll-padding: calc(
+    100% - var(--jp-code-font-size) * var(--jp-code-line-height) -
+      var(--jp-code-padding) - var(--jp-cell-padding) - 1px
+  );
 
   /* Rendermime styles */