@opensumi/ide-editor 3.8.3-next-1747817292.0 → 3.8.3-next-1747895552.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/base-editor-wrapper.d.ts +58 -0
- package/lib/browser/base-editor-wrapper.d.ts.map +1 -0
- package/lib/browser/base-editor-wrapper.js +203 -0
- package/lib/browser/base-editor-wrapper.js.map +1 -0
- package/lib/browser/editor-collection.service.d.ts +8 -57
- package/lib/browser/editor-collection.service.d.ts.map +1 -1
- package/lib/browser/editor-collection.service.js +6 -202
- package/lib/browser/editor-collection.service.js.map +1 -1
- package/lib/browser/editor.less +11 -0
- package/lib/browser/multi-diff/multi-diff-editor.d.ts +6 -5
- package/lib/browser/multi-diff/multi-diff-editor.d.ts.map +1 -1
- package/lib/browser/multi-diff/multi-diff-editor.js +29 -24
- package/lib/browser/multi-diff/multi-diff-editor.js.map +1 -1
- package/package.json +14 -14
- package/src/browser/base-editor-wrapper.ts +254 -0
- package/src/browser/editor-collection.service.ts +5 -256
- package/src/browser/editor.less +11 -0
- package/src/browser/multi-diff/multi-diff-editor.ts +54 -31
|
@@ -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
|
+
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
|
|
2
|
-
import { AppConfig, IContextKeyService,
|
|
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
26
|
IResourceOpenOptions,
|
|
31
|
-
IUndoStopOptions,
|
|
32
27
|
ResourceDecorationNeedChangeEvent,
|
|
33
28
|
} from '../common';
|
|
34
|
-
import {
|
|
29
|
+
import { IEditorDocumentModelRef, isTextEditorViewState } from '../common/editor';
|
|
35
30
|
import { IMultiDiffEditor } from '../common/multi-diff';
|
|
36
31
|
|
|
37
|
-
import {
|
|
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
|
|
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()
|
|
@@ -169,7 +162,7 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
169
162
|
const convertedOptions = getConvertedMonacoOptions(this.configurationService);
|
|
170
163
|
const monacoMultiDiffEditorWidget = this.monacoService.createMultiDiffEditorWidget(dom, overrides);
|
|
171
164
|
const mergedOptions: IConvertedMonacoOptions = { ...convertedOptions.diffOptions, ...options };
|
|
172
|
-
const editor = this.injector.get(BrowserMultiDiffEditor, [monacoMultiDiffEditorWidget, mergedOptions]);
|
|
165
|
+
const editor = this.injector.get(BrowserMultiDiffEditor, [monacoMultiDiffEditorWidget, mergedOptions, this]);
|
|
173
166
|
return editor;
|
|
174
167
|
}
|
|
175
168
|
|
|
@@ -238,7 +231,6 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
238
231
|
}
|
|
239
232
|
}
|
|
240
233
|
|
|
241
|
-
// 将docModel的变更事件反映至resource的dirty装饰
|
|
242
234
|
@OnEvent(EditorDocumentModelContentChangedEvent)
|
|
243
235
|
onDocModelContentChangedEvent(e: EditorDocumentModelContentChangedEvent) {
|
|
244
236
|
this.eventBus.fire(
|
|
@@ -253,230 +245,6 @@ export class EditorCollectionServiceImpl extends WithEventBus implements EditorC
|
|
|
253
245
|
}
|
|
254
246
|
}
|
|
255
247
|
|
|
256
|
-
export type ISumiEditor = IEditor;
|
|
257
|
-
|
|
258
|
-
export function insertSnippetWithMonacoEditor(
|
|
259
|
-
editor: IMonacoCodeEditor,
|
|
260
|
-
template: string,
|
|
261
|
-
ranges: IRange[],
|
|
262
|
-
opts: IUndoStopOptions,
|
|
263
|
-
) {
|
|
264
|
-
const snippetController = editor.getContribution('snippetController2') as any;
|
|
265
|
-
const selections: ISelection[] = ranges.map(
|
|
266
|
-
(r) => new monaco.Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn),
|
|
267
|
-
);
|
|
268
|
-
editor.setSelections(selections);
|
|
269
|
-
editor.focus();
|
|
270
|
-
|
|
271
|
-
snippetController.insert(template, 0, 0, opts.undoStopBefore, opts.undoStopAfter);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function updateOptionsWithMonacoEditor(
|
|
275
|
-
monacoEditor: IMonacoCodeEditor,
|
|
276
|
-
editorOptions: monaco.editor.IEditorOptions,
|
|
277
|
-
modelOptions: monaco.editor.ITextModelUpdateOptions,
|
|
278
|
-
) {
|
|
279
|
-
monacoEditor.updateOptions(editorOptions);
|
|
280
|
-
if (monacoEditor.getModel()) {
|
|
281
|
-
monacoEditor.getModel()!.updateOptions(modelOptions);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
@Injectable({ multiple: true })
|
|
286
|
-
export abstract class BaseMonacoEditorWrapper extends WithEventBus implements IEditor {
|
|
287
|
-
public abstract readonly currentDocumentModel: IEditorDocumentModel | null;
|
|
288
|
-
|
|
289
|
-
public get currentUri(): URI | null {
|
|
290
|
-
return this.currentDocumentModel ? this.currentDocumentModel.uri : null;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
public getId() {
|
|
294
|
-
return this.monacoEditor.getId();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
getSelections() {
|
|
298
|
-
return this.monacoEditor.getSelections() || [];
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
public onFocus = this.monacoEditor.onDidFocusEditorWidget;
|
|
302
|
-
|
|
303
|
-
public onBlur = this.monacoEditor.onDidBlurEditorWidget;
|
|
304
|
-
|
|
305
|
-
protected _specialEditorOptions: any = {};
|
|
306
|
-
|
|
307
|
-
protected _specialModelOptions: monaco.editor.ITextModelUpdateOptions = {};
|
|
308
|
-
|
|
309
|
-
protected _editorOptionsFromContribution: any = {};
|
|
310
|
-
|
|
311
|
-
@Autowired(IEditorFeatureRegistry)
|
|
312
|
-
protected readonly editorFeatureRegistry: IEditorFeatureRegistry;
|
|
313
|
-
|
|
314
|
-
@Autowired(IConfigurationService)
|
|
315
|
-
protected readonly configurationService: IConfigurationService;
|
|
316
|
-
|
|
317
|
-
protected readonly decorationApplier: MonacoEditorDecorationApplier;
|
|
318
|
-
|
|
319
|
-
private _disableSelectionEmitter = false;
|
|
320
|
-
|
|
321
|
-
protected disableSelectionEmitter() {
|
|
322
|
-
this._disableSelectionEmitter = true;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
protected enableSelectionEmitter() {
|
|
326
|
-
this._disableSelectionEmitter = false;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
@Autowired(INJECTOR_TOKEN)
|
|
330
|
-
private injector: Injector;
|
|
331
|
-
|
|
332
|
-
constructor(public readonly monacoEditor: IMonacoCodeEditor, private type: EditorType) {
|
|
333
|
-
super();
|
|
334
|
-
this.decorationApplier = this.injector.get(MonacoEditorDecorationApplier, [this.monacoEditor]);
|
|
335
|
-
this.addDispose(this.monacoEditor.onDidChangeModel(this.onDidChangeModel.bind(this)));
|
|
336
|
-
this.addDispose(
|
|
337
|
-
this.monacoEditor.onDidChangeModelLanguage(() => {
|
|
338
|
-
this._doUpdateOptions();
|
|
339
|
-
}),
|
|
340
|
-
);
|
|
341
|
-
this.addDispose(
|
|
342
|
-
this.configurationService.onDidChangeConfiguration((e) => {
|
|
343
|
-
const changedEditorKeys = Array.from(e.affectedKeys.values()).filter((key) => isEditorOption(key));
|
|
344
|
-
if (changedEditorKeys.length > 0) {
|
|
345
|
-
this._doUpdateOptions();
|
|
346
|
-
}
|
|
347
|
-
}),
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
private async onDidChangeModel() {
|
|
352
|
-
this._editorOptionsFromContribution = {};
|
|
353
|
-
const uri = this.currentUri;
|
|
354
|
-
if (uri) {
|
|
355
|
-
Promise.resolve(this.editorFeatureRegistry.runProvideEditorOptionsForUri(uri)).then((options) => {
|
|
356
|
-
if (!this.currentUri || !uri.isEqual(this.currentUri)) {
|
|
357
|
-
return; // uri可能已经变了
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (options && Object.keys(options).length > 0) {
|
|
361
|
-
this._editorOptionsFromContribution = options;
|
|
362
|
-
if (!isEmptyObject(this._editorOptionsFromContribution)) {
|
|
363
|
-
this._doUpdateOptions();
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
public getType() {
|
|
371
|
-
return this.type;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
updateOptions(
|
|
375
|
-
editorOptions: monaco.editor.IEditorOptions = {},
|
|
376
|
-
modelOptions: monaco.editor.ITextModelUpdateOptions = {},
|
|
377
|
-
) {
|
|
378
|
-
this._specialEditorOptions = removeUndefined({ ...this._specialEditorOptions, ...editorOptions });
|
|
379
|
-
this._specialModelOptions = removeUndefined({ ...this._specialModelOptions, ...modelOptions });
|
|
380
|
-
this._doUpdateOptions();
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
private _doUpdateOptions() {
|
|
384
|
-
const { editorOptions, modelOptions } = this._calculateFinalOptions();
|
|
385
|
-
updateOptionsWithMonacoEditor(this.monacoEditor, editorOptions, modelOptions);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* 合并所有的选项
|
|
390
|
-
* 优先关系: (从高到底)
|
|
391
|
-
* 1. 当前编辑器的特殊选项(通过调用 updateOptions或者启动时传入)
|
|
392
|
-
* 2. 来自 featureRegistry 的根据 当前uri 提供的选项
|
|
393
|
-
* 3. 来自偏好设置的选项
|
|
394
|
-
*/
|
|
395
|
-
private _calculateFinalOptions() {
|
|
396
|
-
const uriStr = this.currentUri ? this.currentUri.toString() : undefined;
|
|
397
|
-
const languageId = this.currentDocumentModel ? this.currentDocumentModel.languageId : undefined;
|
|
398
|
-
const options = getConvertedMonacoOptions(this.configurationService, uriStr, languageId, undefined);
|
|
399
|
-
const basicEditorOptions: Partial<monaco.editor.IEditorOptions> = {
|
|
400
|
-
readOnly: this.currentDocumentModel?.readonly || false,
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
let editorOptions = {
|
|
404
|
-
...basicEditorOptions,
|
|
405
|
-
...options.editorOptions,
|
|
406
|
-
...this._editorOptionsFromContribution,
|
|
407
|
-
...this._specialEditorOptions,
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
if (this.type !== EditorType.CODE) {
|
|
411
|
-
editorOptions = {
|
|
412
|
-
...editorOptions,
|
|
413
|
-
...options.diffOptions,
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return {
|
|
418
|
-
editorOptions,
|
|
419
|
-
modelOptions: { ...options.modelOptions, ...this._specialModelOptions },
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
insertSnippet(template: string, ranges: IRange[], opts: IUndoStopOptions) {
|
|
424
|
-
insertSnippetWithMonacoEditor(this.monacoEditor, template, ranges, opts);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
applyDecoration(key: string, options: IDecorationApplyOptions[]) {
|
|
428
|
-
this.decorationApplier.applyDecoration(key, options);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
onSelectionsChanged(listener) {
|
|
432
|
-
return this.monacoEditor.onDidChangeCursorSelection((e) => {
|
|
433
|
-
if (!this._disableSelectionEmitter) {
|
|
434
|
-
listener({
|
|
435
|
-
selections: this.getSelections(),
|
|
436
|
-
source: e.source,
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
onVisibleRangesChanged(listener) {
|
|
443
|
-
const disposer = new Disposable();
|
|
444
|
-
const monacoEditor = this.monacoEditor;
|
|
445
|
-
disposer.addDispose(
|
|
446
|
-
monacoEditor.onDidScrollChange((e) => {
|
|
447
|
-
listener(this.monacoEditor.getVisibleRanges());
|
|
448
|
-
}),
|
|
449
|
-
);
|
|
450
|
-
disposer.addDispose(
|
|
451
|
-
monacoEditor.onDidLayoutChange((e) => {
|
|
452
|
-
listener(this.monacoEditor.getVisibleRanges());
|
|
453
|
-
}),
|
|
454
|
-
);
|
|
455
|
-
return disposer;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
setSelections(selections) {
|
|
459
|
-
return this.monacoEditor.setSelections(selections as any);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
setSelection(selection) {
|
|
463
|
-
return this.monacoEditor.setSelection(selection as any);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
public async save(): Promise<void> {
|
|
467
|
-
if (this.currentDocumentModel) {
|
|
468
|
-
await this.currentDocumentModel.save();
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
onConfigurationChanged(listener) {
|
|
473
|
-
const monacoEditor = this.monacoEditor;
|
|
474
|
-
return monacoEditor.onDidChangeConfiguration((e) => {
|
|
475
|
-
listener();
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
248
|
@Injectable({ multiple: true })
|
|
481
249
|
export class BrowserCodeEditor extends BaseMonacoEditorWrapper implements ICodeEditor {
|
|
482
250
|
@Autowired(EditorCollectionService)
|
|
@@ -605,9 +373,6 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
|
|
|
605
373
|
@Autowired(EditorCollectionService)
|
|
606
374
|
private collectionService: EditorCollectionServiceImpl;
|
|
607
375
|
|
|
608
|
-
@Autowired(AppConfig)
|
|
609
|
-
private appConfig: AppConfig;
|
|
610
|
-
|
|
611
376
|
private originalDocModelRef: IEditorDocumentModelRef | null;
|
|
612
377
|
|
|
613
378
|
private modifiedDocModelRef: IEditorDocumentModelRef | null;
|
|
@@ -874,7 +639,6 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
|
|
|
874
639
|
}
|
|
875
640
|
|
|
876
641
|
// utils
|
|
877
|
-
|
|
878
642
|
function bindPreventNavigation(div: HTMLElement) {
|
|
879
643
|
div.addEventListener('mousewheel', preventNavigation as any);
|
|
880
644
|
}
|
|
@@ -890,18 +654,3 @@ function preventNavigation(this: HTMLDivElement, e: WheelEvent) {
|
|
|
890
654
|
e.stopPropagation();
|
|
891
655
|
}
|
|
892
656
|
}
|
|
893
|
-
|
|
894
|
-
@Injectable({ multiple: true })
|
|
895
|
-
export class DiffEditorPart extends BaseMonacoEditorWrapper implements IEditor {
|
|
896
|
-
get currentDocumentModel() {
|
|
897
|
-
return this.getDocumentModel();
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
constructor(
|
|
901
|
-
monacoEditor: IMonacoCodeEditor,
|
|
902
|
-
private getDocumentModel: () => IEditorDocumentModel | null,
|
|
903
|
-
type: EditorType,
|
|
904
|
-
) {
|
|
905
|
-
super(monacoEditor, type);
|
|
906
|
-
}
|
|
907
|
-
}
|