3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import * as dom from 'vs/base/browser/dom' ;
7
6
import * as languages from 'vs/editor/common/languages' ;
8
7
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
9
8
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
@@ -89,7 +88,7 @@ export class CellComments extends CellPart {
89
88
90
89
this . commentTheadDisposables . add ( this . _commentThreadWidget . onDidResize ( ( ) => {
91
90
if ( this . currentElement ?. cellKind === CellKind . Code && this . _commentThreadWidget ) {
92
- this . currentElement . commentHeight = dom . getClientArea ( this . _commentThreadWidget . container ) . height ;
91
+ this . currentElement . commentHeight = this . _calculateCommentThreadHeight ( this . _commentThreadWidget . getDimensions ( ) . height ) ;
93
92
}
94
93
} ) ) ;
95
94
}
@@ -102,25 +101,41 @@ export class CellComments extends CellPart {
102
101
this . _createCommentTheadWidget ( info . owner , info . thread ) ;
103
102
const layoutInfo = ( this . currentElement as CodeCellViewModel ) . layoutInfo ;
104
103
this . container . style . top = `${ layoutInfo . outputContainerOffset + layoutInfo . outputTotalHeight } px` ;
105
-
106
- this . currentElement . commentHeight = dom . getClientArea ( this . _commentThreadWidget ! . container ) . height ;
107
-
104
+ this . currentElement . commentHeight = this . _calculateCommentThreadHeight ( this . _commentThreadWidget ! . getDimensions ( ) . height ) ;
108
105
return ;
109
106
}
110
107
111
108
if ( this . _commentThreadWidget ) {
112
- if ( info ) {
113
- this . _commentThreadWidget . updateCommentThread ( info . thread ) ;
114
- this . currentElement . commentHeight = dom . getClientArea ( this . _commentThreadWidget . container ) . height ;
115
- } else {
109
+ if ( ! info ) {
116
110
this . _commentThreadWidget . dispose ( ) ;
117
111
this . currentElement . commentHeight = 0 ;
112
+ return ;
113
+ }
114
+ if ( this . _commentThreadWidget . commentThread === info . thread ) {
115
+ this . currentElement . commentHeight = this . _calculateCommentThreadHeight ( this . _commentThreadWidget . getDimensions ( ) . height ) ;
116
+ return ;
118
117
}
118
+
119
+ this . _commentThreadWidget . updateCommentThread ( info . thread ) ;
120
+ this . currentElement . commentHeight = this . _calculateCommentThreadHeight ( this . _commentThreadWidget . getDimensions ( ) . height ) ;
119
121
}
120
122
}
121
123
} ) ) ;
122
124
}
123
125
126
+ private _calculateCommentThreadHeight ( bodyHeight : number ) {
127
+ const layoutInfo = this . notebookEditor . getLayoutInfo ( ) ;
128
+
129
+ const headHeight = Math . ceil ( layoutInfo . fontInfo . lineHeight * 1.2 ) ;
130
+ const lineHeight = layoutInfo . fontInfo . lineHeight ;
131
+ const arrowHeight = Math . round ( lineHeight / 3 ) ;
132
+ const frameThickness = Math . round ( lineHeight / 9 ) * 2 ;
133
+
134
+ const computedHeight = headHeight + bodyHeight + arrowHeight + frameThickness + 8 /** margin bottom to avoid margin collapse */ ;
135
+ return computedHeight ;
136
+
137
+ }
138
+
124
139
private async _getCommentThreadForCell ( element : ICellViewModel ) : Promise < { thread : languages . CommentThread < ICellRange > ; owner : string } | null > {
125
140
if ( this . notebookEditor . hasModel ( ) ) {
126
141
const commentInfos = coalesce ( await this . commentService . getNotebookComments ( element . uri ) ) ;
@@ -149,7 +164,7 @@ export class CellComments extends CellPart {
149
164
150
165
override prepareLayout ( ) : void {
151
166
if ( this . currentElement ?. cellKind === CellKind . Code && this . _commentThreadWidget ) {
152
- this . currentElement . commentHeight = dom . getClientArea ( this . _commentThreadWidget . container ) . height ;
167
+ this . currentElement . commentHeight = this . _calculateCommentThreadHeight ( this . _commentThreadWidget . getDimensions ( ) . height ) ;
153
168
}
154
169
}
155
170
0 commit comments