@opensumi/ide-editor 3.9.1-next-1747836538.0 → 3.9.1-next-1747917815.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 (30) 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.less +25 -0
  12. package/lib/browser/multi-diff/multi-diff-editor.d.ts +9 -6
  13. package/lib/browser/multi-diff/multi-diff-editor.d.ts.map +1 -1
  14. package/lib/browser/multi-diff/multi-diff-editor.js +58 -7
  15. package/lib/browser/multi-diff/multi-diff-editor.js.map +1 -1
  16. package/lib/browser/multi-diff/multi-diff-resource.d.ts.map +1 -1
  17. package/lib/browser/multi-diff/multi-diff-resource.js.map +1 -1
  18. package/lib/browser/workbench-editor.service.js +1 -1
  19. package/lib/browser/workbench-editor.service.js.map +1 -1
  20. package/lib/common/multi-diff.d.ts +1 -1
  21. package/lib/common/multi-diff.d.ts.map +1 -1
  22. package/package.json +14 -14
  23. package/src/browser/base-editor-wrapper.ts +254 -0
  24. package/src/browser/decoration-applier.ts +1 -0
  25. package/src/browser/editor-collection.service.ts +48 -262
  26. package/src/browser/editor.less +25 -0
  27. package/src/browser/multi-diff/multi-diff-editor.ts +89 -10
  28. package/src/browser/multi-diff/multi-diff-resource.ts +0 -1
  29. package/src/browser/workbench-editor.service.ts +1 -1
  30. package/src/common/multi-diff.ts +1 -1
