@opensumi/ide-editor 3.9.1-next-1748403623.0 → 3.9.1-next-1748403761.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.
Files changed (35) hide show
  1. package/lib/browser/base-editor-wrapper.d.ts +58 -0
  2. package/lib/browser/base-editor-wrapper.d.ts.map +1 -0
  3. package/lib/browser/base-editor-wrapper.js +203 -0
  4. package/lib/browser/base-editor-wrapper.js.map +1 -0
  5. package/lib/browser/decoration-applier.d.ts.map +1 -1
  6. package/lib/browser/decoration-applier.js.map +1 -1
  7. package/lib/browser/editor-collection.service.d.ts +21 -57
  8. package/lib/browser/editor-collection.service.d.ts.map +1 -1
  9. package/lib/browser/editor-collection.service.js +42 -206
  10. package/lib/browser/editor-collection.service.js.map +1 -1
  11. package/lib/browser/editor.contribution.d.ts.map +1 -1
  12. package/lib/browser/editor.contribution.js +1 -0
  13. package/lib/browser/editor.contribution.js.map +1 -1
  14. package/lib/browser/editor.less +25 -0
  15. package/lib/browser/multi-diff/multi-diff-editor.d.ts +10 -7
  16. package/lib/browser/multi-diff/multi-diff-editor.d.ts.map +1 -1
  17. package/lib/browser/multi-diff/multi-diff-editor.js +60 -7
  18. package/lib/browser/multi-diff/multi-diff-editor.js.map +1 -1
  19. package/lib/browser/multi-diff/multi-diff-resource.d.ts.map +1 -1
  20. package/lib/browser/multi-diff/multi-diff-resource.js.map +1 -1
  21. package/lib/browser/workbench-editor.service.js +1 -1
  22. package/lib/browser/workbench-editor.service.js.map +1 -1
  23. package/lib/common/multi-diff.d.ts +6 -1
  24. package/lib/common/multi-diff.d.ts.map +1 -1
  25. package/lib/common/multi-diff.js.map +1 -1
  26. package/package.json +14 -14
  27. package/src/browser/base-editor-wrapper.ts +254 -0
  28. package/src/browser/decoration-applier.ts +1 -0
  29. package/src/browser/editor-collection.service.ts +48 -263
  30. package/src/browser/editor.contribution.ts +2 -0
  31. package/src/browser/editor.less +25 -0
  32. package/src/browser/multi-diff/multi-diff-editor.ts +91 -10
  33. package/src/browser/multi-diff/multi-diff-resource.ts +0 -1
  34. package/src/browser/workbench-editor.service.ts +1 -1
  35. package/src/common/multi-diff.ts +8 -1
@@ -20,3 +20,28 @@
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,6 +1,16 @@
1
1
  import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
2
2
  import { PreferenceService } from '@opensumi/ide-core-browser';
