@@ -8,11 +8,8 @@ import * as dom from 'vs/base/browser/dom';
8
8
import * as languages from 'vs/editor/common/languages' ;
9
9
import { ActionsOrientation , ActionBar } from 'vs/base/browser/ui/actionbar/actionbar' ;
10
10
import { Action , IActionRunner , IAction , Separator , ActionRunner } from 'vs/base/common/actions' ;
11
- import { Disposable , IDisposable , dispose } from 'vs/base/common/lifecycle' ;
11
+ import { Disposable , IDisposable , IReference , dispose } from 'vs/base/common/lifecycle' ;
12
12
import { URI , UriComponents } from 'vs/base/common/uri' ;
13
- import { ITextModel } from 'vs/editor/common/model' ;
14
- import { IModelService } from 'vs/editor/common/services/model' ;
15
- import { ILanguageService } from 'vs/editor/common/languages/language' ;
16
13
import { MarkdownRenderer } from 'vs/editor/browser/widget/markdownRenderer/browser/markdownRenderer' ;
17
14
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
18
15
import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentService' ;
@@ -45,13 +42,14 @@ import { Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable';
45
42
import { SmoothScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement' ;
46
43
import { DomEmitter } from 'vs/base/browser/event' ;
47
44
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys' ;
48
- import { FileAccess } from 'vs/base/common/network' ;
45
+ import { FileAccess , Schemas } from 'vs/base/common/network' ;
49
46
import { COMMENTS_SECTION , ICommentsConfiguration } from 'vs/workbench/contrib/comments/common/commentsConfiguration' ;
50
47
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
51
48
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
52
49
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
53
50
import { MarshalledCommentThread } from 'vs/workbench/common/comments' ;
54
51
import { IHoverService } from 'vs/platform/hover/browser/hover' ;
52
+ import { IResolvedTextEditorModel , ITextModelService } from 'vs/editor/common/services/resolverService' ;
55
53
56
54
class CommentsActionRunner extends ActionRunner {
57
55
protected override async runAction ( action : IAction , context : any [ ] ) : Promise < void > {
@@ -75,7 +73,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
75
73
private _reactionActionsContainer ?: HTMLElement ;
76
74
private _commentEditor : SimpleCommentEditor | null = null ;
77
75
private _commentEditorDisposables : IDisposable [ ] = [ ] ;
78
- private _commentEditorModel : ITextModel | null = null ;
76
+ private _commentEditorModel : IReference < IResolvedTextEditorModel > | null = null ;
79
77
private _editorHeight = MIN_EDITOR_HEIGHT ;
80
78
81
79
private _isPendingLabel ! : HTMLElement ;
@@ -112,15 +110,14 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
112
110
private markdownRenderer : MarkdownRenderer ,
113
111
@IInstantiationService private instantiationService : IInstantiationService ,
114
112
@ICommentService private commentService : ICommentService ,
115
- @IModelService private modelService : IModelService ,
116
- @ILanguageService private languageService : ILanguageService ,
117
113
@INotificationService private notificationService : INotificationService ,
118
114
@IContextMenuService private contextMenuService : IContextMenuService ,
119
115
@IContextKeyService contextKeyService : IContextKeyService ,
120
116
@IConfigurationService private configurationService : IConfigurationService ,
121
117
@IHoverService private hoverService : IHoverService ,
122
118
@IAccessibilityService private accessibilityService : IAccessibilityService ,
123
- @IKeybindingService private keybindingService : IKeybindingService
119
+ @IKeybindingService private keybindingService : IKeybindingService ,
120
+ @ITextModelService private readonly textModelService : ITextModelService ,
124
121
) {
125
122
super ( ) ;
126
123
@@ -494,13 +491,18 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
494
491
return ( typeof this . comment . body === 'string' ) ? this . comment . body : this . comment . body . value ;
495
492
}
496
493
497
- private createCommentEditor ( editContainer : HTMLElement ) : void {
494
+ private async createCommentEditor ( editContainer : HTMLElement ) : Promise < void > {
498
495
const container = dom . append ( editContainer , dom . $ ( '.edit-textarea' ) ) ;
499
496
this . _commentEditor = this . instantiationService . createInstance ( SimpleCommentEditor , container , SimpleCommentEditor . getEditorOptions ( this . configurationService ) , this . _contextKeyService , this . parentThread ) ;
500
- const resource = URI . parse ( `comment:commentinput-${ this . comment . uniqueIdInThread } -${ Date . now ( ) } .md` ) ;
501
- this . _commentEditorModel = this . modelService . createModel ( '' , this . languageService . createByFilepathOrFirstLine ( resource ) , resource , false ) ;
502
497
503
- this . _commentEditor . setModel ( this . _commentEditorModel ) ;
498
+ const resource = URI . from ( {
499
+ scheme : Schemas . commentsInput ,
500
+ path : `/commentinput-${ this . comment . uniqueIdInThread } -${ Date . now ( ) } .md`
501
+ } ) ;
502
+ const modelRef = await this . textModelService . createModelReference ( resource ) ;
503
+ this . _commentEditorModel = modelRef ;
504
+
505
+ this . _commentEditor . setModel ( this . _commentEditorModel . object . textEditorModel ) ;
504
506
this . _commentEditor . setValue ( this . pendingEdit ?? this . commentBodyValue ) ;
505
507
this . pendingEdit = undefined ;
506
508
this . _commentEditor . layout ( { width : container . clientWidth - 14 , height : this . _editorHeight } ) ;
@@ -511,8 +513,8 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
511
513
this . _commentEditor ! . focus ( ) ;
512
514
} ) ;
513
515
514
- const lastLine = this . _commentEditorModel . getLineCount ( ) ;
515
- const lastColumn = this . _commentEditorModel . getLineLength ( lastLine ) + 1 ;
516
+ const lastLine = this . _commentEditorModel . object . textEditorModel . getLineCount ( ) ;
517
+ const lastColumn = this . _commentEditorModel . object . textEditorModel . getLineLength ( lastLine ) + 1 ;
516
518
this . _commentEditor . setSelection ( new Selection ( lastLine , lastColumn , lastLine , lastColumn ) ) ;
517
519
518
520
const commentThread = this . commentThread ;
@@ -547,7 +549,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
547
549
548
550
this . calculateEditorHeight ( ) ;
549
551
550
- this . _register ( ( this . _commentEditorModel . onDidChangeContent ( ( ) => {
552
+ this . _register ( ( this . _commentEditorModel . object . textEditorModel . onDidChangeContent ( ( ) => {
551
553
if ( this . _commentEditor && this . calculateEditorHeight ( ) ) {
552
554
this . _commentEditor . layout ( { height : this . _editorHeight , width : this . _commentEditor . getLayoutInfo ( ) . width } ) ;
553
555
this . _commentEditor . render ( true ) ;
@@ -604,15 +606,15 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
604
606
this . _scrollableElement . setScrollDimensions ( { width, scrollWidth, height, scrollHeight } ) ;
605
607
}
606
608
607
- public switchToEditMode ( ) {
609
+ public async switchToEditMode ( ) {
608
610
if ( this . isEditing ) {
609
611
return ;
610
612
}
611
613
612
614
this . isEditing = true ;
613
615
this . _body . classList . add ( 'hidden' ) ;
614
616
this . _commentEditContainer = dom . append ( this . _commentDetailsContainer , dom . $ ( '.edit-container' ) ) ;
615
- this . createCommentEditor ( this . _commentEditContainer ) ;
617
+ await this . createCommentEditor ( this . _commentEditContainer ) ;
616
618
617
619
const formActions = dom . append ( this . _commentEditContainer , dom . $ ( '.form-actions' ) ) ;
618
620
const otherActions = dom . append ( formActions , dom . $ ( '.other-actions' ) ) ;
@@ -705,7 +707,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
705
707
} ) ) ;
706
708
}
707
709
708
- update ( newComment : languages . Comment ) {
710
+ async update ( newComment : languages . Comment ) {
709
711
710
712
if ( newComment . body !== this . comment . body ) {
711
713
this . updateCommentBody ( newComment . body ) ;
@@ -721,7 +723,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
721
723
722
724
if ( isChangingMode ) {
723
725
if ( newComment . mode === languages . CommentMode . Editing ) {
724
- this . switchToEditMode ( ) ;
726
+ await this . switchToEditMode ( ) ;
725
727
} else {
726
728
this . removeCommentEditor ( ) ;
727
729
}
0 commit comments