@@ -21,21 +21,23 @@ import { Emitter, Event } from '@theia/core/lib/common/event';
21
21
import { EditorsAndDocumentsExtImpl } from './editors-and-documents' ;
22
22
import { TextEditorExt } from './text-editor' ;
23
23
import * as Converters from './type-converters' ;
24
- import { TextEditorSelectionChangeKind , URI } from './types-impl' ;
24
+ import { TextEditorChangeKind , TextEditorSelectionChangeKind , URI } from './types-impl' ;
25
25
import { IdGenerator } from '../common/id-generator' ;
26
26
27
27
export class TextEditorsExtImpl implements TextEditorsExt {
28
28
private readonly _onDidChangeTextEditorSelection = new Emitter < theia . TextEditorSelectionChangeEvent > ( ) ;
29
29
private readonly _onDidChangeTextEditorOptions = new Emitter < theia . TextEditorOptionsChangeEvent > ( ) ;
30
30
private readonly _onDidChangeTextEditorVisibleRanges = new Emitter < theia . TextEditorVisibleRangesChangeEvent > ( ) ;
31
31
private readonly _onDidChangeTextEditorViewColumn = new Emitter < theia . TextEditorViewColumnChangeEvent > ( ) ;
32
+ private readonly _onDidChangeTextEditorDiffInformation = new Emitter < theia . TextEditorDiffInformationChangeEvent > ( ) ;
32
33
private readonly _onDidChangeActiveTextEditor = new Emitter < theia . TextEditor | undefined > ( ) ;
33
34
private readonly _onDidChangeVisibleTextEditors = new Emitter < theia . TextEditor [ ] > ( ) ;
34
35
35
36
readonly onDidChangeTextEditorSelection : Event < theia . TextEditorSelectionChangeEvent > = this . _onDidChangeTextEditorSelection . event ;
36
37
readonly onDidChangeTextEditorOptions = this . _onDidChangeTextEditorOptions . event ;
37
38
readonly onDidChangeTextEditorVisibleRanges = this . _onDidChangeTextEditorVisibleRanges . event ;
38
39
readonly onDidChangeTextEditorViewColumn = this . _onDidChangeTextEditorViewColumn . event ;
40
+ readonly onDidChangeTextEditorDiffInformation = this . _onDidChangeTextEditorDiffInformation . event ;
39
41
readonly onDidChangeActiveTextEditor = this . _onDidChangeActiveTextEditor . event ;
40
42
readonly onDidChangeVisibleTextEditors = this . _onDidChangeVisibleTextEditors . event ;
41
43
@@ -118,6 +120,73 @@ export class TextEditorsExtImpl implements TextEditorsExt {
118
120
return activeEditor . getDiffInformation ( ) ;
119
121
}
120
122
123
+ $acceptEditorDiffInformation ( id : string , diffInformation : theia . TextEditorDiffInformation [ ] | undefined ) : void {
124
+ const textEditor = this . editorsAndDocuments . getEditor ( id ) ;
125
+ if ( ! textEditor ) {
126
+ throw new Error ( 'unknown text editor' ) ;
127
+ }
128
+
129
+ if ( ! diffInformation ) {
130
+ textEditor . _acceptDiffInformation ( undefined ) ;
131
+ this . _onDidChangeTextEditorDiffInformation . fire ( {
132
+ textEditor : textEditor ,
133
+ diffInformation : undefined
134
+ } ) ;
135
+ return ;
136
+ }
137
+
138
+ const that = this ;
139
+ const result = diffInformation . map ( diff => {
140
+ const original = URI . revive ( diff . original ) ;
141
+ const modified = URI . revive ( diff . modified ) ;
142
+
143
+ const changes = diff . changes . map ( change => {
144
+ const originalStartLineNumber = change . original . startLineNumber ;
145
+ const originalEndLineNumberExclusive = change . original . endLineNumberExclusive ;
146
+ const modifiedStartLineNumber = change . modified . startLineNumber ;
147
+ const modifiedEndLineNumberExclusive = change . modified . endLineNumberExclusive ;
148
+
149
+ let kind : TextEditorChangeKind ;
150
+ if ( change . original . startLineNumber === originalEndLineNumberExclusive ) {
151
+ kind = TextEditorChangeKind . Addition ;
152
+ } else if ( modifiedStartLineNumber === modifiedEndLineNumberExclusive ) {
153
+ kind = TextEditorChangeKind . Deletion ;
154
+ } else {
155
+ kind = TextEditorChangeKind . Modification ;
156
+ }
157
+
158
+ return {
159
+ original : {
160
+ startLineNumber : originalStartLineNumber ,
161
+ endLineNumberExclusive : originalEndLineNumberExclusive
162
+ } ,
163
+ modified : {
164
+ startLineNumber : modifiedStartLineNumber ,
165
+ endLineNumberExclusive : modifiedEndLineNumberExclusive
166
+ } ,
167
+ kind
168
+ } satisfies theia . TextEditorChange ;
169
+ } ) ;
170
+
171
+ return Object . freeze ( {
172
+ documentVersion : diff . documentVersion ,
173
+ original,
174
+ modified,
175
+ changes,
176
+ get isStale ( ) : boolean {
177
+ const document = that . editorsAndDocuments . getDocument ( modified . toString ( ) ) ;
178
+ return document ?. document . version !== diff . documentVersion ;
179
+ }
180
+ } ) ;
181
+ } ) ;
182
+
183
+ textEditor . _acceptDiffInformation ( result ) ;
184
+ this . _onDidChangeTextEditorDiffInformation . fire ( {
185
+ textEditor : textEditor ,
186
+ diffInformation : result
187
+ } ) ;
188
+ }
189
+
121
190
getVisibleTextEditors ( ) : theia . TextEditor [ ] {
122
191
return this . editorsAndDocuments . allEditors ( ) ;
123
192
}
0 commit comments