@opensumi/ide-editor 3.9.1-next-1749540423.0 → 3.9.1-next-1749546307.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 (44) hide show
  1. package/lib/browser/decoration-applier.d.ts +1 -1
  2. package/lib/browser/decoration-applier.d.ts.map +1 -1
  3. package/lib/browser/decoration-applier.js +4 -4
  4. package/lib/browser/decoration-applier.js.map +1 -1
  5. package/lib/browser/editor-collection.service.d.ts +57 -21
  6. package/lib/browser/editor-collection.service.d.ts.map +1 -1
  7. package/lib/browser/editor-collection.service.js +207 -56
  8. package/lib/browser/editor-collection.service.js.map +1 -1
  9. package/lib/browser/editor.contribution.d.ts.map +1 -1
  10. package/lib/browser/editor.contribution.js +0 -1
  11. package/lib/browser/editor.contribution.js.map +1 -1
  12. package/lib/browser/editor.less +0 -31
  13. package/lib/browser/editor.view.js +1 -1
  14. package/lib/browser/editor.view.js.map +1 -1
  15. package/lib/browser/multi-diff/multi-diff-editor.d.ts +7 -10
  16. package/lib/browser/multi-diff/multi-diff-editor.d.ts.map +1 -1
  17. package/lib/browser/multi-diff/multi-diff-editor.js +7 -62
  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/editor.d.ts +0 -11
  24. package/lib/common/editor.d.ts.map +1 -1
  25. package/lib/common/editor.js.map +1 -1
  26. package/lib/common/multi-diff.d.ts +1 -6
  27. package/lib/common/multi-diff.d.ts.map +1 -1
  28. package/lib/common/multi-diff.js.map +1 -1
  29. package/package.json +14 -14
  30. package/src/browser/decoration-applier.ts +8 -12
  31. package/src/browser/editor-collection.service.ts +264 -65
  32. package/src/browser/editor.contribution.ts +0 -2
  33. package/src/browser/editor.less +0 -31
  34. package/src/browser/editor.view.tsx +1 -1
  35. package/src/browser/multi-diff/multi-diff-editor.ts +10 -97
  36. package/src/browser/multi-diff/multi-diff-resource.ts +1 -0
  37. package/src/browser/workbench-editor.service.ts +1 -1
  38. package/src/common/editor.ts +0 -14
  39. package/src/common/multi-diff.ts +1 -8
  40. package/lib/browser/base-editor-wrapper.d.ts +0 -63
  41. package/lib/browser/base-editor-wrapper.d.ts.map +0 -1
  42. package/lib/browser/base-editor-wrapper.js +0 -224
  43. package/lib/browser/base-editor-wrapper.js.map +0 -1
  44. package/src/browser/base-editor-wrapper.ts +0 -279
