@@ -10,7 +10,7 @@ const DISPLAY_NONE_TAGS = ['script', 'style'];
1010let after_show_callbacks : ( ( ) => void ) [ ] = [ ] ;
1111
1212// register a callback to execute after the current output widget showing
13- export function AfterCurrentOutputWidgetShow ( callback : ( ) => void ) {
13+ export function AfterCurrentOutputWidgetShow ( callback : ( ) => void ) {
1414 after_show_callbacks . push ( callback ) ;
1515}
1616
@@ -86,7 +86,7 @@ export class OutputHandler implements CommandHandler {
8686
8787 // to avoid widget width exceeding page width
8888 // show horizon scroll bar when content too wide
89- if ( elem . width ( ) > this . container_elem . width ( ) )
89+ if ( elem . width ( ) > this . container_elem . width ( ) )
9090 elem . wrap ( $ ( document . createElement ( 'div' ) ) . css ( 'overflow' , 'auto' ) ) ;
9191
9292 if ( this . is_elem_visible ( elem ) && container_elem . length == 1 ) { // 输出内容为可见标签且输出目的scope唯一
@@ -127,11 +127,20 @@ export class OutputHandler implements CommandHandler {
127127 else if ( spec . if_exist == 'clear' ) {
128128 old . empty ( ) ;
129129 return ;
130+ } else if ( spec . if_exist == 'blank' ) { // Clear the contents of the old scope and keep the height
131+ let scope_css : any = { 'min-height' : old . height ( ) } ;
132+ let prev = old . prev ( ) , next = old . next ( ) ;
133+ if ( prev . length )
134+ scope_css [ 'margin-top' ] = old [ 0 ] . getBoundingClientRect ( ) . top - prev [ 0 ] . getBoundingClientRect ( ) . bottom ;
135+ if ( next . length )
136+ scope_css [ 'margin-bottom' ] = next [ 0 ] . getBoundingClientRect ( ) . top - old [ 0 ] . getBoundingClientRect ( ) . bottom ;
137+ old . css ( scope_css ) ;
138+ old . empty ( ) ;
139+ return ;
130140 } else {
131141 return ;
132142 }
133143 }
134-
135144 let html = `<div id="${ spec . set_scope } "></div>` ;
136145 if ( spec . position === 0 )
137146 container_elem . prepend ( html ) ;
@@ -144,6 +153,9 @@ export class OutputHandler implements CommandHandler {
144153 $ ( `${ spec . container } > *` ) . eq ( spec . position ) . insertAfter ( html ) ;
145154 }
146155 }
156+ if ( msg . spec . loose !== undefined ) { // revoke the effect of ``set_scope(if_exist='blank')``
157+ $ ( msg . spec . loose ) . css ( { 'min-height' : '' , 'margin-top' : '' , 'margin-bottom' : '' } ) ;
158+ }
147159 if ( msg . spec . clear !== undefined ) {
148160 $ ( msg . spec . clear ) . empty ( ) ;
149161 }
0 commit comments