1
1
import { Injectable , Optional } from '@opensumi/di' ;
2
2
import { Disposable , Emitter , Event } from '@opensumi/ide-core-common' ;
3
- import { IRange , Range } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/range' ;
4
3
import { ModelDecorationOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/common/model/textModel' ;
5
4
import { IModelDecorationsChangedEvent } from '@opensumi/monaco-editor-core/esm/vs/editor/common/textModelEvents' ;
6
5
7
6
import { ICodeEditor , IModelDeltaDecoration } from '../../../monaco-api/editor' ;
8
- import { EditorViewType , LineRangeType } from '../types' ;
7
+ import { EditorViewType } from '../types' ;
9
8
import { BaseCodeEditor } from '../view/editors/baseCodeEditor' ;
10
9
import { GuidelineWidget } from '../view/guideline-widget' ;
11
10
11
+ import { InnerRange } from './inner-range' ;
12
12
import { LineRange } from './line-range' ;
13
13
14
- export interface IRenderChangesInput {
15
- ranges : LineRange ;
16
- type : LineRangeType ;
17
- }
18
-
19
- export interface IRenderInnerChangesInput {
20
- ranges : Range [ ] ;
21
- type : LineRangeType ;
22
- }
23
-
24
14
export interface IDiffDecoration {
25
15
id : string ;
26
16
readonly editorDecoration : IModelDeltaDecoration ;
@@ -58,15 +48,19 @@ export class MergeEditorDecorations extends Disposable {
58
48
this . editor . onDidChangeModelDecorations ,
59
49
this . onDidChangeLineWidget ,
60
50
) ( ( ) => {
61
- this . _onDidChangeDecorations . fire ( this ) ;
51
+ this . launchChange ( ) ;
62
52
} ) ,
63
53
) ;
64
54
}
65
55
66
- private createLineDecoration ( range : LineRange , type : LineRangeType ) : IDiffDecoration {
56
+ public launchChange ( ) : void {
57
+ this . _onDidChangeDecorations . fire ( this ) ;
58
+ }
59
+
60
+ public createLineDecoration ( range : LineRange ) : IDiffDecoration {
67
61
const options = ModelDecorationOptions . register ( {
68
- description : 'merge-editor-diff-line' ,
69
- className : `merge-editor-diff-line-background ${ type } ` ,
62
+ description : range . id ,
63
+ className : `merge-editor-diff-line-background ${ range . type } ` ,
70
64
isWholeLine : true ,
71
65
} ) ;
72
66
@@ -76,7 +70,7 @@ export class MergeEditorDecorations extends Disposable {
76
70
range : {
77
71
startLineNumber : range . startLineNumber ,
78
72
startColumn : 0 ,
79
- endLineNumber : range . endLineNumberExclusive - 1 ,
73
+ endLineNumber : Math . max ( range . startLineNumber , range . endLineNumberExclusive - 1 ) ,
80
74
endColumn : Number . MAX_SAFE_INTEGER ,
81
75
} ,
82
76
options : {
@@ -87,21 +81,28 @@ export class MergeEditorDecorations extends Disposable {
87
81
} ;
88
82
}
89
83
90
- private createInnerCharDecoration ( range : IRange , type : LineRangeType ) : IDiffDecoration {
84
+ public createInnerCharDecoration ( range : InnerRange ) : IDiffDecoration {
91
85
return {
92
86
id : '' ,
93
87
editorDecoration : {
94
88
range,
95
89
options : ModelDecorationOptions . register ( {
96
- description : 'merge-editor-diff-inner-char' ,
97
- className : `merge-editor-diff-inner-char-background ${ type } ` ,
90
+ description : range . toString ( ) ,
91
+ className : `merge-editor-diff-inner-char-background ${ range . type } ` ,
98
92
isWholeLine : false ,
99
93
} ) ,
100
94
} ,
101
95
} ;
102
96
}
103
97
104
- private setDecorations ( ranges : IRenderChangesInput [ ] , innerChanges : IRenderInnerChangesInput [ ] ) : void {
98
+ public createGuideLineWidget ( range : LineRange ) : GuidelineWidget {
99
+ const guidelineWidget = new GuidelineWidget ( this . editor ) ;
100
+ guidelineWidget . create ( ) ;
101
+ guidelineWidget . setLineRangeType ( range . type ) . showByLine ( Math . max ( 0 , Math . max ( 0 , range . startLineNumber - 1 ) ) ) ;
102
+ return guidelineWidget ;
103
+ }
104
+
105
+ private setDecorations ( ranges : LineRange [ ] , innerChanges : InnerRange [ ] [ ] ) : void {
105
106
this . editor . changeDecorations ( ( accessor ) => {
106
107
const newDecorations : IDiffDecoration [ ] = this . retainDecoration ;
107
108
this . retainLineWidgetSet . forEach ( ( widget ) => {
@@ -110,23 +111,19 @@ export class MergeEditorDecorations extends Disposable {
110
111
} ) ;
111
112
112
113
for ( const range of ranges ) {
113
- if ( range . ranges . isEmpty ) {
114
- const guidelineWidget = new GuidelineWidget ( this . editor ) ;
115
- guidelineWidget . create ( ) ;
116
- guidelineWidget . setLineRangeType ( range . type ) . showByLine ( Math . max ( 0 , range . ranges . startLineNumber - 1 ) ) ;
117
-
114
+ if ( range . isEmpty ) {
115
+ const guidelineWidget = this . createGuideLineWidget ( range ) ;
118
116
this . lineWidgetSet . add ( guidelineWidget ) ;
119
117
this . _onDidChangeLineWidget . fire ( ) ;
120
118
} else {
121
- newDecorations . push ( this . createLineDecoration ( range . ranges , range . type ) ) ;
119
+ newDecorations . push ( this . createLineDecoration ( range ) ) ;
122
120
}
123
121
}
124
122
125
123
for ( const innerRange of innerChanges ) {
126
- const { ranges, type } = innerRange ;
127
- for ( const range of ranges ) {
124
+ for ( const range of innerRange ) {
128
125
if ( ! range . isEmpty ( ) ) {
129
- newDecorations . push ( this . createInnerCharDecoration ( range , type ) ) ;
126
+ newDecorations . push ( this . createInnerCharDecoration ( range ) ) ;
130
127
}
131
128
}
132
129
}
@@ -160,7 +157,7 @@ export class MergeEditorDecorations extends Disposable {
160
157
this . cleanUpLineWidget ( this . lineWidgetSet ) ;
161
158
}
162
159
163
- public updateDecorations ( ranges : IRenderChangesInput [ ] , innerChanges : IRenderInnerChangesInput [ ] ) : void {
160
+ public updateDecorations ( ranges : LineRange [ ] , innerChanges : InnerRange [ ] [ ] ) : void {
164
161
this . clearDecorations ( ) ;
165
162
this . render ( ranges , innerChanges ) ;
166
163
}
@@ -187,7 +184,7 @@ export class MergeEditorDecorations extends Disposable {
187
184
return this ;
188
185
}
189
186
190
- public render ( ranges : IRenderChangesInput [ ] , innerChanges : IRenderInnerChangesInput [ ] ) : void {
187
+ public render ( ranges : LineRange [ ] , innerChanges : InnerRange [ ] [ ] ) : void {
191
188
this . setDecorations ( ranges , innerChanges ) ;
192
189
}
193
190
0 commit comments