@@ -896,46 +896,70 @@ export class CommentController implements IEditorContribution {
896
896
return ;
897
897
}
898
898
899
+ private getExistingCommentEditorOptions ( editor : ICodeEditor ) {
900
+ const lineDecorationsWidth : number = editor . getOption ( EditorOption . lineDecorationsWidth ) ;
901
+ let extraEditorClassName : string [ ] = [ ] ;
902
+ const configuredExtraClassName = editor . getRawOptions ( ) . extraEditorClassName ;
903
+ if ( configuredExtraClassName ) {
904
+ extraEditorClassName = configuredExtraClassName . split ( ' ' ) ;
905
+ }
906
+ return { lineDecorationsWidth, extraEditorClassName } ;
907
+ }
908
+
909
+ private getWithoutCommentsEditorOptions ( editor : ICodeEditor , extraEditorClassName : string [ ] , startingLineDecorationsWidth : number ) {
910
+ let lineDecorationsWidth = startingLineDecorationsWidth ;
911
+ const inlineCommentPos = extraEditorClassName . findIndex ( name => name === 'inline-comment' ) ;
912
+ if ( inlineCommentPos >= 0 ) {
913
+ extraEditorClassName . splice ( inlineCommentPos , 1 ) ;
914
+ }
915
+
916
+ const options = editor . getOptions ( ) ;
917
+ if ( options . get ( EditorOption . folding ) && options . get ( EditorOption . showFoldingControls ) !== 'never' ) {
918
+ lineDecorationsWidth += 11 ; // 11 comes from https://github.com/microsoft/vscode/blob/94ee5f58619d59170983f453fe78f156c0cc73a3/src/vs/workbench/contrib/comments/browser/media/review.css#L485
919
+ }
920
+ lineDecorationsWidth -= 24 ;
921
+ return { extraEditorClassName, lineDecorationsWidth } ;
922
+ }
923
+
924
+ private getWithCommentsEditorOptions ( editor : ICodeEditor , extraEditorClassName : string [ ] , startingLineDecorationsWidth : number ) {
925
+ let lineDecorationsWidth = startingLineDecorationsWidth ;
926
+ const options = editor . getOptions ( ) ;
927
+ if ( options . get ( EditorOption . folding ) && options . get ( EditorOption . showFoldingControls ) !== 'never' ) {
928
+ lineDecorationsWidth -= 11 ;
929
+ }
930
+ lineDecorationsWidth += 24 ;
931
+ extraEditorClassName . push ( 'inline-comment' ) ;
932
+ return { lineDecorationsWidth, extraEditorClassName } ;
933
+ }
934
+
935
+ private updateEditorLayoutOptions ( editor : ICodeEditor , extraEditorClassName : string [ ] , lineDecorationsWidth : number ) {
936
+ editor . updateOptions ( {
937
+ extraEditorClassName : extraEditorClassName . join ( ' ' ) ,
938
+ lineDecorationsWidth : lineDecorationsWidth
939
+ } ) ;
940
+ }
941
+
899
942
private tryUpdateReservedSpace ( ) {
900
943
if ( ! this . editor ) {
901
944
return ;
902
945
}
903
946
904
- let lineDecorationsWidth : number = this . editor . getLayoutInfo ( ) . decorationsWidth ;
905
947
const hasCommentsOrRanges = this . _commentInfos . some ( info => {
906
948
const hasRanges = Boolean ( info . commentingRanges && ( Array . isArray ( info . commentingRanges ) ? info . commentingRanges : info . commentingRanges . ranges ) . length ) ;
907
949
return hasRanges || ( info . threads . length > 0 ) ;
908
950
} ) ;
909
951
910
- if ( hasCommentsOrRanges ) {
952
+ if ( hasCommentsOrRanges && ! this . _commentingRangeSpaceReserved ) {
911
953
this . _workspaceHasCommenting . set ( true ) ;
912
- if ( ! this . _commentingRangeSpaceReserved ) {
913
- this . _commentingRangeSpaceReserved = true ;
914
- let extraEditorClassName : string [ ] = [ ] ;
915
- const configuredExtraClassName = this . editor . getRawOptions ( ) . extraEditorClassName ;
916
- if ( configuredExtraClassName ) {
917
- extraEditorClassName = configuredExtraClassName . split ( ' ' ) ;
918
- }
919
-
920
- const options = this . editor . getOptions ( ) ;
921
- if ( options . get ( EditorOption . folding ) && options . get ( EditorOption . showFoldingControls ) !== 'never' ) {
922
- lineDecorationsWidth -= 27 ;
923
- }
924
- lineDecorationsWidth += 24 ;
925
- extraEditorClassName . push ( 'inline-comment' ) ;
926
- this . editor . updateOptions ( {
927
- extraEditorClassName : extraEditorClassName . join ( ' ' ) ,
928
- lineDecorationsWidth : lineDecorationsWidth
929
- } ) ;
930
-
931
- // we only update the lineDecorationsWidth property but keep the width of the whole editor.
932
- const originalLayoutInfo = this . editor . getLayoutInfo ( ) ;
933
-
934
- this . editor . layout ( {
935
- width : originalLayoutInfo . width ,
936
- height : originalLayoutInfo . height
937
- } ) ;
938
- }
954
+ this . _commentingRangeSpaceReserved = true ;
955
+ const { lineDecorationsWidth, extraEditorClassName } = this . getExistingCommentEditorOptions ( this . editor ) ;
956
+ const newOptions = this . getWithCommentsEditorOptions ( this . editor , extraEditorClassName , lineDecorationsWidth ) ;
957
+ this . updateEditorLayoutOptions ( this . editor , newOptions . extraEditorClassName , newOptions . lineDecorationsWidth ) ;
958
+ } else if ( ! hasCommentsOrRanges && this . _commentingRangeSpaceReserved ) {
959
+ this . _commentingRangeSpaceReserved = false ;
960
+ const { lineDecorationsWidth, extraEditorClassName } = this . getExistingCommentEditorOptions ( this . editor ) ;
961
+ const newOptions = this . getWithoutCommentsEditorOptions ( this . editor , extraEditorClassName , lineDecorationsWidth ) ;
962
+ this . updateEditorLayoutOptions ( this . editor , newOptions . extraEditorClassName , newOptions . lineDecorationsWidth ) ;
939
963
}
940
964
}
941
965
0 commit comments