4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import type { ActivationFunction , OutputItem , RendererContext } from 'vscode-notebook-renderer' ;
7
- import { createOutputContent , scrollableClass } from './textHelper' ;
7
+ import { appendOutput , createOutputContent , scrollableClass } from './textHelper' ;
8
8
import { HtmlRenderingHook , IDisposable , IRichRenderContext , JavaScriptRenderingHook , RenderOptions } from './rendererTypes' ;
9
9
import { ttPolicy } from './htmlHelper' ;
10
10
@@ -172,7 +172,7 @@ function renderError(
172
172
outputElement . classList . add ( 'traceback' ) ;
173
173
174
174
const outputScrolling = scrollingEnabled ( outputInfo , ctx . settings ) ;
175
- const content = createOutputContent ( outputInfo . id , [ err . stack ?? '' ] , ctx . settings . lineLimit , outputScrolling , trustHTML ) ;
175
+ const content = createOutputContent ( outputInfo . id , err . stack ?? '' , ctx . settings . lineLimit , outputScrolling , trustHTML ) ;
176
176
const contentParent = document . createElement ( 'div' ) ;
177
177
contentParent . classList . toggle ( 'word-wrap' , ctx . settings . outputWordWrap ) ;
178
178
disposableStore . push ( ctx . onDidChangeSettings ( e => {
@@ -276,26 +276,19 @@ interface OutputWithAppend extends OutputItem {
276
276
// div output-item-id="{guid}" <-- content from outputItem parameter
277
277
function renderStream ( outputInfo : OutputWithAppend , outputElement : HTMLElement , error : boolean , ctx : IRichRenderContext ) : IDisposable {
278
278
const appendedText = outputInfo . appendedText ?.( ) ;
279
- if ( appendedText ) {
280
- console . log ( `appending output version ${ appendedText } ` ) ;
281
- }
282
279
const disposableStore = createDisposableStore ( ) ;
283
280
const outputScrolling = scrollingEnabled ( outputInfo , ctx . settings ) ;
284
281
285
282
outputElement . classList . add ( 'output-stream' ) ;
286
283
287
- const text = outputInfo . text ( ) ;
288
- const newContent = createOutputContent ( outputInfo . id , [ text ] , ctx . settings . lineLimit , outputScrolling , false ) ;
289
- newContent . setAttribute ( 'output-item-id' , outputInfo . id ) ;
290
- if ( error ) {
291
- newContent . classList . add ( 'error' ) ;
292
- }
284
+
293
285
294
286
const scrollTop = outputScrolling ? findScrolledHeight ( outputElement ) : undefined ;
295
287
296
288
const previousOutputParent = getPreviousMatchingContentGroup ( outputElement ) ;
297
289
// If the previous output item for the same cell was also a stream, append this output to the previous
298
290
if ( previousOutputParent ) {
291
+ const newContent = createContent ( outputInfo , ctx , outputScrolling , error ) ;
299
292
const existingContent = previousOutputParent . querySelector ( `[output-item-id="${ outputInfo . id } "]` ) as HTMLElement | null ;
300
293
if ( existingContent ) {
301
294
existingContent . replaceWith ( newContent ) ;
@@ -309,15 +302,19 @@ function renderStream(outputInfo: OutputWithAppend, outputElement: HTMLElement,
309
302
const existingContent = outputElement . querySelector ( `[output-item-id="${ outputInfo . id } "]` ) as HTMLElement | null ;
310
303
let contentParent = existingContent ?. parentElement ;
311
304
if ( existingContent && contentParent ) {
312
- if ( appendedText ) {
313
- existingContent
305
+ if ( appendedText ) {
306
+ appendOutput ( existingContent , outputInfo . id , appendedText , ctx . settings . lineLimit , outputScrolling , false ) ;
314
307
}
315
- existingContent . replaceWith ( newContent ) ;
316
- while ( newContent . nextSibling ) {
317
- // clear out any stale content if we had previously combined streaming outputs into this one
318
- newContent . nextSibling . remove ( ) ;
308
+ else {
309
+ const newContent = createContent ( outputInfo , ctx , outputScrolling , error ) ;
310
+ existingContent . replaceWith ( newContent ) ;
311
+ while ( newContent . nextSibling ) {
312
+ // clear out any stale content if we had previously combined streaming outputs into this one
313
+ newContent . nextSibling . remove ( ) ;
314
+ }
319
315
}
320
316
} else {
317
+ const newContent = createContent ( outputInfo , ctx , outputScrolling , error ) ;
321
318
contentParent = document . createElement ( 'div' ) ;
322
319
contentParent . appendChild ( newContent ) ;
323
320
while ( outputElement . firstChild ) {
@@ -338,13 +335,23 @@ function renderStream(outputInfo: OutputWithAppend, outputElement: HTMLElement,
338
335
return disposableStore ;
339
336
}
340
337
338
+ function createContent ( outputInfo : OutputWithAppend , ctx : IRichRenderContext , outputScrolling : boolean , error : boolean ) {
339
+ const text = outputInfo . text ( ) ;
340
+ const newContent = createOutputContent ( outputInfo . id , text , ctx . settings . lineLimit , outputScrolling , false ) ;
341
+ newContent . setAttribute ( 'output-item-id' , outputInfo . id ) ;
342
+ if ( error ) {
343
+ newContent . classList . add ( 'error' ) ;
344
+ }
345
+ return newContent ;
346
+ }
347
+
341
348
function renderText ( outputInfo : OutputItem , outputElement : HTMLElement , ctx : IRichRenderContext ) : IDisposable {
342
349
const disposableStore = createDisposableStore ( ) ;
343
350
clearContainer ( outputElement ) ;
344
351
345
352
const text = outputInfo . text ( ) ;
346
353
const outputScrolling = scrollingEnabled ( outputInfo , ctx . settings ) ;
347
- const content = createOutputContent ( outputInfo . id , [ text ] , ctx . settings . lineLimit , outputScrolling , false ) ;
354
+ const content = createOutputContent ( outputInfo . id , text , ctx . settings . lineLimit , outputScrolling , false ) ;
348
355
content . classList . add ( 'output-plaintext' ) ;
349
356
if ( ctx . settings . outputWordWrap ) {
350
357
content . classList . add ( 'word-wrap' ) ;
0 commit comments