@@ -0,0 +1,254 @@
1
+ import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
2
+ import { IRange } from '@opensumi/ide-core-browser';
3
+ import { Disposable, ISelection, URI, WithEventBus, isEmptyObject, objects } from '@opensumi/ide-core-common';
4
+ import * as monaco from '@opensumi/ide-monaco';
5
+ import { IConfigurationService } from '@opensumi/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
6
+
7
+ import { EditorType, IDecorationApplyOptions, IEditor, IUndoStopOptions } from '../common';
8
+ import { IEditorDocumentModel } from '../common/editor';
9
+
10
+ import { MonacoEditorDecorationApplier } from './decoration-applier';
11
+ import { getConvertedMonacoOptions, isEditorOption } from './preference/converter';
12
+ import { IEditorFeatureRegistry } from './types';
13
+
14
+ import type { ICodeEditor as IMonacoCodeEditor } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
15
+
16
+ export type ISumiEditor = IEditor;
17
+
18
+ export function insertSnippetWithMonacoEditor(
19
+ editor: IMonacoCodeEditor,
20
+ template: string,
21
+ ranges: IRange[],
22
+ opts: IUndoStopOptions,
23
+ ) {
24
+ const snippetController = editor.getContribution('snippetController2') as any;
25
+ const selections: ISelection[] = ranges.map(
26
+ (r) => new monaco.Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn),
27
+ );
28
+ editor.setSelections(selections);
29
+ editor.focus();
30
+
31
+ snippetController.insert(template, 0, 0, opts.undoStopBefore, opts.undoStopAfter);
32
+ }
33
+
34
+ const { removeUndefined } = objects;
35
+
36
+ function updateOptionsWithMonacoEditor(
37
+ monacoEditor: IMonacoCodeEditor,
38
+ editorOptions: monaco.editor.IEditorOptions,
39
+ modelOptions: monaco.editor.ITextModelUpdateOptions,
40
+ ) {
41
+ monacoEditor.updateOptions(editorOptions);
42
+ if (monacoEditor.getModel()) {
43
+ monacoEditor.getModel()!.updateOptions(modelOptions);
44
+ }
45
+ }
46
+
47
+ @Injectable({ multiple: true })
48
+ export abstract class BaseMonacoEditorWrapper extends WithEventBus implements IEditor {
49
+ public abstract readonly currentDocumentModel: IEditorDocumentModel | null;
50
+
51
+ public get currentUri(): URI | null {
52
+ return this.currentDocumentModel ? this.currentDocumentModel.uri : null;
53
+ }
54
+
55
+ public getId() {
56
+ return this.monacoEditor.getId();
57
+ }
58
+
59
+ getSelections() {
60
+ return this.monacoEditor.getSelections() || [];
61
+ }
62
+
63
+ public onFocus = this.monacoEditor.onDidFocusEditorWidget;
64
+
65
+ public onBlur = this.monacoEditor.onDidBlurEditorWidget;
66
+
67
+ protected _specialEditorOptions: any = {};
68
+
69
+ protected _specialModelOptions: monaco.editor.ITextModelUpdateOptions = {};
70
+
71
+ protected _editorOptionsFromContribution: any = {};
72
+
73
+ @Autowired(IEditorFeatureRegistry)
74
+ protected readonly editorFeatureRegistry: IEditorFeatureRegistry;
75
+
76
+ @Autowired(IConfigurationService)
77
+ protected readonly configurationService: IConfigurationService;
78
+
79
+ protected readonly decorationApplier: MonacoEditorDecorationApplier;
80
+
81
+ private _disableSelectionEmitter = false;
82
+
83
+ protected disableSelectionEmitter() {
84
+ this._disableSelectionEmitter = true;
85
+ }
86
+
87
+ protected enableSelectionEmitter() {
88
+ this._disableSelectionEmitter = false;
89
+ }
90
+
91
+ @Autowired(INJECTOR_TOKEN)
92
+ private injector: Injector;
93
+
94
+ constructor(public readonly monacoEditor: IMonacoCodeEditor, private type: EditorType) {
95
+ super();
96
+ this.decorationApplier = this.injector.get(MonacoEditorDecorationApplier, [this.monacoEditor]);
97
+ this.addDispose(this.monacoEditor.onDidChangeModel(this.onDidChangeModel.bind(this)));
98
+ this.addDispose(
99
+ this.monacoEditor.onDidChangeModelLanguage(() => {
100
+ this._doUpdateOptions();
101
+ }),
102
+ );
103
+ this.addDispose(
104
+ this.configurationService.onDidChangeConfiguration((e) => {
105
+ const changedEditorKeys = Array.from(e.affectedKeys.values()).filter((key) => isEditorOption(key));
106
+ if (changedEditorKeys.length > 0) {
107
+ this._doUpdateOptions();
108
+ }
109
+ }),
110
+ );
111
+ }
112
+
113
+ private async onDidChangeModel() {
114
+ this._editorOptionsFromContribution = {};
115
+ const uri = this.currentUri;
116
+ if (uri) {
117
+ Promise.resolve(this.editorFeatureRegistry.runProvideEditorOptionsForUri(uri)).then((options) => {
118
+ if (!this.currentUri || !uri.isEqual(this.currentUri)) {
119
+ return; // uri可能已经变了
120
+ }
121
+
122
+ if (options && Object.keys(options).length > 0) {
123
+ this._editorOptionsFromContribution = options;
124
+ if (!isEmptyObject(this._editorOptionsFromContribution)) {
125
+ this._doUpdateOptions();
126
+ }
127
+ }
128
+ });
129
+ }
130
+ }
131
+
132
+ public getType() {
133
+ return this.type;
134
+ }
135
+
136
+ updateOptions(
137
+ editorOptions: monaco.editor.IEditorOptions = {},
138
+ modelOptions: monaco.editor.ITextModelUpdateOptions = {},
139
+ ) {
140
+ this._specialEditorOptions = removeUndefined({ ...this._specialEditorOptions, ...editorOptions });
141
+ this._specialModelOptions = removeUndefined({ ...this._specialModelOptions, ...modelOptions });
142
+ this._doUpdateOptions();
143
+ }
144
+
145
+ private _doUpdateOptions() {
146
+ const { editorOptions, modelOptions } = this._calculateFinalOptions();
147
+ updateOptionsWithMonacoEditor(this.monacoEditor, editorOptions, modelOptions);
148
+ }
149
+
150
+ /**
151
+ * 合并所有的选项
152
+ * 优先关系: (从高到底)
153
+ * 1. 当前编辑器的特殊选项(通过调用 updateOptions或者启动时传入)
154
+ * 2. 来自 featureRegistry 的根据 当前uri 提供的选项
155
+ * 3. 来自偏好设置的选项
156
+ */
157
+ private _calculateFinalOptions() {
158
+ const uriStr = this.currentUri ? this.currentUri.toString() : undefined;
159
+ const languageId = this.currentDocumentModel ? this.currentDocumentModel.languageId : undefined;
160
+ const options = getConvertedMonacoOptions(this.configurationService, uriStr, languageId, undefined);
161
+ const basicEditorOptions: Partial<monaco.editor.IEditorOptions> = {
162
+ readOnly: this.currentDocumentModel?.readonly || false,
163
+ };
164
+
165
+ let editorOptions = {
166
+ ...basicEditorOptions,
167
+ ...options.editorOptions,
168
+ ...this._editorOptionsFromContribution,
169
+ ...this._specialEditorOptions,
170
+ };
171
+
172
+ if (this.type !== EditorType.CODE) {
173
+ editorOptions = {
174
+ ...editorOptions,
175
+ ...options.diffOptions,
176
+ };
177
+ }
178
+
179
+ return {
180
+ editorOptions,
181
+ modelOptions: { ...options.modelOptions, ...this._specialModelOptions },
182
+ };
183
+ }
184
+
185
+ insertSnippet(template: string, ranges: IRange[], opts: IUndoStopOptions) {
186
+ insertSnippetWithMonacoEditor(this.monacoEditor, template, ranges, opts);
187
+ }
188
+
189
+ applyDecoration(key: string, options: IDecorationApplyOptions[]) {
190
+ this.decorationApplier.applyDecoration(key, options);
191
+ }
192
+
193
+ onSelectionsChanged(listener) {
194
+ return this.monacoEditor.onDidChangeCursorSelection((e) => {
195
+ if (!this._disableSelectionEmitter) {
196
+ listener({
197
+ selections: this.getSelections(),
198
+ source: e.source,
199
+ });
200
+ }
201
+ });
202
+ }
203
+
204
+ onVisibleRangesChanged(listener) {
205
+ const disposer = new Disposable();
206
+ const monacoEditor = this.monacoEditor;
207
+ disposer.addDispose(
208
+ monacoEditor.onDidScrollChange((e) => {
209
+ listener(this.monacoEditor.getVisibleRanges());
210
+ }),
211
+ );
212
+ disposer.addDispose(
213
+ monacoEditor.onDidLayoutChange((e) => {
214
+ listener(this.monacoEditor.getVisibleRanges());
215
+ }),
216
+ );
217
+ return disposer;
218
+ }
219
+
220
+ setSelections(selections) {
221
+ return this.monacoEditor.setSelections(selections as any);
222
+ }
223
+
224
+ setSelection(selection) {
225
+ return this.monacoEditor.setSelection(selection as any);
226
+ }
227
+
228
+ public async save(): Promise<void> {
229
+ if (this.currentDocumentModel) {
230
+ await this.currentDocumentModel.save();
231
+ }
232
+ }
233
+
234
+ onConfigurationChanged(listener) {
235
+ const monacoEditor = this.monacoEditor;
236
+ return monacoEditor.onDidChangeConfiguration((e) => {
237
+ listener();
238
+ });
239
+ }
240
+ }
241
+ @Injectable({ multiple: true })
242
+ export class DiffEditorPart extends BaseMonacoEditorWrapper implements IEditor {
243
+ get currentDocumentModel() {
244
+ return this.getDocumentModel();
245
+ }
246
+
247
+ constructor(
248
+ monacoEditor: IMonacoCodeEditor,
249
+ private getDocumentModel: () => IEditorDocumentModel | null,
250
+ type: EditorType,
251
+ ) {
252
+ super(monacoEditor, type);
253
+ }
254
+ }
@@ -34,6 +34,7 @@ export class MonacoEditorDecorationApplier extends Disposable {
34
34
  constructor(private editor: IMonacoCodeEditor) {
35
35
  super();
36
36
  this.applyDecorationFromProvider();
37
+
37
38
  this.editor.onDidChangeModel(() => {
38
39
  this.clearDecorations();
39
40
  this.applyDecorationFromProvider();
@@ -1,18 +1,15 @@
1
1
  import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
2
- import { AppConfig, IContextKeyService, IRange, PreferenceService } from '@opensumi/ide-core-browser';
2
+ import { AppConfig, IContextKeyService, 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,
7
6
  Emitter,
8
7
  Event,
9
8
  Emitter as EventEmitter,
10
9
  ILineChange,
11
- ISelection,
12
10
  OnEvent,
13
11
  URI,
14
12
  WithEventBus,
15
- isEmptyObject,
16
13
  objects,
17
14
  } from '@opensumi/ide-core-common';
18
15
  import * as monaco from '@opensumi/ide-monaco';
@@ -24,21 +21,19 @@ import {
24
21
  EditorCollectionService,
25
22
  EditorType,
26
23
  ICodeEditor,
27
- IDecorationApplyOptions,
28
24
  IDiffEditor,
29
25
  IEditor,
30
- IResource,
31
26
  IResourceOpenOptions,
32
- IUndoStopOptions,
33
27
  ResourceDecorationNeedChangeEvent,
34
28
  } from '../common';
35
- import { IEditorDocumentModel, IEditorDocumentModelRef, isTextEditorViewState } from '../common/editor';
29
+ import { IEditorDocumentModelRef, isTextEditorViewState } from '../common/editor';
30
+ import { IMultiDiffEditor } from '../common/multi-diff';
36
31
 
37
- import { MonacoEditorDecorationApplier } from './decoration-applier';
32
+ import { BaseMonacoEditorWrapper, DiffEditorPart, ISumiEditor } from './base-editor-wrapper';
38
33
  import { EditorDocumentModelContentChangedEvent, IEditorDocumentModelService } from './doc-model/types';
39
34
  import { EditorFeatureRegistryImpl } from './feature';
40
35
  import { BrowserMultiDiffEditor } from './multi-diff/multi-diff-editor';
41
- import { getConvertedMonacoOptions, isDiffEditorOption, isEditorOption } from './preference/converter';
36
+ import { getConvertedMonacoOptions, isDiffEditorOption } from './preference/converter';
42
37
  import { IConvertedMonacoOptions, IEditorFeatureRegistry } from './types';
43
38
 
44
39
  import type {
@@ -47,8 +42,6 @@ import type {
47
42
  } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
48
43
  import type { IDiffEditorConstructionOptions } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
49
44
 
50
- const { removeUndefined } = objects;
51
-
52
45
  @Injectable()
53
46
  export class EditorCollectionServiceImpl extends WithEventBus implements EditorCollectionService {
54
47
  @Autowired()
@@ -65,12 +58,23 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
65
58
 
66
59
  private _editors: Set<ISumiEditor> = new Set();
67
60
  private _diffEditors: Set<IDiffEditor> = new Set();
61
+ private _multiDiffEditors: Set<IMultiDiffEditor> = new Set();
68
62
 
69
63
  private _onCodeEditorCreate = new Emitter<ICodeEditor>();
70
64
  private _onDiffEditorCreate = new Emitter<IDiffEditor>();
65
+ private _onMultiDiffEditorCreate = new Emitter<IMultiDiffEditor>();
66
+
67
+ private _onCodeEditorChange = new Emitter<void>();
68
+ private _onDiffEditorChange = new Emitter<void>();
69
+ private _onMultiDiffEditorChange = new Emitter<void>();
71
70
 
72
71
  public onCodeEditorCreate = this._onCodeEditorCreate.event;
73
72
  public onDiffEditorCreate = this._onDiffEditorCreate.event;
73
+ public onMultiDiffEditorCreate = this._onMultiDiffEditorCreate.event;
74
+
75
+ public onCodeEditorChange = this._onCodeEditorChange.event;
76
+ public onDiffEditorChange = this._onDiffEditorChange.event;
77
+ public onMultiDiffEditorChange = this._onMultiDiffEditorChange.event;
74
78
 
75
79
  @Autowired(IEditorDocumentModelService)
76
80
  documentModelService: IEditorDocumentModelService;
@@ -128,7 +132,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
128
132
  }
129
133
  });
130
134
  if (this._editors.size !== beforeSize) {
131
- // fire event;
135
+ this._onCodeEditorChange.fire();
132
136
  }
133
137
  }
134
138
 
@@ -141,7 +145,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
141
145
  }
142
146
  });