@@ -1,279 +0,0 @@
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 { ISettableObservable } from '@opensumi/ide-monaco/lib/common/observable';
6
- import { RefCounted } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/widget/diffEditor/utils';
7
- import { IDocumentDiffItem } from '@opensumi/monaco-editor-core/esm/vs/editor/browser/widget/multiDiffEditor/model';
8
- import { IConfigurationService } from '@opensumi/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
9
-
10
- import { EditorType, IDecorationApplyOptions, IEditor, IUndoStopOptions } from '../common';
11
- import { IEditorDocumentModel } from '../common/editor';
12
-
13
- import { MonacoEditorDecorationApplier } from './decoration-applier';
14
- import { getConvertedMonacoOptions, isEditorOption } from './preference/converter';
15
- import { IEditorFeatureRegistry } from './types';
16
-
17
- import type { ICodeEditor as IMonacoCodeEditor } from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
18
-
19
- export type ISumiEditor = IEditor;
20
-
21
- export function insertSnippetWithMonacoEditor(
22
- editor: IMonacoCodeEditor,
23
- template: string,
24
- ranges: IRange[],
25
- opts: IUndoStopOptions,
26
- ) {
27
- const snippetController = editor.getContribution('snippetController2') as any;
28
- const selections: ISelection[] = ranges.map(
29
- (r) => new monaco.Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn),
30
- );
31
- editor.setSelections(selections);
32
- editor.focus();
33
-
34
- snippetController.insert(template, 0, 0, opts.undoStopBefore, opts.undoStopAfter);
35
- }
36
-
37
- const { removeUndefined } = objects;
38
-
39
- function updateOptionsWithMonacoEditor(
40
- monacoEditor: IMonacoCodeEditor,
41
- editorOptions: monaco.editor.IEditorOptions,
42
- modelOptions: monaco.editor.ITextModelUpdateOptions,
43
- ) {
44
- monacoEditor.updateOptions(editorOptions);
45
- if (monacoEditor.getModel()) {
46
- monacoEditor.getModel()!.updateOptions(modelOptions);
47
- }
48
- }
49
-
50
- @Injectable({ multiple: true })
51
- export abstract class BaseMonacoEditorWrapper extends WithEventBus implements IEditor {
52
- public abstract readonly currentDocumentModel: IEditorDocumentModel | null;
53
-
54
- public get currentUri(): URI | null {
55
- return this.currentDocumentModel ? this.currentDocumentModel.uri : null;
56
- }
57
-
58
- public getId() {
59
- return this.monacoEditor.getId();
60
- }
61
-
62
- getSelections() {
63
- return this.monacoEditor.getSelections() || [];
64
- }
65
-
66
- public onFocus = this.monacoEditor.onDidFocusEditorWidget;
67
-
68
- public onBlur = this.monacoEditor.onDidBlurEditorWidget;
69
-
70
- protected _specialEditorOptions: any = {};
71
-
72
- protected _specialModelOptions: monaco.editor.ITextModelUpdateOptions = {};
73
-
74
- protected _editorOptionsFromContribution: any = {};
75
-
76
- @Autowired(IEditorFeatureRegistry)
77
- protected readonly editorFeatureRegistry: IEditorFeatureRegistry;
78
-
79
- @Autowired(IConfigurationService)
80
- protected readonly configurationService: IConfigurationService;
81
-
82
- public readonly decorationApplier: MonacoEditorDecorationApplier;
83
-
84
- private _disableSelectionEmitter = false;
85
-
86
- protected disableSelectionEmitter() {
87
- this._disableSelectionEmitter = true;
88
- }
89
-
90
- protected enableSelectionEmitter() {
91
- this._disableSelectionEmitter = false;
92
- }
93
-
94
- @Autowired(INJECTOR_TOKEN)
95
- private injector: Injector;
96
-
97
- constructor(public readonly monacoEditor: IMonacoCodeEditor, private type: EditorType) {
98
- super();
99
- this.decorationApplier = this.injector.get(MonacoEditorDecorationApplier, [this.monacoEditor]);
100
- this.addDispose(this.monacoEditor.onDidChangeModel(this.onDidChangeModel.bind(this)));
101
- this.addDispose(
102
- this.monacoEditor.onDidChangeModelLanguage(() => {
103
- this._doUpdateOptions();
104
- }),
105
- );
106
- this.addDispose(
107
- this.configurationService.onDidChangeConfiguration((e) => {
108
- const changedEditorKeys = Array.from(e.affectedKeys.values()).filter((key) => isEditorOption(key));
109
- if (changedEditorKeys.length > 0) {
110
- this._doUpdateOptions();
111
- }
112
- }),
113
- );
114
- }
115
-
116
- private async onDidChangeModel() {
117
- this._editorOptionsFromContribution = {};
118
- const uri = this.currentUri;
119
- if (uri) {
120
- Promise.resolve(this.editorFeatureRegistry.runProvideEditorOptionsForUri(uri)).then((options) => {
121
- if (!this.currentUri || !uri.isEqual(this.currentUri)) {
122
- return; // uri可能已经变了
123
- }
124
-
125
- if (options && Object.keys(options).length > 0) {
126
- this._editorOptionsFromContribution = options;
127
- if (!isEmptyObject(this._editorOptionsFromContribution)) {
128
- this._doUpdateOptions();
129
- }
130
- }
131
- });
132
- }
133
- }
134
-
135
- public getType() {
136
- return this.type;
137
- }
138
-
139
- updateOptions(
140
- editorOptions: monaco.editor.IEditorOptions = {},
141
- modelOptions: monaco.editor.ITextModelUpdateOptions = {},
142
- ) {
143
- this._specialEditorOptions = removeUndefined({ ...this._specialEditorOptions, ...editorOptions });
144
- this._specialModelOptions = removeUndefined({ ...this._specialModelOptions, ...modelOptions });
145
- this._doUpdateOptions();
146
- }
147
-
148
- private _doUpdateOptions() {
149
- const { editorOptions, modelOptions } = this._calculateFinalOptions();
150
- updateOptionsWithMonacoEditor(this.monacoEditor, editorOptions, modelOptions);
151
- }
152
-
153
- /**
154
- * 合并所有的选项
155
- * 优先关系: (从高到底)
156
- * 1. 当前编辑器的特殊选项(通过调用 updateOptions或者启动时传入)
157
- * 2. 来自 featureRegistry 的根据 当前uri 提供的选项
158
- * 3. 来自偏好设置的选项
159
- */
160
- private _calculateFinalOptions() {
161
- const uriStr = this.currentUri ? this.currentUri.toString() : undefined;
162
- const languageId = this.currentDocumentModel ? this.currentDocumentModel.languageId : undefined;
163
- const options = getConvertedMonacoOptions(this.configurationService, uriStr, languageId, undefined);
164
- const basicEditorOptions: Partial<monaco.editor.IEditorOptions> = {
165
- readOnly: this.currentDocumentModel?.readonly || false,
166
- };
167
-
168
- let editorOptions = {
169
- ...basicEditorOptions,
170
- ...options.editorOptions,
171
- ...this._editorOptionsFromContribution,
172
- ...this._specialEditorOptions,
173
- };
174
-
175
- if (this.type !== EditorType.CODE) {
176
- editorOptions = {
177
- ...editorOptions,
178
- ...options.diffOptions,
179
- };
180
- }
181
-
182
- return {
183
- editorOptions,
184
- modelOptions: { ...options.modelOptions, ...this._specialModelOptions },
185
- };
186
- }
187
-
188
- insertSnippet(template: string, ranges: IRange[], opts: IUndoStopOptions) {
189
- insertSnippetWithMonacoEditor(this.monacoEditor, template, ranges, opts);
190
- }
191
-
192
- applyDecoration(key: string, options: IDecorationApplyOptions[]) {
193
- this.decorationApplier.applyDecoration(key, options);
194
- }
195
-
196
- onSelectionsChanged(listener) {
197
- return this.monacoEditor.onDidChangeCursorSelection((e) => {
198
- if (!this._disableSelectionEmitter) {
199
- listener({
200
- selections: this.getSelections(),
201
- source: e.source,
202
- });
203
- }
204
- });
205
- }
206
-
207
- onVisibleRangesChanged(listener) {
208
- const disposer = new Disposable();
209
- const monacoEditor = this.monacoEditor;
210
- disposer.addDispose(
211
- monacoEditor.onDidScrollChange((e) => {
212
- listener(this.monacoEditor.getVisibleRanges());
213
- }),
214
- );
215
- disposer.addDispose(
216
- monacoEditor.onDidLayoutChange((e) => {
217
- listener(this.monacoEditor.getVisibleRanges());
218
- }),
219
- );
220
- return disposer;
221
- }
222
-
223
- setSelections(selections) {
224
- return this.monacoEditor.setSelections(selections as any);
225
- }
226
-
227
- setSelection(selection) {
228
- return this.monacoEditor.setSelection(selection as any);
229
- }
230
-
231
- public async save(): Promise<void> {
232
- if (this.currentDocumentModel) {
233
- await this.currentDocumentModel.save();
234
- }
235
- }
236
-
237
- onConfigurationChanged(listener) {
238
- const monacoEditor = this.monacoEditor;
239
- return monacoEditor.onDidChangeConfiguration((e) => {
240
- listener();
241
- });
242
- }
243
- }
244
- @Injectable({ multiple: true })
245
- export class DiffEditorPart extends BaseMonacoEditorWrapper implements IEditor {
246
- get currentDocumentModel() {
247
- return this._getDocumentModel();
248
- }
249
-
250
- public updateDocumentModel(uri: URI) {
251
- const document = this.documents.get();
252
- if (document === 'loading') {
253
- return;
254
- }
255
- for (const item of document) {
256
- if (item.object.modified) {
257
- if (URI.from(item.object.modified.uri).isEqual(uri)) {
258
- this._getDocumentModel = () => (item.object as any).modifiedInstance;
259
- }
260
- }
261
- if (item.object.original) {
262
- if (URI.from(item.object.original.uri).isEqual(uri)) {
263
- this._getDocumentModel = () => (item.object as any).originalInstance;
264
- }
265
- }
266
- }
267
- this.decorationApplier.clearDecorations();
268
- this.decorationApplier.applyDecorationFromProvider();
269
- }
270
-
271
- constructor(
272
- monacoEditor: IMonacoCodeEditor,
273
- public _getDocumentModel: () => IEditorDocumentModel | null,
274
- type: EditorType,
275
- private documents: ISettableObservable<readonly RefCounted<IDocumentDiffItem>[] | 'loading', void>,
276
- ) {
277
- super(monacoEditor, type);
278
- }
279
- }