3
- import { DisposableStore, Emitter, IDisposable, ILogger, OnEvent, URI, WithEventBus } from '@opensumi/ide-core-common';
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';
4
14
  import {
5
15
  ValueWithChangeEventFromObservable,
6
16
  constObservable,
@@ -25,11 +35,14 @@ import { IMultiDiffResourceId } from '@opensumi/monaco-editor-core/esm/vs/editor
25
35
  import { Range } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/range';
26
36
  import { IDiffEditor } from '@opensumi/monaco-editor-core/esm/vs/editor/common/editorCommon';
27
37
 
28
- import { IEditorDocumentModelRef, IResourceOpenOptions } from '../../common/editor';
38
+ import { EditorType, IEditorDocumentModelRef, IResourceOpenOptions } from '../../common/editor';
29
39
  import { IMultiDiffEditor, IMultiDiffSourceResolverService, IResolvedMultiDiffSource } from '../../common/multi-diff';
40
+ import { DiffEditorPart } from '../base-editor-wrapper';
30
41
  import { EditorDocumentModelContentChangedEvent, IEditorDocumentModelService } from '../doc-model/types';
31
42
  import { IConvertedMonacoOptions, IResource, ResourceDecorationNeedChangeEvent } from '../types';
32
43
 
44
+ import type { EditorCollectionServiceImpl } from '../editor-collection.service';
45
+
33
46
  @Injectable({ multiple: true })
34
47
  export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEditor {
35
48
  @Autowired(INJECTOR_TOKEN)
@@ -39,7 +52,7 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
39
52
  private readonly messageService: IMessageService;
40
53
 
41
54
  @Autowired(IEditorDocumentModelService)
42
- documentModelManager: IEditorDocumentModelService;
55
+ private readonly documentModelManager: IEditorDocumentModelService;
43
56
 
44
57
  @Autowired(PreferenceService)
45
58
  private readonly preferenceService: PreferenceService;
@@ -58,8 +71,13 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
58
71
 
59
72
  private multiDiffModel: IMultiDiffEditorModel & IDisposable;
60
73
 
61
- constructor(private multiDiffWidget: MultiDiffEditorWidget, private convertedOptions: IConvertedMonacoOptions) {
74
+ constructor(
75
+ public readonly multiDiffWidget: MultiDiffEditorWidget,
76
+ private convertedOptions: IConvertedMonacoOptions,
77
+ private editorCollectionService: EditorCollectionServiceImpl,
78
+ ) {
62
79
  super();
80
+ this.editorCollectionService.addMultiDiffEditors([this]);
63
81
  }
64
82
 
65
83
  @OnEvent(EditorDocumentModelContentChangedEvent)
@@ -109,7 +127,33 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
109
127
  }
110
128
  }
111
129
 
112
- async compareMultiple(resource: IResource, options?: IResourceOpenOptions): Promise<void> {
130
+ private createAndRegisterEditorParts(
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> {
113
157
  // Save current view state before changing
114
158
  if (this.currentUri) {
115
159
  this.saveViewState(this.currentUri);
@@ -124,12 +168,10 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
124
168
  this,
125
169
  resources,
126
170
  async (r, store) => {
127
- /** @description documentsWithPromises */
128
171
  let original: IEditorDocumentModelRef | undefined;
129
172
  let modified: IEditorDocumentModelRef | undefined;
130
173
 
131
174
  const multiDiffItemStore = new DisposableStore();
132
-
133
175
  try {
134
176
  [original, modified] = await Promise.all([
135
177
  r.originalUri ? this.documentModelManager.createModelReference(r.originalUri) : undefined,
@@ -152,9 +194,11 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
152
194
  multiDiffEditorItem: r,
153
195
  original: original?.instance.getMonacoModel(),
154
196
  modified: modified?.instance.getMonacoModel(),
197
+ originalInstance: original?.instance,
198
+ modifiedInstance: modified?.instance,
155
199
  contextKeys: r.contextKeys,
156
200
  options: {
157
- readOnly: modified?.instance.readonly,
201
+ readOnly: (modified || original)?.instance.readonly,
158
202
  // TODO: codelens,wordWrap options
159
203
  ...this.convertedOptions.diffOptions,
160
204
  },
@@ -174,7 +218,6 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
174
218
  const documents = observableValue<readonly RefCounted<IDocumentDiffItem>[] | 'loading'>('documents', 'loading');
175
219
 
176
220
  const updateDocuments = derived(async (reader) => {
177
- /** @description Update documents */
178
221
  const docsPromises = documentsWithPromises.read(reader);
179
222
  const docs = await Promise.all(docsPromises);
180
223
  const newDocuments = docs.filter((item) => item !== undefined);
@@ -193,11 +236,49 @@ export class BrowserMultiDiffEditor extends WithEventBus implements IMultiDiffEd
193
236
  const viewModel = this.multiDiffWidget.createViewModel(this.multiDiffModel);
194
237
  await viewModel.waitForDiffs();
195
238
  this.multiDiffWidget.setViewModel(viewModel);
239
+ this.multiDiffWidget.getActiveControl();
196
240
 
197
241
  // Update current URI and restore view state
198
242
  this.currentUri = resource.uri;
199
243
  this.restoreViewState(resource.uri);
200
-
244
+ const documentRefs = documents.get();
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
+ }
201
282
  this.multiDiffModelChangeEmitter.fire(this.multiDiffModel);
202
283
  }
203
284
 
@@ -40,7 +40,6 @@ 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
-
44
43
  return {
45
44
  name: `Multi-Diff: ${name || parsedSources.length + ' files'}`,
46
45
  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(resource, options);
2501
+ await this.multiDiffEditor.compareMultiple(this.multiDiffEditor, resource, options);
2502
2502
  }
2503
2503
  }
2504
2504
 
@@ -10,6 +10,8 @@ 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
+
13
15
  export const MULTI_DIFF_SCHEME = 'multi-diff-editor';
14
16
 
15
17
  export const IMultiDiffSourceResolverService = Symbol('IMultiDiffSourceResolverService');
@@ -58,7 +60,7 @@ export interface IMultiDiffEditor extends IDisposable {
58
60
  /**
59
61
  * Compare multiple file pairs
60
62
  */
61
- compareMultiple(resource: IResource, options?: IResourceOpenOptions): Promise<void>;
63
+ compareMultiple(editor: IMultiDiffEditor, resource: IResource, options?: IResourceOpenOptions): Promise<void>;
62
64
 
63
65
  /**
64
66
  * Get all file pairs currently being compared
@@ -94,4 +96,9 @@ export interface IMultiDiffEditor extends IDisposable {
94
96
  * Expand all files
95
97
  */
96
98
  expandAll(): void;
99
+
100
+ /**
101
+ * Get the multi-diff editor widget
102
+ */
103
+ multiDiffWidget: MultiDiffEditorWidget;
97
104
  }