44 *--------------------------------------------------------------------------------------------*/
55
66import type { ActivationFunction , OutputItem , RendererContext } from 'vscode-notebook-renderer' ;
7- import { createOutputContent , scrollableClass } from './textHelper' ;
7+ import { appendOutput , createOutputContent , scrollableClass } from './textHelper' ;
88import { HtmlRenderingHook , IDisposable , IRichRenderContext , JavaScriptRenderingHook , RenderOptions } from './rendererTypes' ;
99import { ttPolicy } from './htmlHelper' ;
1010
@@ -172,7 +172,7 @@ function renderError(
172172 outputElement . classList . add ( 'traceback' ) ;
173173
174174 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 ) ;
176176 const contentParent = document . createElement ( 'div' ) ;
177177 contentParent . classList . toggle ( 'word-wrap' , ctx . settings . outputWordWrap ) ;
178178 disposableStore . push ( ctx . onDidChangeSettings ( e => {
@@ -276,26 +276,19 @@ interface OutputWithAppend extends OutputItem {
276276// div output-item-id="{guid}" <-- content from outputItem parameter
277277function renderStream ( outputInfo : OutputWithAppend , outputElement : HTMLElement , error : boolean , ctx : IRichRenderContext ) : IDisposable {
278278 const appendedText = outputInfo . appendedText ?.( ) ;
279- if ( appendedText ) {
280- console . log ( `appending output version ${ appendedText } ` ) ;
281- }
282279 const disposableStore = createDisposableStore ( ) ;
283280 const outputScrolling = scrollingEnabled ( outputInfo , ctx . settings ) ;
284281
285282 outputElement . classList . add ( 'output-stream' ) ;
286283
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+
293285
294286 const scrollTop = outputScrolling ? findScrolledHeight ( outputElement ) : undefined ;
295287
296288 const previousOutputParent = getPreviousMatchingContentGroup ( outputElement ) ;
297289 // If the previous output item for the same cell was also a stream, append this output to the previous
298290 if ( previousOutputParent ) {
291+ const newContent = createContent ( outputInfo , ctx , outputScrolling , error ) ;
299292 const existingContent = previousOutputParent . querySelector ( `[output-item-id="${ outputInfo . id } "]` ) as HTMLElement | null ;
300293 if ( existingContent ) {
301294 existingContent . replaceWith ( newContent ) ;
@@ -309,15 +302,19 @@ function renderStream(outputInfo: OutputWithAppend, outputElement: HTMLElement,
309302 const existingContent = outputElement . querySelector ( `[output-item-id="${ outputInfo . id } "]` ) as HTMLElement | null ;
310303 let contentParent = existingContent ?. parentElement ;
311304 if ( existingContent && contentParent ) {
312- if ( appendedText ) {
313- existingContent
305+ if ( appendedText ) {
306+ appendOutput ( existingContent , outputInfo . id , appendedText , ctx . settings . lineLimit , outputScrolling , false ) ;
314307 }
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+ }
319315 }
320316 } else {
317+ const newContent = createContent ( outputInfo , ctx , outputScrolling , error ) ;
321318 contentParent = document . createElement ( 'div' ) ;
322319 contentParent . appendChild ( newContent ) ;
323320 while ( outputElement . firstChild ) {
@@ -338,13 +335,23 @@ function renderStream(outputInfo: OutputWithAppend, outputElement: HTMLElement,
338335 return disposableStore ;
339336}
340337
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+
341348function renderText ( outputInfo : OutputItem , outputElement : HTMLElement , ctx : IRichRenderContext ) : IDisposable {
342349 const disposableStore = createDisposableStore ( ) ;
343350 clearContainer ( outputElement ) ;
344351
345352 const text = outputInfo . text ( ) ;
346353 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 ) ;
348355 content . classList . add ( 'output-plaintext' ) ;
349356 if ( ctx . settings . outputWordWrap ) {
350357 content . classList . add ( 'word-wrap' ) ;
0 commit comments