소스 검색

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.