Преглед на файлове

Output area calls a new protected function to determine if outputs should be combined.

This allows subclasses of output area to define their own collapsing semantics, which may be less aggressive than the default output area behavior.
Jason Grout преди 5 години
родител
ревизия
d59af071aa
променени са 1 файла, в които са добавени 18 реда и са изтрити 1 реда
  1. 18 1
      packages/outputarea/src/model.ts

+ 18 - 1
packages/outputarea/src/model.ts

@@ -307,7 +307,11 @@ export class OutputAreaModel implements IOutputAreaModel {
     if (
       nbformat.isStream(value) &&
       this._lastStream &&
-      value.name === this._lastName
+      value.name === this._lastName &&
+      this.shouldCombine({
+        value,
+        lastModel: this.list.get(this.length - 1)
+      })
     ) {
       // In order to get a list change event, we add the previous
       // text to the current item and replace the previous item.
@@ -342,6 +346,19 @@ export class OutputAreaModel implements IOutputAreaModel {
     return this.list.push(item);
   }
 
+  /**
+   * Whether a new value should be consolidated with the previous output.
+   *
+   * This will only be called if the minimal criteria of both being stream
+   * messages of the same type.
+   */
+  protected shouldCombine(options: {
+    value: nbformat.IOutput;
+    lastModel: IOutputModel;
+  }) {
+    return true;
+  }
+
   /**
    * A flag that is set when we want to clear the output area
    * *after* the next addition to it.