@@ -89,11 +89,19 @@ function equalUnderline(cell1: IBufferCell | IAttributeData, cell2: IBufferCell)
8989 if ( ! cell1 . isUnderline ( ) && ! cell2 . isUnderline ( ) ) {
9090 return true ;
9191 }
92- const cell1Data = cell1 as unknown as IAttributeData ;
93- const cell2Data = cell2 as unknown as IAttributeData ;
94- return cell1Data . getUnderlineStyle ( ) === cell2Data . getUnderlineStyle ( )
95- && cell1Data . getUnderlineColor ( ) === cell2Data . getUnderlineColor ( )
96- && cell1Data . getUnderlineColorMode ( ) === cell2Data . getUnderlineColorMode ( ) ;
92+ if ( cell1 . getUnderlineStyle ( ) !== cell2 . getUnderlineStyle ( ) ) {
93+ return false ;
94+ }
95+ const cell1Default = cell1 . isUnderlineColorDefault ( ) ;
96+ const cell2Default = cell2 . isUnderlineColorDefault ( ) ;
97+ if ( cell1Default && cell2Default ) {
98+ return true ;
99+ }
100+ if ( cell1Default !== cell2Default ) {
101+ return false ;
102+ }
103+ return cell1 . getUnderlineColor ( ) === cell2 . getUnderlineColor ( )
104+ && cell1 . getUnderlineColorMode ( ) === cell2 . getUnderlineColorMode ( ) ;
97105}
98106
99107function equalFlags ( cell1 : IBufferCell | IAttributeData , cell2 : IBufferCell ) : boolean {
@@ -109,6 +117,16 @@ function equalFlags(cell1: IBufferCell | IAttributeData, cell2: IBufferCell): bo
109117 && cell1 . isStrikethrough ( ) === cell2 . isStrikethrough ( ) ;
110118}
111119
120+ function attributesEquals ( cell1 : IBufferCell | IAttributeData , cell2 : IBufferCell ) : boolean {
121+ const cell1AsBufferCell = cell1 as IBufferCell ;
122+ if ( typeof cell1AsBufferCell . attributesEquals === 'function' ) {
123+ return cell1AsBufferCell . attributesEquals ( cell2 ) ;
124+ }
125+ return equalFg ( cell1 , cell2 )
126+ && equalBg ( cell1 , cell2 )
127+ && equalFlags ( cell1 , cell2 ) ;
128+ }
129+
112130class StringSerializeHandler extends BaseSerializeHandler {
113131 private _rowIndex : number = 0 ;
114132 private _allRows : string [ ] = new Array < string > ( ) ;
@@ -258,6 +276,9 @@ class StringSerializeHandler extends BaseSerializeHandler {
258276
259277 private _diffStyle ( cell : IBufferCell | IAttributeData , oldCell : IBufferCell ) : number [ ] {
260278 const sgrSeq : number [ ] = [ ] ;
279+ if ( attributesEquals ( cell , oldCell ) ) {
280+ return sgrSeq ;
281+ }
261282 const fgChanged = ! equalFg ( cell , oldCell ) ;
262283 const bgChanged = ! equalBg ( cell , oldCell ) ;
263284 const flagsChanged = ! equalFlags ( cell , oldCell ) ;
@@ -290,17 +311,18 @@ class StringSerializeHandler extends BaseSerializeHandler {
290311 if ( cell . isInverse ( ) !== oldCell . isInverse ( ) ) { sgrSeq . push ( cell . isInverse ( ) ? 7 : 27 ) ; }
291312 if ( cell . isBold ( ) !== oldCell . isBold ( ) ) { sgrSeq . push ( cell . isBold ( ) ? 1 : 22 ) ; }
292313 if ( ! equalUnderline ( cell , oldCell ) ) {
293- const cellData = cell as unknown as IAttributeData ;
294- const style = cellData . getUnderlineStyle ( ) ;
314+ const style = cell . getUnderlineStyle ( ) ;
295315 if ( style === UnderlineStyle . NONE ) {
296316 sgrSeq . push ( 24 ) ;
317+ } else if ( style === UnderlineStyle . SINGLE && cell . isUnderlineColorDefault ( ) ) {
318+ sgrSeq . push ( 4 ) ;
297319 } else {
298320 // Use SGR 4:X format for underline styles
299321 sgrSeq . push ( '4:' + style as unknown as number ) ;
300322 // Handle underline color
301- if ( ! cellData . isUnderlineColorDefault ( ) ) {
302- const color = cellData . getUnderlineColor ( ) ;
303- if ( cellData . isUnderlineColorRGB ( ) ) {
323+ if ( ! cell . isUnderlineColorDefault ( ) ) {
324+ const color = cell . getUnderlineColor ( ) ;
325+ if ( cell . isUnderlineColorRGB ( ) ) {
304326 sgrSeq . push ( '58:2::' + ( ( color >>> 16 ) & 0xFF ) + ':' + ( ( color >>> 8 ) & 0xFF ) + ':' + ( color & 0xFF ) as unknown as number ) ;
305327 } else {
306328 sgrSeq . push ( '58:5:' + color as unknown as number ) ;
@@ -675,12 +697,11 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
675697 }
676698
677699 private _getUnderlineColor ( cell : IBufferCell ) : string | undefined {
678- const cellData = cell as unknown as IAttributeData ;
679- if ( cellData . isUnderlineColorDefault ( ) ) {
700+ if ( cell . isUnderlineColorDefault ( ) ) {
680701 return undefined ;
681702 }
682- const color = cellData . getUnderlineColor ( ) ;
683- if ( cellData . isUnderlineColorRGB ( ) ) {
703+ const color = cell . getUnderlineColor ( ) ;
704+ if ( cell . isUnderlineColorRGB ( ) ) {
684705 const rgb = [
685706 ( color >> 16 ) & 255 ,
686707 ( color >> 8 ) & 255 ,
@@ -693,8 +714,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
693714 }
694715
695716 private _getUnderlineStyle ( cell : IBufferCell ) : string {
696- const cellData = cell as unknown as IAttributeData ;
697- switch ( cellData . getUnderlineStyle ( ) ) {
717+ switch ( cell . getUnderlineStyle ( ) ) {
698718 case UnderlineStyle . SINGLE :
699719 return 'underline' ;
700720 case UnderlineStyle . DOUBLE :
@@ -713,6 +733,10 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
713733 private _diffStyle ( cell : IBufferCell , oldCell : IBufferCell ) : string [ ] | undefined {
714734 const content : string [ ] = [ ] ;
715735
736+ if ( attributesEquals ( cell , oldCell ) ) {
737+ return undefined ;
738+ }
739+
716740 const fgChanged = ! equalFg ( cell , oldCell ) ;
717741 const bgChanged = ! equalBg ( cell , oldCell ) ;
718742 const flagsChanged = ! equalFlags ( cell , oldCell ) ;
0 commit comments