浏览代码

Add an activity monitor to markdown cells.

Ian Rose 8 年之前
父节点
当前提交
b95830f347
共有 1 个文件被更改,包括 18 次插入1 次删除
  1. 18 1
      packages/cells/src/widget.ts

+ 18 - 1
packages/cells/src/widget.ts

@@ -22,11 +22,12 @@ import {
 } from '@phosphor/widgets';
 
 import {
+<<<<<<< HEAD
   IClientSession
 } from '@jupyterlab/apputils';
 
 import {
-  IChangedArgs
+  IChangedArgs, ActivityMonitor
 } from '@jupyterlab/coreutils';
 
 import {
@@ -142,6 +143,10 @@ const NO_OUTPUTS_CLASS = 'jp-mod-noOutputs';
  */
 const DEFAULT_MARKDOWN_TEXT = 'Type Markdown and LaTeX: $ α^2 $';
 
+/**
+ * The timeout to wait for change activity to have ceased before rendering.
+ */
+const RENDER_TIMEOUT = 1000;
 
 /******************************************************************************
  * Cell
@@ -669,6 +674,17 @@ class MarkdownCell extends Cell {
     this.addClass(MARKDOWN_CELL_CLASS);
     this._rendermime = options.rendermime;
     this.editor.wordWrap = true;
+
+    // Throttle the rendering rate of the widget.
+    this._monitor = new ActivityMonitor({
+      signal: this.model.contentChanged,
+      timeout: RENDER_TIMEOUT
+    });
+    this._monitor.activityStopped.connect(()=>{
+      if(this._rendered) {
+        this.update();
+      }
+    }, this);
   }
 
   /**
@@ -759,6 +775,7 @@ class MarkdownCell extends Cell {
     this._prevTrusted = trusted;
   }
 
+  private _monitor: ActivityMonitor<any, any> = null;
   private _rendermime: RenderMime = null;
   private _renderedInput: Widget = null;
   private _rendered = true;