143
147
  if (this._editors.size !== beforeSize) {
144
- // fire event;
148
+ this._onCodeEditorChange.fire();
145
149
  }
146
150
  }
147
151
 
@@ -154,11 +158,11 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
154
158
  return editor;
155
159
  }
156
160
 
157
- createMultiDiffEditor(dom: HTMLElement, options?: any, overrides?: { [key: string]: any }) {
161
+ public createMultiDiffEditor(dom: HTMLElement, options?: any, overrides?: { [key: string]: any }) {
158
162
  const convertedOptions = getConvertedMonacoOptions(this.configurationService);
159
163
  const monacoMultiDiffEditorWidget = this.monacoService.createMultiDiffEditorWidget(dom, overrides);
160
164
  const mergedOptions: IConvertedMonacoOptions = { ...convertedOptions.diffOptions, ...options };
161
- const editor = this.injector.get(BrowserMultiDiffEditor, [monacoMultiDiffEditorWidget, mergedOptions]);
165
+ const editor = this.injector.get(BrowserMultiDiffEditor, [monacoMultiDiffEditorWidget, mergedOptions, this]);
162
166
  return editor;
163
167
  }
164
168
 
@@ -187,7 +191,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
187
191
  }
188
192
  });
189
193
  if (this._diffEditors.size !== beforeSize) {
190
- // fire event _onDiffEditorAdd;
194
+ this._onDiffEditorChange.fire();
191
195
  }
