@opensumi/ide-editor 3.9.1-next-1748403761.0 → 3.9.1-next-1748425167.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/decoration-applier.d.ts.map +1 -1
- package/lib/browser/decoration-applier.js.map +1 -1
- package/lib/browser/editor-collection.service.d.ts +57 -21
- package/lib/browser/editor-collection.service.d.ts.map +1 -1
- package/lib/browser/editor-collection.service.js +206 -42
- package/lib/browser/editor-collection.service.js.map +1 -1
- package/lib/browser/editor.contribution.d.ts.map +1 -1
- package/lib/browser/editor.contribution.js +0 -1
- package/lib/browser/editor.contribution.js.map +1 -1
- package/lib/browser/editor.less +0 -25
- package/lib/browser/multi-diff/multi-diff-editor.d.ts +7 -10
- package/lib/browser/multi-diff/multi-diff-editor.d.ts.map +1 -1
- package/lib/browser/multi-diff/multi-diff-editor.js +7 -60
- package/lib/browser/multi-diff/multi-diff-editor.js.map +1 -1
- package/lib/browser/multi-diff/multi-diff-resource.d.ts.map +1 -1
- package/lib/browser/multi-diff/multi-diff-resource.js.map +1 -1
- package/lib/browser/workbench-editor.service.js +1 -1
- package/lib/browser/workbench-editor.service.js.map +1 -1
- package/lib/common/multi-diff.d.ts +1 -6
- package/lib/common/multi-diff.d.ts.map +1 -1
- package/lib/common/multi-diff.js.map +1 -1
- package/package.json +14 -14
- package/src/browser/decoration-applier.ts +0 -1
- package/src/browser/editor-collection.service.ts +263 -48
- package/src/browser/editor.contribution.ts +0 -2
- package/src/browser/editor.less +0 -25
- package/src/browser/multi-diff/multi-diff-editor.ts +10 -91
- package/src/browser/multi-diff/multi-diff-resource.ts +1 -0
- package/src/browser/workbench-editor.service.ts +1 -1
- package/src/common/multi-diff.ts +1 -8
- package/lib/browser/base-editor-wrapper.d.ts +0 -58
- package/lib/browser/base-editor-wrapper.d.ts.map +0 -1
- package/lib/browser/base-editor-wrapper.js +0 -203
- package/lib/browser/base-editor-wrapper.js.map +0 -1
- package/src/browser/base-editor-wrapper.ts +0 -254
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
|
|
2
|
-
import { IContextKeyService, PreferenceService } from '@opensumi/ide-core-browser';
|
|
2
|
+
import { AppConfig, IContextKeyService, IRange, PreferenceService } from '@opensumi/ide-core-browser';
|
|
3
3
|
import { ResourceContextKey } from '@opensumi/ide-core-browser/lib/contextkey';
|
|
4
4
|
import { MonacoService } from '@opensumi/ide-core-browser/lib/monaco';
|
|
5
5
|
import {
|
|
6
|
+
Disposable,
|
|
6
7
|
Emitter,
|
|
7
8
|
Event,
|
|
8
9
|
Emitter as EventEmitter,
|
|
9
10
|
ILineChange,
|
|
11
|
+
ISelection,
|
|
10
12
|
OnEvent,
|
|
11
13
|
URI,
|
|
12
14
|
WithEventBus,
|
|
15
|
+
isEmptyObject,
|
|
16
|
+
objects,
|
|
13
17
|
} from '@opensumi/ide-core-common';
|
|
14
18
|
import * as monaco from '@opensumi/ide-monaco';
|
|
15
19
|
import { IConfigurationService } from '@opensumi/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
|
|
@@ -20,19 +24,21 @@ import {
|
|
|
20
24
|
EditorCollectionService,
|
|
21
25
|
EditorType,
|
|
22
26
|
ICodeEditor,
|
|
27
|
+
IDecorationApplyOptions,
|
|
23
28
|
IDiffEditor,
|
|
24
29
|
IEditor,
|
|
30
|
+
IResource,
|
|
25
31
|
IResourceOpenOptions,
|
|
32
|
+
IUndoStopOptions,
|
|
26
33
|
ResourceDecorationNeedChangeEvent,
|
|
27
34
|
} from '../common';
|
|
28
|
-
import { IEditorDocumentModelRef, isTextEditorViewState } from '../common/editor';
|
|
29
|
-
import { IMultiDiffEditor } from '../common/multi-diff';
|
|
35
|
+
import { IEditorDocumentModel, IEditorDocumentModelRef, isTextEditorViewState } from '../common/editor';
|
|
30
36
|
|
|
31
|
-
import {
|
|
37
|
+
import { MonacoEditorDecorationApplier } from './decoration-applier';
|
|
32
38
|
import { EditorDocumentModelContentChangedEvent, IEditorDocumentModelService } from './doc-model/types';
|
|
33
39
|
import { EditorFeatureRegistryImpl } from './feature';
|
|
34
40
|
import { BrowserMultiDiffEditor } from './multi-diff/multi-diff-editor';
|
|
35
|
-
import { getConvertedMonacoOptions, isDiffEditorOption } from './preference/converter';
|
|
41
|
+
import { getConvertedMonacoOptions, isDiffEditorOption, isEditorOption } from './preference/converter';
|
|
36
42
|
import { IConvertedMonacoOptions, IEditorFeatureRegistry } from './types';
|
|
37
43
|
|
|
38
44
|
import type {
|
|
@@ -41,6 +47,8 @@ import type {
|
|
|
41
47
|
} from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
|
|
42
48
|
import type { IDiffEditorConstructionOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
|
|
43
49
|
|
|
50
|
+
const { removeUndefined } = objects;
|
|
51
|
+
|
|
44
52
|
@Injectable()
|
|
45
53
|
export class EditorCollectionServiceImpl extends WithEventBus implements EditorCollectionService {
|
|
46
54
|
@Autowired()
|
|
@@ -57,23 +65,12 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
57
65
|
|
|
58
66
|
private _editors: Set<ISumiEditor> = new Set();
|
|
59
67
|
private _diffEditors: Set<IDiffEditor> = new Set();
|
|
60
|
-
private _multiDiffEditors: Set<IMultiDiffEditor> = new Set();
|
|
61
68
|
|
|
62
69
|
private _onCodeEditorCreate = new Emitter<ICodeEditor>();
|
|
63
70
|
private _onDiffEditorCreate = new Emitter<IDiffEditor>();
|
|
64
|
-
private _onMultiDiffEditorCreate = new Emitter<IMultiDiffEditor>();
|
|
65
|
-
|
|
66
|
-
private _onCodeEditorChange = new Emitter<void>();
|
|
67
|
-
private _onDiffEditorChange = new Emitter<void>();
|
|
68
|
-
private _onMultiDiffEditorChange = new Emitter<void>();
|
|
69
71
|
|
|
70
72
|
public onCodeEditorCreate = this._onCodeEditorCreate.event;
|
|
71
73
|
public onDiffEditorCreate = this._onDiffEditorCreate.event;
|
|
72
|
-
public onMultiDiffEditorCreate = this._onMultiDiffEditorCreate.event;
|
|
73
|
-
|
|
74
|
-
public onCodeEditorChange = this._onCodeEditorChange.event;
|
|
75
|
-
public onDiffEditorChange = this._onDiffEditorChange.event;
|
|
76
|
-
public onMultiDiffEditorChange = this._onMultiDiffEditorChange.event;
|
|
77
74
|
|
|
78
75
|
@Autowired(IEditorDocumentModelService)
|
|
79
76
|
documentModelService: IEditorDocumentModelService;
|
|
@@ -131,7 +128,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
131
128
|
}
|
|
132
129
|
});
|
|
133
130
|
if (this._editors.size !== beforeSize) {
|
|
134
|
-
|
|
131
|
+
// fire event;
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
|
|
@@ -144,7 +141,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
144
141
|
}
|
|
145
142
|
});
|
|
146
143
|
if (this._editors.size !== beforeSize) {
|
|
147
|
-
|
|
144
|
+
// fire event;
|
|
148
145
|
}
|
|
149
146
|
}
|
|
150
147
|
|
|
@@ -157,11 +154,11 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
157
154
|
return editor;
|
|
158
155
|
}
|
|
159
156
|
|
|
160
|
-
|
|
157
|
+
createMultiDiffEditor(dom: HTMLElement, options?: any, overrides?: { [key: string]: any }) {
|
|
161
158
|
const convertedOptions = getConvertedMonacoOptions(this.configurationService);
|
|
162
159
|
const monacoMultiDiffEditorWidget = this.monacoService.createMultiDiffEditorWidget(dom, overrides);
|
|
163
160
|
const mergedOptions: IConvertedMonacoOptions = { ...convertedOptions.diffOptions, ...options };
|
|
164
|
-
const editor = this.injector.get(BrowserMultiDiffEditor, [monacoMultiDiffEditorWidget, mergedOptions
|
|
161
|
+
const editor = this.injector.get(BrowserMultiDiffEditor, [monacoMultiDiffEditorWidget, mergedOptions]);
|
|
165
162
|
return editor;
|
|
166
163
|
}
|
|
167
164
|
|
|
@@ -190,7 +187,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
190
187
|
}
|
|
191
188
|
});
|
|
192
189
|
if (this._diffEditors.size !== beforeSize) {
|
|
193
|
-
|
|
190
|
+
// fire event _onDiffEditorAdd;
|
|
194
191
|
}
|
|
195
192
|
}
|
|
196
193
|
|
|
@@ -200,36 +197,11 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
200
197
|
this._diffEditors.delete(diffEditor);
|
|
201
198
|
});
|
|
202
199
|
if (this._diffEditors.size !== beforeSize) {
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
public listMultiDiffEditors(): IMultiDiffEditor[] {
|
|
208
|
-
return Array.from(this._multiDiffEditors.values());
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public addMultiDiffEditors(multiDiffEditors: IMultiDiffEditor[]) {
|
|
212
|
-
const beforeSize = this._multiDiffEditors.size;
|
|
213
|
-
multiDiffEditors.forEach((multiDiffEditor) => {
|
|
214
|
-
if (!this._multiDiffEditors.has(multiDiffEditor)) {
|
|
215
|
-
this._multiDiffEditors.add(multiDiffEditor);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
if (this._multiDiffEditors.size !== beforeSize) {
|
|
219
|
-
this._onMultiDiffEditorChange.fire();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
public removeMultiDiffEditors(multiDiffEditors: IMultiDiffEditor[]) {
|
|
224
|
-
const beforeSize = this._multiDiffEditors.size;
|
|
225
|
-
multiDiffEditors.forEach((multiDiffEditor) => {
|
|
226
|
-
this._multiDiffEditors.delete(multiDiffEditor);
|
|
227
|
-
});
|
|
228
|
-
if (this._multiDiffEditors.size !== beforeSize) {
|
|
229
|
-
this._onMultiDiffEditorChange.fire();
|
|
200
|
+
// fire event _onDiffEditorRemove;
|
|
230
201
|
}
|
|
231
202
|
}
|
|
232
203
|
|
|
204
|
+
// 将docModel的变更事件反映至resource的dirty装饰
|
|
233
205
|
@OnEvent(EditorDocumentModelContentChangedEvent)
|
|
234
206
|
onDocModelContentChangedEvent(e: EditorDocumentModelContentChangedEvent) {
|
|
235
207
|
this.eventBus.fire(
|
|
@@ -244,6 +216,230 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
244
216
|
}
|
|
245
217
|
}
|
|
246
218
|
|
|
219
|
+
export type ISumiEditor = IEditor;
|
|
220
|
+
|
|
221
|
+
export function insertSnippetWithMonacoEditor(
|
|
222
|
+
editor: IMonacoCodeEditor,
|
|
223
|
+
template: string,
|
|
224
|
+
ranges: IRange[],
|
|
225
|
+
opts: IUndoStopOptions,
|
|
226
|
+
) {
|
|
227
|
+
const snippetController = editor.getContribution('snippetController2') as any;
|
|
228
|
+
const selections: ISelection[] = ranges.map(
|
|
229
|
+
(r) => new monaco.Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn),
|
|
230
|
+
);
|
|
231
|
+
editor.setSelections(selections);
|
|
232
|
+
editor.focus();
|
|
233
|
+
|
|
234
|
+
snippetController.insert(template, 0, 0, opts.undoStopBefore, opts.undoStopAfter);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function updateOptionsWithMonacoEditor(
|
|
238
|
+
monacoEditor: IMonacoCodeEditor,
|
|
239
|
+
editorOptions: monaco.editor.IEditorOptions,
|
|
240
|
+
modelOptions: monaco.editor.ITextModelUpdateOptions,
|
|
241
|
+
) {
|
|
242
|
+
monacoEditor.updateOptions(editorOptions);
|
|
243
|
+
if (monacoEditor.getModel()) {
|
|
244
|
+
monacoEditor.getModel()!.updateOptions(modelOptions);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@Injectable({ multiple: true })
|
|
249
|
+
export abstract class BaseMonacoEditorWrapper extends WithEventBus implements IEditor {
|
|
250
|
+
public abstract readonly currentDocumentModel: IEditorDocumentModel | null;
|
|
251
|
+
|
|
252
|
+
public get currentUri(): URI | null {
|
|
253
|
+
return this.currentDocumentModel ? this.currentDocumentModel.uri : null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public getId() {
|
|
257
|
+
return this.monacoEditor.getId();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
getSelections() {
|
|
261
|
+
return this.monacoEditor.getSelections() || [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public onFocus = this.monacoEditor.onDidFocusEditorWidget;
|
|
265
|
+
|
|
266
|
+
public onBlur = this.monacoEditor.onDidBlurEditorWidget;
|
|
267
|
+
|
|
268
|
+
protected _specialEditorOptions: any = {};
|
|
269
|
+
|
|
270
|
+
protected _specialModelOptions: monaco.editor.ITextModelUpdateOptions = {};
|
|
271
|
+
|
|
272
|
+
protected _editorOptionsFromContribution: any = {};
|
|
273
|
+
|
|
274
|
+
@Autowired(IEditorFeatureRegistry)
|
|
275
|
+
protected readonly editorFeatureRegistry: IEditorFeatureRegistry;
|
|
276
|
+
|
|
277
|
+
@Autowired(IConfigurationService)
|
|
278
|
+
protected readonly configurationService: IConfigurationService;
|
|
279
|
+
|
|
280
|
+
protected readonly decorationApplier: MonacoEditorDecorationApplier;
|
|
281
|
+
|
|
282
|
+
private _disableSelectionEmitter = false;
|
|
283
|
+
|
|
284
|
+
protected disableSelectionEmitter() {
|
|
285
|
+
this._disableSelectionEmitter = true;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
protected enableSelectionEmitter() {
|
|
289
|
+
this._disableSelectionEmitter = false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
@Autowired(INJECTOR_TOKEN)
|
|
293
|
+
private injector: Injector;
|
|
294
|
+
|
|
295
|
+
constructor(public readonly monacoEditor: IMonacoCodeEditor, private type: EditorType) {
|
|
296
|
+
super();
|
|
297
|
+
this.decorationApplier = this.injector.get(MonacoEditorDecorationApplier, [this.monacoEditor]);
|
|
298
|
+
this.addDispose(this.monacoEditor.onDidChangeModel(this.onDidChangeModel.bind(this)));
|
|
299
|
+
this.addDispose(
|
|
300
|
+
this.monacoEditor.onDidChangeModelLanguage(() => {
|
|
301
|
+
this._doUpdateOptions();
|
|
302
|
+
}),
|
|
303
|
+
);
|
|
304
|
+
this.addDispose(
|
|
305
|
+
this.configurationService.onDidChangeConfiguration((e) => {
|
|
306
|
+
const changedEditorKeys = Array.from(e.affectedKeys.values()).filter((key) => isEditorOption(key));
|
|
307
|
+
if (changedEditorKeys.length > 0) {
|
|
308
|
+
this._doUpdateOptions();
|
|
309
|
+
}
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private async onDidChangeModel() {
|
|
315
|
+
this._editorOptionsFromContribution = {};
|
|
316
|
+
const uri = this.currentUri;
|
|
317
|
+
if (uri) {
|
|
318
|
+
Promise.resolve(this.editorFeatureRegistry.runProvideEditorOptionsForUri(uri)).then((options) => {
|
|
319
|
+
if (!this.currentUri || !uri.isEqual(this.currentUri)) {
|
|
320
|
+
return; // uri可能已经变了
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (options && Object.keys(options).length > 0) {
|
|
324
|
+
this._editorOptionsFromContribution = options;
|
|
325
|
+
if (!isEmptyObject(this._editorOptionsFromContribution)) {
|
|
326
|
+
this._doUpdateOptions();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
public getType() {
|
|
334
|
+
return this.type;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
updateOptions(
|
|
338
|
+
editorOptions: monaco.editor.IEditorOptions = {},
|
|
339
|
+
modelOptions: monaco.editor.ITextModelUpdateOptions = {},
|
|
340
|
+
) {
|
|
341
|
+
this._specialEditorOptions = removeUndefined({ ...this._specialEditorOptions, ...editorOptions });
|
|
342
|
+
this._specialModelOptions = removeUndefined({ ...this._specialModelOptions, ...modelOptions });
|
|
343
|
+
this._doUpdateOptions();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private _doUpdateOptions() {
|
|
347
|
+
const { editorOptions, modelOptions } = this._calculateFinalOptions();
|
|
348
|
+
updateOptionsWithMonacoEditor(this.monacoEditor, editorOptions, modelOptions);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 合并所有的选项
|
|
353
|
+
* 优先关系: (从高到底)
|
|
354
|
+
* 1. 当前编辑器的特殊选项(通过调用 updateOptions或者启动时传入)
|
|
355
|
+
* 2. 来自 featureRegistry 的根据 当前uri 提供的选项
|
|
356
|
+
* 3. 来自偏好设置的选项
|
|
357
|
+
*/
|
|
358
|
+
private _calculateFinalOptions() {
|
|
359
|
+
const uriStr = this.currentUri ? this.currentUri.toString() : undefined;
|
|
360
|
+
const languageId = this.currentDocumentModel ? this.currentDocumentModel.languageId : undefined;
|
|
361
|
+
const options = getConvertedMonacoOptions(this.configurationService, uriStr, languageId, undefined);
|
|
362
|
+
const basicEditorOptions: Partial<monaco.editor.IEditorOptions> = {
|
|
363
|
+
readOnly: this.currentDocumentModel?.readonly || false,
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
let editorOptions = {
|
|
367
|
+
...basicEditorOptions,
|
|
368
|
+
...options.editorOptions,
|
|
369
|
+
...this._editorOptionsFromContribution,
|
|
370
|
+
...this._specialEditorOptions,
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
if (this.type !== EditorType.CODE) {
|
|
374
|
+
editorOptions = {
|
|
375
|
+
...editorOptions,
|
|
376
|
+
...options.diffOptions,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return {
|
|
381
|
+
editorOptions,
|
|
382
|
+
modelOptions: { ...options.modelOptions, ...this._specialModelOptions },
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
insertSnippet(template: string, ranges: IRange[], opts: IUndoStopOptions) {
|
|
387
|
+
insertSnippetWithMonacoEditor(this.monacoEditor, template, ranges, opts);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
applyDecoration(key: string, options: IDecorationApplyOptions[]) {
|
|
391
|
+
this.decorationApplier.applyDecoration(key, options);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
onSelectionsChanged(listener) {
|
|
395
|
+
return this.monacoEditor.onDidChangeCursorSelection((e) => {
|
|
396
|
+
if (!this._disableSelectionEmitter) {
|
|
397
|
+
listener({
|
|
398
|
+
selections: this.getSelections(),
|
|
399
|
+
source: e.source,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
onVisibleRangesChanged(listener) {
|
|
406
|
+
const disposer = new Disposable();
|
|
407
|
+
const monacoEditor = this.monacoEditor;
|
|
408
|
+
disposer.addDispose(
|
|
409
|
+
monacoEditor.onDidScrollChange((e) => {
|
|
410
|
+
listener(this.monacoEditor.getVisibleRanges());
|
|
411
|
+
}),
|
|
412
|
+
);
|
|
413
|
+
disposer.addDispose(
|
|
414
|
+
monacoEditor.onDidLayoutChange((e) => {
|
|
415
|
+
listener(this.monacoEditor.getVisibleRanges());
|
|
416
|
+
}),
|
|
417
|
+
);
|
|
418
|
+
return disposer;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
setSelections(selections) {
|
|
422
|
+
return this.monacoEditor.setSelections(selections as any);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
setSelection(selection) {
|
|
426
|
+
return this.monacoEditor.setSelection(selection as any);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
public async save(): Promise<void> {
|
|
430
|
+
if (this.currentDocumentModel) {
|
|
431
|
+
await this.currentDocumentModel.save();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
onConfigurationChanged(listener) {
|
|
436
|
+
const monacoEditor = this.monacoEditor;
|
|
437
|
+
return monacoEditor.onDidChangeConfiguration((e) => {
|
|
438
|
+
listener();
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
247
443
|
@Injectable({ multiple: true })
|
|
248
444
|
export class BrowserCodeEditor extends BaseMonacoEditorWrapper implements ICodeEditor {
|
|
249
445
|
@Autowired(EditorCollectionService)
|
|
@@ -372,6 +568,9 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
|
|
|
372
568
|
@Autowired(EditorCollectionService)
|
|
373
569
|
private collectionService: EditorCollectionServiceImpl;
|
|
374
570
|
|
|
571
|
+
@Autowired(AppConfig)
|
|
572
|
+
private appConfig: AppConfig;
|
|
573
|
+
|
|
375
574
|
private originalDocModelRef: IEditorDocumentModelRef | null;
|
|
376
575
|
|
|
377
576
|
private modifiedDocModelRef: IEditorDocumentModelRef | null;
|
|
@@ -638,6 +837,7 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
|
|
|
638
837
|
}
|
|
639
838
|
|
|
640
839
|
// utils
|
|
840
|
+
|
|
641
841
|
function bindPreventNavigation(div: HTMLElement) {
|
|
642
842
|
div.addEventListener('mousewheel', preventNavigation as any);
|
|
643
843
|
}
|
|
@@ -653,3 +853,18 @@ function preventNavigation(this: HTMLDivElement, e: WheelEvent) {
|
|
|
653
853
|
e.stopPropagation();
|
|
654
854
|
}
|
|
655
855
|
}
|
|
856
|
+
|
|
857
|
+
@Injectable({ multiple: true })
|
|
858
|
+
export class DiffEditorPart extends BaseMonacoEditorWrapper implements IEditor {
|
|
859
|
+
get currentDocumentModel() {
|
|
860
|
+
return this.getDocumentModel();
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
constructor(
|
|
864
|
+
monacoEditor: IMonacoCodeEditor,
|
|
865
|
+
private getDocumentModel: () => IEditorDocumentModel | null,
|
|
866
|
+
type: EditorType,
|
|
867
|
+
) {
|
|
868
|
+
super(monacoEditor, type);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
@@ -1246,7 +1246,6 @@ export class EditorContribution
|
|
|
1246
1246
|
title: string;
|
|
1247
1247
|
multiDiffSourceUri: UriComponents;
|
|
1248
1248
|
resources: { originalUri?: UriComponents; modifiedUri?: UriComponents }[];
|
|
1249
|
-
editorOptions?: IResourceOpenOptions;
|
|
1250
1249
|
}) => {
|
|
1251
1250
|
const sources: MultiDiffEditorItem[] = [];
|
|
1252
1251
|
for (const { originalUri, modifiedUri } of options.resources) {
|
|
@@ -1263,7 +1262,6 @@ export class EditorContribution
|
|
|
1263
1262
|
this.multiDiffResolver.registerSources(multiDiffSourceUri, sources);
|
|
1264
1263
|
await this.workbenchEditorService.open(multiDiffSourceUri, {
|
|
1265
1264
|
label: options.title,
|
|
1266
|
-
...options.editorOptions,
|
|
1267
1265
|
});
|
|
1268
1266
|
},
|
|
1269
1267
|
},
|
package/src/browser/editor.less
CHANGED
|
@@ -20,28 +20,3 @@
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
.monaco-component.multiDiffEditor {
|
|
25
|
-
& .multiDiffEntry {
|
|
26
|
-
& .header {
|
|
27
|
-
margin-top: 8px;
|
|
28
|
-
.header-content {
|
|
29
|
-
margin-top: 0;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
.status {
|
|
33
|
-
&.added {
|
|
34
|
-
color: var(--gitDecoration-addedResourceForeground);
|
|
35
|
-
}
|
|
36
|
-
&.deleted {
|
|
37
|
-
color: var(--gitDecoration-deletedResourceForeground);
|
|
38
|
-
}
|
|
39
|
-
&.renamed {
|
|
40
|
-
color: var(--gitDecoration-renamedResourceForeground);
|
|
41
|
-
}
|
|
42
|
-
&.modified {
|
|
43
|
-
color: var(--gitDecoration-modifiedResourceForeground);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
|
|
2
2
|
import { PreferenceService } from '@opensumi/ide-core-browser';
|
|
3
|
-
import {
|
|
4
|
-
DisposableStore,
|
|
5
|
-
Emitter,
|
|
6
|
-
Event,
|
|
7
|
-
IDisposable,
|
|
8
|
-
ILogger,
|
|
9
|
-
OnEvent,
|
|
10
|
-
URI,
|
|
11
|
-
WithEventBus,
|
|
12
|
-
isString,
|
|
13
|
-
} from '@opensumi/ide-core-common';
|
|
3
|
+
import { DisposableStore, Emitter, IDisposable, ILogger, OnEvent, URI, WithEventBus } from '@opensumi/ide-core-common';
|
|
14
4
|
import {
|
|
15
5
|
ValueWithChangeEventFromObservable,
|
|
16
6
|
constObservable,
|
|
@@ -35,14 +25,11 @@ import { IMultiDiffResourceId } from '@opensumi/monaco-editor-core/esm/vs/editor
|
|
|
35
25
|
import { Range } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/range';
|
|
36
26
|
import { IDiffEditor } from '@opensumi/monaco-editor-core/esm/vs/editor/common/editorCommon';
|
|
37
27
|
|
|
38
|
-
import {
|
|
28
|
+
import { IEditorDocumentModelRef, IResourceOpenOptions } from '../../common/editor';
|
|
39
29
|
import { IMultiDiffEditor, IMultiDiffSourceResolverService, IResolvedMultiDiffSource } from '../../common/multi-diff';
|
|
40
|
-
import { DiffEditorPart } from '../base-editor-wrapper';
|
|
41
30
|
import { EditorDocumentModelContentChangedEvent, IEditorDocumentModelService } from '../doc-model/types';
|
|
42
31
|
import { IConvertedMonacoOptions, IResource, ResourceDecorationNeedChangeEvent } from '../types';
|
|
43
32
|
|
|
44
|
-
import type { EditorCollectionServiceImpl } from '../editor-collection.service';
|
|
45
|
-
|
|
46
33
|
@Injectable({ multiple: true })
|
|
47
34
|
export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEditor {
|
|
48
35
|
@Autowired(INJECTOR_TOKEN)
|
|
@@ -52,7 +39,7 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
52
39
|
private readonly messageService: IMessageService;
|
|
53
40
|
|
|
54
41
|
@Autowired(IEditorDocumentModelService)
|
|
55
|
-
|
|
42
|
+
documentModelManager: IEditorDocumentModelService;
|
|
56
43
|
|
|
57
44
|
@Autowired(PreferenceService)
|
|
58
45
|
private readonly preferenceService: PreferenceService;
|
|
@@ -71,13 +58,8 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
71
58
|
|
|
72
59
|
private multiDiffModel: IMultiDiffEditorModel & IDisposable;
|
|
73
60
|
|
|
74
|
-
constructor(
|
|
75
|
-
public readonly multiDiffWidget: MultiDiffEditorWidget,
|
|
76
|
-
private convertedOptions: IConvertedMonacoOptions,
|
|
77
|
-
private editorCollectionService: EditorCollectionServiceImpl,
|
|
78
|
-
) {
|
|
61
|
+
constructor(private multiDiffWidget: MultiDiffEditorWidget, private convertedOptions: IConvertedMonacoOptions) {
|
|
79
62
|
super();
|
|
80
|
-
this.editorCollectionService.addMultiDiffEditors([this]);
|
|
81
63
|
}
|
|
82
64
|
|
|
83
65
|
@OnEvent(EditorDocumentModelContentChangedEvent)
|
|
@@ -127,33 +109,7 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
127
109
|
}
|
|
128
110
|
}
|
|
129
111
|
|
|
130
|
-
|
|
131
|
-
modifiedEditor: { editor: ICodeEditor } | undefined,
|
|
132
|
-
originalEditor: { editor: ICodeEditor } | undefined,
|
|
133
|
-
modifiedInstance: any,
|
|
134
|
-
originalInstance: any,
|
|
135
|
-
): void {
|
|
136
|
-
const editors: DiffEditorPart[] = [];
|
|
137
|
-
if (modifiedEditor) {
|
|
138
|
-
const modifiedDiffEditorPart = this.injector.get(DiffEditorPart, [
|
|
139
|
-
modifiedEditor.editor,
|
|
140
|
-
() => modifiedInstance,
|
|
141
|
-
EditorType.MODIFIED_DIFF,
|
|
142
|
-
]);
|
|
143
|
-
editors.push(modifiedDiffEditorPart);
|
|
144
|
-
}
|
|
145
|
-
if (originalEditor) {
|
|
146
|
-
const originalDiffEditorPart = this.injector.get(DiffEditorPart, [
|
|
147
|
-
originalEditor.editor,
|
|
148
|
-
() => originalInstance,
|
|
149
|
-
EditorType.ORIGINAL_DIFF,
|
|
150
|
-
]);
|
|
151
|
-
editors.push(originalDiffEditorPart);
|
|
152
|
-
}
|
|
153
|
-
this.editorCollectionService.addEditors(editors);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async compareMultiple(editor: IMultiDiffEditor, resource: IResource, options?: IResourceOpenOptions): Promise<void> {
|
|
112
|
+
async compareMultiple(resource: IResource, options?: IResourceOpenOptions): Promise<void> {
|
|
157
113
|
// Save current view state before changing
|
|
158
114
|
if (this.currentUri) {
|
|
159
115
|
this.saveViewState(this.currentUri);
|
|
@@ -168,10 +124,12 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
168
124
|
this,
|
|
169
125
|
resources,
|
|
170
126
|
async (r, store) => {
|
|
127
|
+
/** @description documentsWithPromises */
|
|
171
128
|
let original: IEditorDocumentModelRef | undefined;
|
|
172
129
|
let modified: IEditorDocumentModelRef | undefined;
|
|
173
130
|
|
|
174
131
|
const multiDiffItemStore = new DisposableStore();
|
|
132
|
+
|
|
175
133
|
try {
|
|
176
134
|
[original, modified] = await Promise.all([
|
|
177
135
|
r.originalUri ? this.documentModelManager.createModelReference(r.originalUri) : undefined,
|
|
@@ -194,11 +152,9 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
194
152
|
multiDiffEditorItem: r,
|
|
195
153
|
original: original?.instance.getMonacoModel(),
|
|
196
154
|
modified: modified?.instance.getMonacoModel(),
|
|
197
|
-
originalInstance: original?.instance,
|
|
198
|
-
modifiedInstance: modified?.instance,
|
|
199
155
|
contextKeys: r.contextKeys,
|
|
200
156
|
options: {
|
|
201
|
-
readOnly:
|
|
157
|
+
readOnly: modified?.instance.readonly,
|
|
202
158
|
// TODO: codelens,wordWrap options
|
|
203
159
|
...this.convertedOptions.diffOptions,
|
|
204
160
|
},
|
|
@@ -218,6 +174,7 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
218
174
|
const documents = observableValue<readonly RefCounted<IDocumentDiffItem>[] | 'loading'>('documents', 'loading');
|
|
219
175
|
|
|
220
176
|
const updateDocuments = derived(async (reader) => {
|
|
177
|
+
/** @description Update documents */
|
|
221
178
|
const docsPromises = documentsWithPromises.read(reader);
|
|
222
179
|
const docs = await Promise.all(docsPromises);
|
|
223
180
|
const newDocuments = docs.filter((item) => item !== undefined);
|
|
@@ -236,49 +193,11 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
|
|
|
236
193
|
const viewModel = this.multiDiffWidget.createViewModel(this.multiDiffModel);
|
|
237
194
|
await viewModel.waitForDiffs();
|
|
238
195
|
this.multiDiffWidget.setViewModel(viewModel);
|
|
239
|
-
this.multiDiffWidget.getActiveControl();
|
|
240
196
|
|
|
241
197
|
// Update current URI and restore view state
|
|
242
198
|
this.currentUri = resource.uri;
|
|
243
199
|
this.restoreViewState(resource.uri);
|
|
244
|
-
|
|
245
|
-
for (const ref of documentRefs) {
|
|
246
|
-
if (isString(ref)) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const modified = ref.object.modified;
|
|
250
|
-
const original = ref.object.original;
|
|
251
|
-
if (!modified && !original) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
let modifiedEditor = modified ? this.multiDiffWidget.tryGetCodeEditor(modified.uri) : undefined;
|
|
255
|
-
let originalEditor = original ? this.multiDiffWidget.tryGetCodeEditor(original.uri) : undefined;
|
|
256
|
-
if (!modifiedEditor && !originalEditor) {
|
|
257
|
-
const editor = modified || original;
|
|
258
|
-
if (!editor) {
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
Event.once(editor.onDidChangeAttached)(() => {
|
|
262
|
-
setTimeout(() => {
|
|
263
|
-
modifiedEditor = modified ? this.multiDiffWidget.tryGetCodeEditor(modified.uri) : undefined;
|
|
264
|
-
originalEditor = original ? this.multiDiffWidget.tryGetCodeEditor(original.uri) : undefined;
|
|
265
|
-
this.createAndRegisterEditorParts(
|
|
266
|
-
modifiedEditor,
|
|
267
|
-
originalEditor,
|
|
268
|
-
(ref.object as any).modifiedInstance,
|
|
269
|
-
(ref.object as any).originalInstance,
|
|
270
|
-
);
|
|
271
|
-
}, 0);
|
|
272
|
-
});
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
this.createAndRegisterEditorParts(
|
|
276
|
-
modifiedEditor,
|
|
277
|
-
originalEditor,
|
|
278
|
-
(ref.object as any).modifiedInstance,
|
|
279
|
-
(ref.object as any).originalInstance,
|
|
280
|
-
);
|
|
281
|
-
}
|
|
200
|
+
|
|
282
201
|
this.multiDiffModelChangeEmitter.fire(this.multiDiffModel);
|
|
283
202
|
}
|
|
284
203
|
|
|
@@ -40,6 +40,7 @@ export class MultiDiffResourceProvider extends WithEventBus implements IResource
|
|
|
40
40
|
// Get icon from the first modified file
|
|
41
41
|
const firstModifiedUri = parsedSources.length > 0 ? new URI(parsedSources[0].modifiedUri) : undefined;
|
|
42
42
|
const icon = firstModifiedUri ? this.labelService.getIcon(firstModifiedUri) : undefined;
|
|
43
|
+
|
|
43
44
|
return {
|
|
44
45
|
name: `Multi-Diff: ${name || parsedSources.length + ' files'}`,
|
|
45
46
|
icon: icon || getIcon('diff'),
|
|
@@ -2498,7 +2498,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
|
|
|
2498
2498
|
});
|
|
2499
2499
|
}
|
|
2500
2500
|
|
|
2501
|
-
await this.multiDiffEditor.compareMultiple(
|
|
2501
|
+
await this.multiDiffEditor.compareMultiple(resource, options);
|
|
2502
2502
|
}
|
|
2503
2503
|
}
|
|
2504
2504
|
|
package/src/common/multi-diff.ts
CHANGED
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
import { IResourceOpenOptions } from './editor';
|
|
11
11
|
import { IResource } from './resource';
|
|
12
12
|
|
|
13
|
-
import type { MultiDiffEditorWidget } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/widget/multiDiffEditor/multiDiffEditorWidget';
|
|
14
|
-
|
|
15
13
|
export const MULTI_DIFF_SCHEME = 'multi-diff-editor';
|
|
16
14
|
|
|
17
15
|
export const IMultiDiffSourceResolverService = Symbol('IMultiDiffSourceResolverService');
|
|
@@ -60,7 +58,7 @@ export interface IMultiDiffEditor extends IDisposable {
|
|
|
60
58
|
/**
|
|
61
59
|
* Compare multiple file pairs
|
|
62
60
|
*/
|
|
63
|
-
compareMultiple(
|
|
61
|
+
compareMultiple(resource: IResource, options?: IResourceOpenOptions): Promise<void>;
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
64
|
* Get all file pairs currently being compared
|
|
@@ -96,9 +94,4 @@ export interface IMultiDiffEditor extends IDisposable {
|
|
|
96
94
|
* Expand all files
|
|
97
95
|
*/
|
|
98
96
|
expandAll(): void;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the multi-diff editor widget
|
|
102
|
-
*/
|
|
103
|
-
multiDiffWidget: MultiDiffEditorWidget;
|
|
104
97
|
}
|