192
196
  }
193
197
 
@@ -197,11 +201,36 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
197
201
  this._diffEditors.delete(diffEditor);
198
202
  });
199
203
  if (this._diffEditors.size !== beforeSize) {
200
- // fire event _onDiffEditorRemove;
204
+ this._onDiffEditorChange.fire();
205
+ }
206
+ }
207
+
208
+ public listMultiDiffEditors(): IMultiDiffEditor[] {
209
+ return Array.from(this._multiDiffEditors.values());
210
+ }
211
+
212
+ public addMultiDiffEditors(multiDiffEditors: IMultiDiffEditor[]) {
213
+ const beforeSize = this._multiDiffEditors.size;
214
+ multiDiffEditors.forEach((multiDiffEditor) => {
215
+ if (!this._multiDiffEditors.has(multiDiffEditor)) {
216
+ this._multiDiffEditors.add(multiDiffEditor);
217
+ }
218
+ });
219
+ if (this._multiDiffEditors.size !== beforeSize) {
220
+ this._onMultiDiffEditorChange.fire();
221
+ }
222
+ }
223
+
224
+ public removeMultiDiffEditors(multiDiffEditors: IMultiDiffEditor[]) {
225
+ const beforeSize = this._multiDiffEditors.size;
226
+ multiDiffEditors.forEach((multiDiffEditor) => {
227
+ this._multiDiffEditors.delete(multiDiffEditor);
228
+ });
229
+ if (this._multiDiffEditors.size !== beforeSize) {
230
+ this._onMultiDiffEditorChange.fire();
201
231
  }
202
232
  }
203
233
 
204
- // 将docModel的变更事件反映至resource的dirty装饰
205
234
  @OnEvent(EditorDocumentModelContentChangedEvent)
206
235
  onDocModelContentChangedEvent(e: EditorDocumentModelContentChangedEvent) {
207
236
  this.eventBus.fire(
@@ -216,230 +245,6 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
216
245
  }
217
246
  }
218
247
 
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
-
443
248
  @Injectable({ multiple: true })
444
249
  export class BrowserCodeEditor extends BaseMonacoEditorWrapper implements ICodeEditor {
445
250
  @Autowired(EditorCollectionService)
@@ -568,9 +373,6 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
568
373
  @Autowired(EditorCollectionService)
569
374
  private collectionService: EditorCollectionServiceImpl;
570
375
 
571
- @Autowired(AppConfig)
572
- private appConfig: AppConfig;
573
-
574
376
  private originalDocModelRef: IEditorDocumentModelRef | null;
575
377
 
576
378
  private modifiedDocModelRef: IEditorDocumentModelRef | null;
@@ -837,7 +639,6 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
837
639
  }
838
640
 
839
641
  // utils
840
-
841
642
  function bindPreventNavigation(div: HTMLElement) {
842
643
  div.addEventListener('mousewheel', preventNavigation as any);
843
644
  }
@@ -853,18 +654,3 @@ function preventNavigation(this: HTMLDivElement, e: WheelEvent) {
853
654
  e.stopPropagation();
854
655
  }
855
656
  }
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
- }