@opensumi/ide-editor 2.21.13 → 2.22.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/breadcrumb/default.js.map +1 -1
- package/lib/browser/breadcrumb/document-symbol.js.map +1 -1
- package/lib/browser/breadcrumb/index.js.map +1 -1
- package/lib/browser/component.js.map +1 -1
- package/lib/browser/decoration-applier.js.map +1 -1
- package/lib/browser/diff/compare.js.map +1 -1
- package/lib/browser/diff/index.d.ts.map +1 -1
- package/lib/browser/diff/index.js +1 -1
- package/lib/browser/diff/index.js.map +1 -1
- package/lib/browser/doc-cache/empty-doc-cache.js.map +1 -1
- package/lib/browser/doc-cache/local-storage-cache.js.map +1 -1
- package/lib/browser/doc-model/editor-document-model-service.js +3 -3
- package/lib/browser/doc-model/editor-document-model-service.js.map +1 -1
- package/lib/browser/doc-model/editor-document-model.d.ts +8 -0
- package/lib/browser/doc-model/editor-document-model.d.ts.map +1 -1
- package/lib/browser/doc-model/editor-document-model.js +61 -11
- package/lib/browser/doc-model/editor-document-model.js.map +1 -1
- package/lib/browser/doc-model/editor-document-registry.js.map +1 -1
- package/lib/browser/doc-model/override.js.map +1 -1
- package/lib/browser/doc-model/save-task.js +1 -1
- package/lib/browser/doc-model/save-task.js.map +1 -1
- package/lib/browser/doc-model/saveParticipants.d.ts +7 -7
- package/lib/browser/doc-model/saveParticipants.d.ts.map +1 -1
- package/lib/browser/doc-model/saveParticipants.js +69 -38
- package/lib/browser/doc-model/saveParticipants.js.map +1 -1
- package/lib/browser/doc-model/types.d.ts +1 -1
- package/lib/browser/doc-model/types.d.ts.map +1 -1
- package/lib/browser/editor-collection.service.d.ts +8 -3
- package/lib/browser/editor-collection.service.d.ts.map +1 -1
- package/lib/browser/editor-collection.service.js +75 -66
- package/lib/browser/editor-collection.service.js.map +1 -1
- package/lib/browser/editor-opener.js.map +1 -1
- package/lib/browser/editor.contribution.d.ts.map +1 -1
- package/lib/browser/editor.contribution.js +31 -3
- package/lib/browser/editor.contribution.js.map +1 -1
- package/lib/browser/editor.decoration.service.d.ts +5 -6
- package/lib/browser/editor.decoration.service.d.ts.map +1 -1
- package/lib/browser/editor.decoration.service.js +9 -1
- package/lib/browser/editor.decoration.service.js.map +1 -1
- package/lib/browser/editor.override.js +2 -2
- package/lib/browser/editor.override.js.map +1 -1
- package/lib/browser/editor.status-bar.service.js.map +1 -1
- package/lib/browser/editor.view.d.ts.map +1 -1
- package/lib/browser/editor.view.js +20 -23
- package/lib/browser/editor.view.js.map +1 -1
- package/lib/browser/error.d.ts +1 -1
- package/lib/browser/error.d.ts.map +1 -1
- package/lib/browser/feature.js.map +1 -1
- package/lib/browser/format/format.service.js.map +1 -1
- package/lib/browser/format/formatterSelect.js.map +1 -1
- package/lib/browser/fs-resource/file-tree-set.js +6 -6
- package/lib/browser/fs-resource/file-tree-set.js.map +1 -1
- package/lib/browser/fs-resource/fs-editor-doc.js +1 -1
- package/lib/browser/fs-resource/fs-editor-doc.js.map +1 -1
- package/lib/browser/fs-resource/fs-resource.js.map +1 -1
- package/lib/browser/fs-resource/index.js.map +1 -1
- package/lib/browser/history/index.d.ts.map +1 -1
- package/lib/browser/history/index.js +2 -1
- package/lib/browser/history/index.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +2 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/language/diagnostic-collection.d.ts +5 -5
- package/lib/browser/language/diagnostic-collection.d.ts.map +1 -1
- package/lib/browser/language/diagnostic-collection.js +1 -1
- package/lib/browser/language/diagnostic-collection.js.map +1 -1
- package/lib/browser/language/language-status.contribution.js.map +1 -1
- package/lib/browser/language/language-status.service.js.map +1 -1
- package/lib/browser/language/language.service.d.ts +4 -3
- package/lib/browser/language/language.service.d.ts.map +1 -1
- package/lib/browser/language/language.service.js +8 -2
- package/lib/browser/language/language.service.js.map +1 -1
- package/lib/browser/menu/editor.context.js +3 -3
- package/lib/browser/menu/editor.context.js.map +1 -1
- package/lib/browser/menu/editor.menu.d.ts +2 -2
- package/lib/browser/menu/editor.menu.d.ts.map +1 -1
- package/lib/browser/menu/editor.menu.js +6 -8
- package/lib/browser/menu/editor.menu.js.map +1 -1
- package/lib/browser/menu/open-type-menu.contribution.js +9 -9
- package/lib/browser/menu/open-type-menu.contribution.js.map +1 -1
- package/lib/browser/menu/title-context.menu.js.map +1 -1
- package/lib/browser/merge-editor/merge-editor.contribution.d.ts +8 -0
- package/lib/browser/merge-editor/merge-editor.contribution.d.ts.map +1 -0
- package/lib/browser/merge-editor/merge-editor.contribution.js +29 -0
- package/lib/browser/merge-editor/merge-editor.contribution.js.map +1 -0
- package/lib/browser/merge-editor/merge-editor.provider.d.ts +8 -0
- package/lib/browser/merge-editor/merge-editor.provider.d.ts.map +1 -0
- package/lib/browser/merge-editor/merge-editor.provider.js +44 -0
- package/lib/browser/merge-editor/merge-editor.provider.js.map +1 -0
- package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.js.map +1 -1
- package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.js +7 -7
- package/lib/browser/monaco-contrib/callHierarchy/callHierarchy.service.js.map +1 -1
- package/lib/browser/monaco-contrib/command/command.service.d.ts +1 -1
- package/lib/browser/monaco-contrib/command/command.service.d.ts.map +1 -1
- package/lib/browser/monaco-contrib/command/command.service.js.map +1 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate-registry.js.map +1 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.d.ts +2 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.d.ts.map +1 -1
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.js +5 -2
- package/lib/browser/monaco-contrib/tokenizer/textmate.service.js.map +1 -1
- package/lib/browser/monaco-contrib/typeHierarchy/typeHierarchy.contribution.js.map +1 -1
- package/lib/browser/monaco-contrib/typeHierarchy/typeHierarchy.service.js +7 -7
- package/lib/browser/monaco-contrib/typeHierarchy/typeHierarchy.service.js.map +1 -1
- package/lib/browser/navigation.module.less +1 -1
- package/lib/browser/navigation.view.d.ts.map +1 -1
- package/lib/browser/navigation.view.js +26 -15
- package/lib/browser/navigation.view.js.map +1 -1
- package/lib/browser/preference/contribution.js.map +1 -1
- package/lib/browser/preference/converter.d.ts +3 -3
- package/lib/browser/preference/converter.d.ts.map +1 -1
- package/lib/browser/preference/schema.d.ts +1 -1
- package/lib/browser/preference/schema.d.ts.map +1 -1
- package/lib/browser/preference/schema.js +8 -8
- package/lib/browser/preference/schema.js.map +1 -1
- package/lib/browser/quick-open/go-to-line.js.map +1 -1
- package/lib/browser/quick-open/workspace-symbol-quickopen.d.ts.map +1 -1
- package/lib/browser/quick-open/workspace-symbol-quickopen.js +2 -2
- package/lib/browser/quick-open/workspace-symbol-quickopen.js.map +1 -1
- package/lib/browser/resource.service.js.map +1 -1
- package/lib/browser/tab.view.d.ts +1 -1
- package/lib/browser/tab.view.d.ts.map +1 -1
- package/lib/browser/tab.view.js +2 -2
- package/lib/browser/tab.view.js.map +1 -1
- package/lib/browser/types.d.ts +5 -5
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/untitled-resource.js +1 -1
- package/lib/browser/untitled-resource.js.map +1 -1
- package/lib/browser/view/suggest-widget.js.map +1 -1
- package/lib/browser/workbench-editor.service.d.ts +17 -0
- package/lib/browser/workbench-editor.service.d.ts.map +1 -1
- package/lib/browser/workbench-editor.service.js +259 -176
- package/lib/browser/workbench-editor.service.js.map +1 -1
- package/lib/common/doc-cache.d.ts +2 -2
- package/lib/common/doc-cache.d.ts.map +1 -1
- package/lib/common/editor.d.ts +20 -6
- package/lib/common/editor.d.ts.map +1 -1
- package/lib/common/editor.js +12 -1
- package/lib/common/editor.js.map +1 -1
- package/lib/common/language.d.ts +18 -7
- package/lib/common/language.d.ts.map +1 -1
- package/lib/common/language.js +15 -7
- package/lib/common/language.js.map +1 -1
- package/lib/common/mocks/workbench-editor.service.js.map +1 -1
- package/lib/common/resource.d.ts +8 -2
- package/lib/common/resource.d.ts.map +1 -1
- package/lib/common/resource.js +1 -0
- package/lib/common/resource.js.map +1 -1
- package/package.json +17 -16
- package/src/browser/breadcrumb/default.ts +299 -0
- package/src/browser/breadcrumb/document-symbol.ts +187 -0
- package/src/browser/breadcrumb/index.ts +96 -0
- package/src/browser/component.ts +204 -0
- package/src/browser/decoration-applier.ts +256 -0
- package/src/browser/diff/compare.ts +99 -0
- package/src/browser/diff/index.ts +81 -0
- package/src/browser/doc-cache/empty-doc-cache.ts +26 -0
- package/src/browser/doc-cache/index.ts +2 -0
- package/src/browser/doc-cache/local-storage-cache.ts +67 -0
- package/src/browser/doc-model/editor-document-error.ts +10 -0
- package/src/browser/doc-model/editor-document-model-service.ts +346 -0
- package/src/browser/doc-model/editor-document-model.ts +690 -0
- package/src/browser/doc-model/editor-document-registry.ts +119 -0
- package/src/browser/doc-model/editor-is-fn.ts +9 -0
- package/src/browser/doc-model/main.ts +4 -0
- package/src/browser/doc-model/override.ts +49 -0
- package/src/browser/doc-model/save-task.ts +88 -0
- package/src/browser/doc-model/saveParticipants.ts +227 -0
- package/src/browser/doc-model/types.ts +350 -0
- package/src/browser/editor-collection.service.ts +790 -0
- package/src/browser/editor-opener.ts +44 -0
- package/src/browser/editor.contribution.ts +1438 -0
- package/src/browser/editor.decoration.service.ts +247 -0
- package/src/browser/editor.less +4 -0
- package/src/browser/editor.module.less +548 -0
- package/src/browser/editor.override.ts +133 -0
- package/src/browser/editor.status-bar.service.ts +116 -0
- package/src/browser/editor.view.tsx +623 -0
- package/src/browser/error.ts +21 -0
- package/src/browser/feature.ts +63 -0
- package/src/browser/format/format.service.ts +95 -0
- package/src/browser/format/formatterSelect.ts +82 -0
- package/src/browser/fs-resource/file-tree-set.ts +126 -0
- package/src/browser/fs-resource/fs-editor-doc.ts +213 -0
- package/src/browser/fs-resource/fs-resource.ts +247 -0
- package/src/browser/fs-resource/index.ts +27 -0
- package/src/browser/grid/grid.service.ts +288 -0
- package/src/browser/history/index.ts +228 -0
- package/src/browser/index.ts +236 -0
- package/src/browser/language/diagnostic-collection.ts +83 -0
- package/src/browser/language/language-status.contribution.ts +81 -0
- package/src/browser/language/language-status.service.ts +32 -0
- package/src/browser/language/language.service.ts +185 -0
- package/src/browser/menu/editor.context.ts +186 -0
- package/src/browser/menu/editor.menu.ts +45 -0
- package/src/browser/menu/open-type-menu.contribution.ts +90 -0
- package/src/browser/menu/title-context.menu.ts +54 -0
- package/src/browser/merge-editor/merge-editor.contribution.ts +25 -0
- package/src/browser/merge-editor/merge-editor.provider.ts +36 -0
- package/src/browser/monaco-contrib/callHierarchy/callHierarchy.contribution.ts +78 -0
- package/src/browser/monaco-contrib/callHierarchy/callHierarchy.service.ts +160 -0
- package/src/browser/monaco-contrib/command/command.service.ts +438 -0
- package/src/browser/monaco-contrib/index.ts +4 -0
- package/src/browser/monaco-contrib/tokenizer/textmate-registry.ts +107 -0
- package/src/browser/monaco-contrib/tokenizer/textmate-tokenizer.ts +104 -0
- package/src/browser/monaco-contrib/tokenizer/textmate.service.ts +925 -0
- package/src/browser/monaco-contrib/typeHierarchy/typeHierarchy.contribution.ts +78 -0
- package/src/browser/monaco-contrib/typeHierarchy/typeHierarchy.service.ts +154 -0
- package/src/browser/navigation.module.less +96 -0
- package/src/browser/navigation.view.tsx +254 -0
- package/src/browser/preference/contribution.ts +8 -0
- package/src/browser/preference/converter.ts +793 -0
- package/src/browser/preference/schema.ts +1896 -0
- package/src/browser/preference/util.ts +14 -0
- package/src/browser/quick-open/go-to-line.ts +164 -0
- package/src/browser/quick-open/workspace-symbol-quickopen.ts +276 -0
- package/src/browser/resource.service.ts +263 -0
- package/src/browser/tab.view.tsx +514 -0
- package/src/browser/types.ts +467 -0
- package/src/browser/untitled-resource.ts +223 -0
- package/src/browser/view/editor.react.tsx +82 -0
- package/src/browser/view/react-hook.tsx +7 -0
- package/src/browser/view/suggest-widget.ts +77 -0
- package/src/browser/view/topPadding.ts +18 -0
- package/src/browser/workbench-editor.service.ts +2291 -0
- package/src/common/doc-cache.ts +117 -0
- package/src/common/editor.ts +799 -0
- package/src/common/index.ts +6 -0
- package/src/common/language-status.ts +33 -0
- package/src/common/language.ts +206 -0
- package/src/common/mocks/workbench-editor.service.ts +52 -0
- package/src/common/resource.ts +147 -0
- package/src/common/utils.ts +10 -0
- package/src/index.ts +1 -0
- package/lib/browser/component/scroll/scroll.d.ts +0 -2
- package/lib/browser/component/scroll/scroll.d.ts.map +0 -1
- package/lib/browser/component/scroll/scroll.js +0 -5
- package/lib/browser/component/scroll/scroll.js.map +0 -1
- package/lib/browser/component/scroll/scroll.module.less +0 -86
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
|
|
2
|
+
import { IRange, IContextKeyService } from '@opensumi/ide-core-browser';
|
|
3
|
+
import { ResourceContextKey } from '@opensumi/ide-core-browser/lib/contextkey';
|
|
4
|
+
import { MonacoService } from '@opensumi/ide-core-browser/lib/monaco';
|
|
5
|
+
import {
|
|
6
|
+
ILineChange,
|
|
7
|
+
URI,
|
|
8
|
+
WithEventBus,
|
|
9
|
+
OnEvent,
|
|
10
|
+
Emitter as EventEmitter,
|
|
11
|
+
ISelection,
|
|
12
|
+
Disposable,
|
|
13
|
+
objects,
|
|
14
|
+
isEmptyObject,
|
|
15
|
+
} from '@opensumi/ide-core-common';
|
|
16
|
+
import { Emitter } from '@opensumi/ide-core-common';
|
|
17
|
+
import type {
|
|
18
|
+
ICodeEditor as IMonacoCodeEditor,
|
|
19
|
+
IDiffEditor as IMonacoDiffEditor,
|
|
20
|
+
} from '@opensumi/ide-monaco/lib/browser/monaco-api/types';
|
|
21
|
+
import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';
|
|
22
|
+
import { IConfigurationService } from '@opensumi/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
ICodeEditor,
|
|
26
|
+
IEditor,
|
|
27
|
+
EditorCollectionService,
|
|
28
|
+
IDiffEditor,
|
|
29
|
+
ResourceDecorationNeedChangeEvent,
|
|
30
|
+
CursorStatus,
|
|
31
|
+
IUndoStopOptions,
|
|
32
|
+
IDecorationApplyOptions,
|
|
33
|
+
EditorType,
|
|
34
|
+
IResourceOpenOptions,
|
|
35
|
+
} from '../common';
|
|
36
|
+
|
|
37
|
+
import { MonacoEditorDecorationApplier } from './decoration-applier';
|
|
38
|
+
import {
|
|
39
|
+
IEditorDocumentModelRef,
|
|
40
|
+
EditorDocumentModelContentChangedEvent,
|
|
41
|
+
IEditorDocumentModelService,
|
|
42
|
+
IEditorDocumentModel,
|
|
43
|
+
} from './doc-model/types';
|
|
44
|
+
import { EditorFeatureRegistryImpl } from './feature';
|
|
45
|
+
import { getConvertedMonacoOptions, isEditorOption, isDiffEditorOption } from './preference/converter';
|
|
46
|
+
import { IEditorFeatureRegistry } from './types';
|
|
47
|
+
|
|
48
|
+
const { removeUndefined } = objects;
|
|
49
|
+
|
|
50
|
+
@Injectable()
|
|
51
|
+
export class EditorCollectionServiceImpl extends WithEventBus implements EditorCollectionService {
|
|
52
|
+
@Autowired()
|
|
53
|
+
protected readonly monacoService: MonacoService;
|
|
54
|
+
|
|
55
|
+
@Autowired(INJECTOR_TOKEN)
|
|
56
|
+
protected readonly injector: Injector;
|
|
57
|
+
|
|
58
|
+
@Autowired(IConfigurationService)
|
|
59
|
+
protected readonly configurationService: IConfigurationService;
|
|
60
|
+
|
|
61
|
+
@Autowired(IEditorFeatureRegistry)
|
|
62
|
+
protected readonly editorFeatureRegistry: EditorFeatureRegistryImpl;
|
|
63
|
+
|
|
64
|
+
private _editors: Set<IMonacoImplEditor> = new Set();
|
|
65
|
+
private _diffEditors: Set<IDiffEditor> = new Set();
|
|
66
|
+
|
|
67
|
+
private _onCodeEditorCreate = new Emitter<ICodeEditor>();
|
|
68
|
+
private _onDiffEditorCreate = new Emitter<IDiffEditor>();
|
|
69
|
+
|
|
70
|
+
public onCodeEditorCreate = this._onCodeEditorCreate.event;
|
|
71
|
+
public onDiffEditorCreate = this._onDiffEditorCreate.event;
|
|
72
|
+
|
|
73
|
+
@Autowired(IEditorDocumentModelService)
|
|
74
|
+
documentModelService: IEditorDocumentModelService;
|
|
75
|
+
|
|
76
|
+
private _currentEditor: IEditor | undefined;
|
|
77
|
+
|
|
78
|
+
get currentEditor() {
|
|
79
|
+
return this._currentEditor;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
constructor() {
|
|
83
|
+
super();
|
|
84
|
+
this.addDispose(
|
|
85
|
+
this.editorFeatureRegistry.onDidRegisterFeature((contribution) => {
|
|
86
|
+
this._editors.forEach((editor) => {
|
|
87
|
+
this.editorFeatureRegistry.runOneContribution(editor, contribution);
|
|
88
|
+
});
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
createCodeEditor(dom: HTMLElement, options?: any, overrides?: { [key: string]: any }): ICodeEditor {
|
|
94
|
+
const mergedOptions = { ...getConvertedMonacoOptions(this.configurationService).editorOptions, ...options };
|
|
95
|
+
const monacoCodeEditor = this.monacoService.createCodeEditor(dom, mergedOptions, overrides);
|
|
96
|
+
const editor = this.injector.get(BrowserCodeEditor, [monacoCodeEditor, options]);
|
|
97
|
+
|
|
98
|
+
this._onCodeEditorCreate.fire(editor);
|
|
99
|
+
return editor;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public listEditors(): IMonacoImplEditor[] {
|
|
103
|
+
return Array.from(this._editors.values());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public addEditors(editors: IMonacoImplEditor[]) {
|
|
107
|
+
const beforeSize = this._editors.size;
|
|
108
|
+
editors.forEach((editor) => {
|
|
109
|
+
if (!this._editors.has(editor)) {
|
|
110
|
+
this._editors.add(editor);
|
|
111
|
+
this.editorFeatureRegistry.runContributions(editor);
|
|
112
|
+
editor.monacoEditor.onDidFocusEditorWidget(() => {
|
|
113
|
+
this._currentEditor = editor;
|
|
114
|
+
});
|
|
115
|
+
editor.monacoEditor.onContextMenu(() => {
|
|
116
|
+
this._currentEditor = editor;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (this._editors.size !== beforeSize) {
|
|
121
|
+
// fire event;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public removeEditors(editors: IMonacoImplEditor[]) {
|
|
126
|
+
const beforeSize = this._editors.size;
|
|
127
|
+
editors.forEach((editor) => {
|
|
128
|
+
this._editors.delete(editor);
|
|
129
|
+
if (this._currentEditor === editor) {
|
|
130
|
+
this._currentEditor = undefined;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
if (this._editors.size !== beforeSize) {
|
|
134
|
+
// fire event;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public createDiffEditor(dom: HTMLElement, options?: any, overrides?: { [key: string]: any }): IDiffEditor {
|
|
139
|
+
const preferenceOptions = getConvertedMonacoOptions(this.configurationService);
|
|
140
|
+
const mergedOptions = { ...preferenceOptions.editorOptions, ...preferenceOptions.diffOptions, ...options };
|
|
141
|
+
const monacoDiffEditor = this.monacoService.createDiffEditor(dom, mergedOptions, overrides);
|
|
142
|
+
const editor = this.injector.get(BrowserDiffEditor, [monacoDiffEditor, options]);
|
|
143
|
+
this._onDiffEditorCreate.fire(editor);
|
|
144
|
+
return editor;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public createMergeEditor(dom: HTMLElement, options?: any, overrides?: { [key: string]: any }) {
|
|
148
|
+
const preferenceOptions = getConvertedMonacoOptions(this.configurationService);
|
|
149
|
+
const mergedOptions = { ...preferenceOptions.editorOptions, ...preferenceOptions.diffOptions, ...options };
|
|
150
|
+
const editor = this.monacoService.createMergeEditor(dom, mergedOptions, overrides);
|
|
151
|
+
return editor;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public listDiffEditors(): IDiffEditor[] {
|
|
155
|
+
return Array.from(this._diffEditors.values());
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public addDiffEditors(diffEditors: IDiffEditor[]) {
|
|
159
|
+
const beforeSize = this._diffEditors.size;
|
|
160
|
+
diffEditors.forEach((diffEditor) => {
|
|
161
|
+
if (!this._diffEditors.has(diffEditor)) {
|
|
162
|
+
this._diffEditors.add(diffEditor);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
if (this._diffEditors.size !== beforeSize) {
|
|
166
|
+
// fire event _onDiffEditorAdd;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public removeDiffEditors(diffEditors: IDiffEditor[]) {
|
|
171
|
+
const beforeSize = this._diffEditors.size;
|
|
172
|
+
diffEditors.forEach((diffEditor) => {
|
|
173
|
+
this._diffEditors.delete(diffEditor);
|
|
174
|
+
});
|
|
175
|
+
if (this._diffEditors.size !== beforeSize) {
|
|
176
|
+
// fire event _onDiffEditorRemove;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 将docModel的变更事件反映至resource的dirty装饰
|
|
181
|
+
@OnEvent(EditorDocumentModelContentChangedEvent)
|
|
182
|
+
onDocModelContentChangedEvent(e: EditorDocumentModelContentChangedEvent) {
|
|
183
|
+
this.eventBus.fire(
|
|
184
|
+
new ResourceDecorationNeedChangeEvent({
|
|
185
|
+
uri: e.payload.uri,
|
|
186
|
+
decoration: {
|
|
187
|
+
dirty: !!e.payload.dirty,
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type IMonacoImplEditor = IEditor;
|
|
195
|
+
|
|
196
|
+
export function insertSnippetWithMonacoEditor(
|
|
197
|
+
editor: IMonacoCodeEditor,
|
|
198
|
+
template: string,
|
|
199
|
+
ranges: IRange[],
|
|
200
|
+
opts: IUndoStopOptions,
|
|
201
|
+
) {
|
|
202
|
+
const snippetController = editor.getContribution('snippetController2') as any;
|
|
203
|
+
const selections: ISelection[] = ranges.map(
|
|
204
|
+
(r) => new monaco.Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn),
|
|
205
|
+
);
|
|
206
|
+
editor.setSelections(selections);
|
|
207
|
+
editor.focus();
|
|
208
|
+
|
|
209
|
+
snippetController.insert(template, 0, 0, opts.undoStopBefore, opts.undoStopAfter);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function updateOptionsWithMonacoEditor(
|
|
213
|
+
monacoEditor: IMonacoCodeEditor,
|
|
214
|
+
editorOptions: monaco.editor.IEditorOptions,
|
|
215
|
+
modelOptions: monaco.editor.ITextModelUpdateOptions,
|
|
216
|
+
) {
|
|
217
|
+
monacoEditor.updateOptions(editorOptions);
|
|
218
|
+
if (monacoEditor.getModel()) {
|
|
219
|
+
monacoEditor.getModel()!.updateOptions(modelOptions);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@Injectable({ multiple: true })
|
|
224
|
+
export abstract class BaseMonacoEditorWrapper extends Disposable implements IEditor {
|
|
225
|
+
public abstract readonly currentDocumentModel: IEditorDocumentModel | null;
|
|
226
|
+
|
|
227
|
+
public get currentUri(): URI | null {
|
|
228
|
+
return this.currentDocumentModel ? this.currentDocumentModel.uri : null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public getId() {
|
|
232
|
+
return this.monacoEditor.getId();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
getSelections() {
|
|
236
|
+
return this.monacoEditor.getSelections() || [];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public onFocus = this.monacoEditor.onDidFocusEditorWidget;
|
|
240
|
+
|
|
241
|
+
public onBlur = this.monacoEditor.onDidBlurEditorWidget;
|
|
242
|
+
|
|
243
|
+
protected _specialEditorOptions: any = {};
|
|
244
|
+
|
|
245
|
+
protected _specialModelOptions: monaco.editor.ITextModelUpdateOptions = {};
|
|
246
|
+
|
|
247
|
+
protected _editorOptionsFromContribution: any = {};
|
|
248
|
+
|
|
249
|
+
@Autowired(IEditorFeatureRegistry)
|
|
250
|
+
protected readonly editorFeatureRegistry: IEditorFeatureRegistry;
|
|
251
|
+
|
|
252
|
+
@Autowired(IConfigurationService)
|
|
253
|
+
protected readonly configurationService: IConfigurationService;
|
|
254
|
+
|
|
255
|
+
protected readonly decorationApplier: MonacoEditorDecorationApplier;
|
|
256
|
+
|
|
257
|
+
private _disableSelectionEmitter = false;
|
|
258
|
+
|
|
259
|
+
protected disableSelectionEmitter() {
|
|
260
|
+
this._disableSelectionEmitter = true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
protected enableSelectionEmitter() {
|
|
264
|
+
this._disableSelectionEmitter = false;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@Autowired(INJECTOR_TOKEN)
|
|
268
|
+
private injector: Injector;
|
|
269
|
+
|
|
270
|
+
constructor(public readonly monacoEditor: IMonacoCodeEditor, private type: EditorType) {
|
|
271
|
+
super();
|
|
272
|
+
this.decorationApplier = this.injector.get(MonacoEditorDecorationApplier, [this.monacoEditor]);
|
|
273
|
+
this.addDispose(this.monacoEditor.onDidChangeModel(this.onDidChangeModel.bind(this)));
|
|
274
|
+
this.addDispose(
|
|
275
|
+
this.monacoEditor.onDidChangeModelLanguage(() => {
|
|
276
|
+
this._doUpdateOptions();
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
this.addDispose(
|
|
280
|
+
this.configurationService.onDidChangeConfiguration((e) => {
|
|
281
|
+
const changedEditorKeys = e.affectedKeys.filter((key) => isEditorOption(key));
|
|
282
|
+
if (changedEditorKeys.length > 0) {
|
|
283
|
+
this._doUpdateOptions();
|
|
284
|
+
}
|
|
285
|
+
}),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private async onDidChangeModel() {
|
|
290
|
+
this._editorOptionsFromContribution = {};
|
|
291
|
+
const uri = this.currentUri;
|
|
292
|
+
if (uri) {
|
|
293
|
+
Promise.resolve(this.editorFeatureRegistry.runProvideEditorOptionsForUri(uri)).then((options) => {
|
|
294
|
+
if (!this.currentUri || !uri.isEqual(this.currentUri)) {
|
|
295
|
+
return; // uri可能已经变了
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (options && Object.keys(options).length > 0) {
|
|
299
|
+
this._editorOptionsFromContribution = options;
|
|
300
|
+
if (!isEmptyObject(this._editorOptionsFromContribution)) {
|
|
301
|
+
this._doUpdateOptions();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public getType() {
|
|
309
|
+
return this.type;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
updateOptions(
|
|
313
|
+
editorOptions: monaco.editor.IEditorOptions = {},
|
|
314
|
+
modelOptions: monaco.editor.ITextModelUpdateOptions = {},
|
|
315
|
+
) {
|
|
316
|
+
this._specialEditorOptions = removeUndefined({ ...this._specialEditorOptions, ...editorOptions });
|
|
317
|
+
this._specialModelOptions = removeUndefined({ ...this._specialModelOptions, ...modelOptions });
|
|
318
|
+
this._doUpdateOptions();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private _doUpdateOptions() {
|
|
322
|
+
const { editorOptions, modelOptions } = this._calculateFinalOptions();
|
|
323
|
+
updateOptionsWithMonacoEditor(this.monacoEditor, editorOptions, modelOptions);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* 合并所有的选项
|
|
328
|
+
* 优先关系: (从高到底)
|
|
329
|
+
* 1. 当前编辑器的特殊选项(通过调用 updateOptions或者启动时传入)
|
|
330
|
+
* 2. 来自 featureRegistry 的根据 当前uri 提供的选项
|
|
331
|
+
* 3. 来自偏好设置的选项
|
|
332
|
+
*/
|
|
333
|
+
private _calculateFinalOptions() {
|
|
334
|
+
const uriStr = this.currentUri ? this.currentUri.toString() : undefined;
|
|
335
|
+
const languageId = this.currentDocumentModel ? this.currentDocumentModel.languageId : undefined;
|
|
336
|
+
const options = getConvertedMonacoOptions(this.configurationService, uriStr, languageId, undefined);
|
|
337
|
+
const basicEditorOptions: Partial<monaco.editor.IEditorOptions> = {
|
|
338
|
+
readOnly: this.currentDocumentModel?.readonly || false,
|
|
339
|
+
};
|
|
340
|
+
return {
|
|
341
|
+
editorOptions: {
|
|
342
|
+
...basicEditorOptions,
|
|
343
|
+
...options.editorOptions,
|
|
344
|
+
...this._editorOptionsFromContribution,
|
|
345
|
+
...this._specialEditorOptions,
|
|
346
|
+
},
|
|
347
|
+
modelOptions: { ...options.modelOptions, ...this._specialModelOptions },
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
insertSnippet(template: string, ranges: IRange[], opts: IUndoStopOptions) {
|
|
352
|
+
insertSnippetWithMonacoEditor(this.monacoEditor, template, ranges, opts);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
applyDecoration(key: string, options: IDecorationApplyOptions[]) {
|
|
356
|
+
this.decorationApplier.applyDecoration(key, options);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
onSelectionsChanged(listener) {
|
|
360
|
+
return this.monacoEditor.onDidChangeCursorSelection((e) => {
|
|
361
|
+
if (!this._disableSelectionEmitter) {
|
|
362
|
+
listener({
|
|
363
|
+
selections: this.getSelections(),
|
|
364
|
+
source: e.source,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
onVisibleRangesChanged(listener) {
|
|
371
|
+
const disposer = new Disposable();
|
|
372
|
+
const monacoEditor = this.monacoEditor;
|
|
373
|
+
disposer.addDispose(
|
|
374
|
+
monacoEditor.onDidScrollChange((e) => {
|
|
375
|
+
listener(this.monacoEditor.getVisibleRanges());
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
378
|
+
disposer.addDispose(
|
|
379
|
+
monacoEditor.onDidLayoutChange((e) => {
|
|
380
|
+
listener(this.monacoEditor.getVisibleRanges());
|
|
381
|
+
}),
|
|
382
|
+
);
|
|
383
|
+
return disposer;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
setSelections(selections) {
|
|
387
|
+
return this.monacoEditor.setSelections(selections as any);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
setSelection(selection) {
|
|
391
|
+
return this.monacoEditor.setSelection(selection as any);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
public async save(): Promise<void> {
|
|
395
|
+
if (this.currentDocumentModel) {
|
|
396
|
+
await this.currentDocumentModel.save();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
onConfigurationChanged(listener) {
|
|
401
|
+
const monacoEditor = this.monacoEditor;
|
|
402
|
+
return monacoEditor.onDidChangeConfiguration((e) => {
|
|
403
|
+
listener();
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export class BrowserCodeEditor extends BaseMonacoEditorWrapper implements ICodeEditor {
|
|
409
|
+
@Autowired(EditorCollectionService)
|
|
410
|
+
private collectionService: EditorCollectionServiceImpl;
|
|
411
|
+
|
|
412
|
+
@Autowired(IEditorFeatureRegistry)
|
|
413
|
+
protected readonly editorFeatureRegistry: IEditorFeatureRegistry;
|
|
414
|
+
|
|
415
|
+
private editorState: Map<string, monaco.editor.ICodeEditorViewState> = new Map();
|
|
416
|
+
|
|
417
|
+
private readonly toDispose: monaco.IDisposable[] = [];
|
|
418
|
+
|
|
419
|
+
protected _currentDocumentModelRef: IEditorDocumentModelRef;
|
|
420
|
+
|
|
421
|
+
private _onCursorPositionChanged = new EventEmitter<CursorStatus>();
|
|
422
|
+
public onCursorPositionChanged = this._onCursorPositionChanged.event;
|
|
423
|
+
|
|
424
|
+
public _disposed = false;
|
|
425
|
+
|
|
426
|
+
private _onRefOpen = new Emitter<IEditorDocumentModelRef>();
|
|
427
|
+
|
|
428
|
+
public onRefOpen = this._onRefOpen.event;
|
|
429
|
+
|
|
430
|
+
public get currentDocumentModel() {
|
|
431
|
+
if (this._currentDocumentModelRef && !this._currentDocumentModelRef.disposed) {
|
|
432
|
+
return this._currentDocumentModelRef.instance;
|
|
433
|
+
} else {
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
getType() {
|
|
439
|
+
return EditorType.CODE;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
constructor(public readonly monacoEditor: IMonacoCodeEditor, options: any = {}) {
|
|
443
|
+
super(monacoEditor, EditorType.CODE);
|
|
444
|
+
this._specialEditorOptions = options;
|
|
445
|
+
this.collectionService.addEditors([this]);
|
|
446
|
+
// 防止浏览器后退前进手势
|
|
447
|
+
const disposer = monacoEditor.onDidChangeModel(() => {
|
|
448
|
+
bindPreventNavigation(this.monacoEditor.getDomNode()!);
|
|
449
|
+
disposer.dispose();
|
|
450
|
+
});
|
|
451
|
+
this.toDispose.push(
|
|
452
|
+
monacoEditor.onDidChangeCursorPosition(() => {
|
|
453
|
+
if (!this.currentDocumentModel) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
const selection = monacoEditor.getSelection();
|
|
457
|
+
this._onCursorPositionChanged.fire({
|
|
458
|
+
position: monacoEditor.getPosition(),
|
|
459
|
+
selectionLength: selection ? this.currentDocumentModel.getMonacoModel().getValueInRange(selection).length : 0,
|
|
460
|
+
});
|
|
461
|
+
}),
|
|
462
|
+
);
|
|
463
|
+
this.addDispose({
|
|
464
|
+
dispose: () => {
|
|
465
|
+
this.monacoEditor.dispose();
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
layout(): void {
|
|
471
|
+
this.monacoEditor.layout();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
focus(): void {
|
|
475
|
+
this.monacoEditor.focus();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
dispose() {
|
|
479
|
+
super.dispose();
|
|
480
|
+
this.saveCurrentState();
|
|
481
|
+
this.collectionService.removeEditors([this]);
|
|
482
|
+
this._disposed = true;
|
|
483
|
+
this.toDispose.forEach((disposable) => disposable.dispose());
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
protected saveCurrentState() {
|
|
487
|
+
if (this.currentUri) {
|
|
488
|
+
const state = this.monacoEditor.saveViewState();
|
|
489
|
+
if (state) {
|
|
490
|
+
this.editorState.set(this.currentUri.toString(), state);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
protected restoreState() {
|
|
496
|
+
if (this.currentUri) {
|
|
497
|
+
const state = this.editorState.get(this.currentUri.toString());
|
|
498
|
+
if (state) {
|
|
499
|
+
this.monacoEditor.restoreViewState(state);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
open(documentModelRef: IEditorDocumentModelRef): void {
|
|
505
|
+
this.saveCurrentState();
|
|
506
|
+
this._currentDocumentModelRef = documentModelRef;
|
|
507
|
+
const model = this.currentDocumentModel!.getMonacoModel();
|
|
508
|
+
|
|
509
|
+
this.disableSelectionEmitter();
|
|
510
|
+
this.monacoEditor.setModel(model);
|
|
511
|
+
this.enableSelectionEmitter();
|
|
512
|
+
this.restoreState();
|
|
513
|
+
|
|
514
|
+
this._onRefOpen.fire(documentModelRef);
|
|
515
|
+
// monaco 在文件首次打开时不会触发 cursorChange
|
|
516
|
+
this._onCursorPositionChanged.fire({
|
|
517
|
+
position: this.monacoEditor.getPosition(),
|
|
518
|
+
selectionLength: 0,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export class BrowserDiffEditor extends Disposable implements IDiffEditor {
|
|
524
|
+
@Autowired(EditorCollectionService)
|
|
525
|
+
private collectionService: EditorCollectionServiceImpl;
|
|
526
|
+
|
|
527
|
+
private originalDocModelRef: IEditorDocumentModelRef | null;
|
|
528
|
+
|
|
529
|
+
private modifiedDocModelRef: IEditorDocumentModelRef | null;
|
|
530
|
+
|
|
531
|
+
get originalDocModel() {
|
|
532
|
+
if (this.originalDocModelRef && !this.originalDocModelRef.disposed) {
|
|
533
|
+
return this.originalDocModelRef.instance;
|
|
534
|
+
}
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
get modifiedDocModel() {
|
|
539
|
+
if (this.modifiedDocModelRef && !this.modifiedDocModelRef.disposed) {
|
|
540
|
+
return this.modifiedDocModelRef.instance;
|
|
541
|
+
}
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
public originalEditor: IMonacoImplEditor;
|
|
546
|
+
|
|
547
|
+
public modifiedEditor: IMonacoImplEditor;
|
|
548
|
+
|
|
549
|
+
public _disposed: boolean;
|
|
550
|
+
|
|
551
|
+
@Autowired(INJECTOR_TOKEN)
|
|
552
|
+
protected readonly injector: Injector;
|
|
553
|
+
|
|
554
|
+
@Autowired(IConfigurationService)
|
|
555
|
+
protected readonly configurationService: IConfigurationService;
|
|
556
|
+
|
|
557
|
+
@Autowired(IContextKeyService)
|
|
558
|
+
protected readonly contextKeyService: IContextKeyService;
|
|
559
|
+
|
|
560
|
+
private editorState: Map<string, monaco.editor.IDiffEditorViewState> = new Map();
|
|
561
|
+
|
|
562
|
+
private currentUri: URI | undefined;
|
|
563
|
+
|
|
564
|
+
private diffResourceKeys: ResourceContextKey[];
|
|
565
|
+
|
|
566
|
+
protected saveCurrentState() {
|
|
567
|
+
if (this.currentUri) {
|
|
568
|
+
const state = this.monacoDiffEditor.saveViewState();
|
|
569
|
+
if (state) {
|
|
570
|
+
this.editorState.set(this.currentUri.toString(), state);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
protected restoreState() {
|
|
576
|
+
if (this.currentUri) {
|
|
577
|
+
const state = this.editorState.get(this.currentUri.toString());
|
|
578
|
+
if (state) {
|
|
579
|
+
this.monacoDiffEditor.restoreViewState(state);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
constructor(public readonly monacoDiffEditor: IMonacoDiffEditor, private specialOptions: any = {}) {
|
|
585
|
+
super();
|
|
586
|
+
this.wrapEditors();
|
|
587
|
+
this.addDispose(
|
|
588
|
+
this.configurationService.onDidChangeConfiguration((e) => {
|
|
589
|
+
const changedEditorKeys = e.affectedKeys.filter((key) => isDiffEditorOption(key));
|
|
590
|
+
if (changedEditorKeys.length > 0) {
|
|
591
|
+
this.doUpdateDiffOptions();
|
|
592
|
+
}
|
|
593
|
+
}),
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
async compare(
|
|
598
|
+
originalDocModelRef: IEditorDocumentModelRef,
|
|
599
|
+
modifiedDocModelRef: IEditorDocumentModelRef,
|
|
600
|
+
options: IResourceOpenOptions = {},
|
|
601
|
+
rawUri?: URI,
|
|
602
|
+
) {
|
|
603
|
+
this.saveCurrentState(); // 保存上一个状态
|
|
604
|
+
this.originalDocModelRef = originalDocModelRef;
|
|
605
|
+
this.modifiedDocModelRef = modifiedDocModelRef;
|
|
606
|
+
this.monacoDiffEditor.setModel({
|
|
607
|
+
original: this.originalDocModel!.getMonacoModel(),
|
|
608
|
+
modified: this.modifiedDocModel!.getMonacoModel(),
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
if (rawUri) {
|
|
612
|
+
this.currentUri = rawUri;
|
|
613
|
+
} else {
|
|
614
|
+
this.currentUri = URI.from({
|
|
615
|
+
scheme: 'diff',
|
|
616
|
+
query: URI.stringifyQuery({
|
|
617
|
+
name,
|
|
618
|
+
original: this.originalDocModel!.uri.toString(),
|
|
619
|
+
modified: this.modifiedDocModel!.uri.toString(),
|
|
620
|
+
}),
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (options.range || options.originalRange) {
|
|
625
|
+
const range = (options.range || options.originalRange) as monaco.IRange;
|
|
626
|
+
const currentEditor = options.range ? this.modifiedEditor.monacoEditor : this.originalEditor.monacoEditor;
|
|
627
|
+
// 必须使用 setTimeout, 因为两边的 editor 出现时机问题,diffEditor是异步显示和渲染
|
|
628
|
+
setTimeout(() => {
|
|
629
|
+
currentEditor.revealRangeInCenter(range);
|
|
630
|
+
currentEditor.setSelection(range);
|
|
631
|
+
});
|
|
632
|
+
// monaco diffEditor 在setModel后,计算diff完成后, 左侧 originalEditor 会发出一个异步的onScroll,
|
|
633
|
+
// 这个行为可能会带动右侧 modifiedEditor 进行滚动, 导致 revealRange 错位
|
|
634
|
+
// 此处 添加一个onDidUpdateDiff 监听
|
|
635
|
+
const disposer = this.monacoDiffEditor.onDidUpdateDiff(() => {
|
|
636
|
+
disposer.dispose();
|
|
637
|
+
currentEditor.setSelection(range);
|
|
638
|
+
setTimeout(() => {
|
|
639
|
+
currentEditor.revealRangeInCenter(range);
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
} else {
|
|
643
|
+
this.restoreState();
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (options.revealFirstDiff) {
|
|
647
|
+
const diffs = this.monacoDiffEditor.getLineChanges();
|
|
648
|
+
if (diffs && diffs.length > 0) {
|
|
649
|
+
this.showFirstDiff();
|
|
650
|
+
} else {
|
|
651
|
+
const disposer = this.monacoDiffEditor.onDidUpdateDiff(() => {
|
|
652
|
+
this.showFirstDiff();
|
|
653
|
+
disposer.dispose();
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
await this.updateOptionsOnModelChange();
|
|
658
|
+
this.diffResourceKeys.forEach((r) => r.set(this.currentUri));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
showFirstDiff() {
|
|
662
|
+
const diffs = this.monacoDiffEditor.getLineChanges();
|
|
663
|
+
if (diffs && diffs.length > 0) {
|
|
664
|
+
setTimeout(() => {
|
|
665
|
+
this.monacoDiffEditor.revealLineInCenter(diffs[0].modifiedStartLineNumber);
|
|
666
|
+
}, 0);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
private async updateOptionsOnModelChange() {
|
|
671
|
+
await this.doUpdateDiffOptions();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
private async doUpdateDiffOptions() {
|
|
675
|
+
const uriStr = this.modifiedEditor.currentUri ? this.modifiedEditor.currentUri.toString() : undefined;
|
|
676
|
+
const languageId = this.modifiedEditor.currentDocumentModel
|
|
677
|
+
? this.modifiedEditor.currentDocumentModel.languageId
|
|
678
|
+
: undefined;
|
|
679
|
+
const options = getConvertedMonacoOptions(this.configurationService, uriStr, languageId);
|
|
680
|
+
this.monacoDiffEditor.updateOptions({ ...options.diffOptions, ...this.specialOptions });
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
updateDiffOptions(options: Partial<monaco.editor.IDiffEditorOptions>) {
|
|
684
|
+
this.specialOptions = removeUndefined({ ...this.specialOptions, ...options });
|
|
685
|
+
this.doUpdateDiffOptions();
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
getLineChanges(): ILineChange[] | null {
|
|
689
|
+
const diffChanges = this.monacoDiffEditor.getLineChanges();
|
|
690
|
+
if (!diffChanges) {
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
return diffChanges.map((change) => [
|
|
694
|
+
change.originalStartLineNumber,
|
|
695
|
+
change.originalEndLineNumber,
|
|
696
|
+
change.modifiedStartLineNumber,
|
|
697
|
+
change.modifiedEndLineNumber,
|
|
698
|
+
change.charChanges?.map((charChange) => [
|
|
699
|
+
charChange.originalStartLineNumber,
|
|
700
|
+
charChange.originalStartColumn,
|
|
701
|
+
charChange.originalEndLineNumber,
|
|
702
|
+
charChange.originalEndColumn,
|
|
703
|
+
charChange.modifiedStartLineNumber,
|
|
704
|
+
charChange.modifiedStartColumn,
|
|
705
|
+
charChange.modifiedEndLineNumber,
|
|
706
|
+
charChange.modifiedEndColumn,
|
|
707
|
+
]),
|
|
708
|
+
]);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
private wrapEditors() {
|
|
712
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
713
|
+
const diffEditor = this;
|
|
714
|
+
this.originalEditor = this.injector.get(DiffEditorPart, [
|
|
715
|
+
diffEditor.monacoDiffEditor.getOriginalEditor(),
|
|
716
|
+
() => diffEditor.originalDocModel,
|
|
717
|
+
EditorType.ORIGINAL_DIFF,
|
|
718
|
+
]);
|
|
719
|
+
|
|
720
|
+
this.modifiedEditor = this.injector.get(DiffEditorPart, [
|
|
721
|
+
diffEditor.monacoDiffEditor.getModifiedEditor(),
|
|
722
|
+
() => diffEditor.modifiedDocModel,
|
|
723
|
+
EditorType.MODIFIED_DIFF,
|
|
724
|
+
]);
|
|
725
|
+
|
|
726
|
+
this.collectionService.addEditors([this.originalEditor, this.modifiedEditor]);
|
|
727
|
+
this.collectionService.addDiffEditors([this]);
|
|
728
|
+
|
|
729
|
+
// 为 modified 和 original editor 的 contextKeyService 注入diffEditor的ResourceKey
|
|
730
|
+
const modifiedContextKeyService = this.contextKeyService.createScoped(
|
|
731
|
+
(this.modifiedEditor.monacoEditor as any)._contextKeyService,
|
|
732
|
+
);
|
|
733
|
+
const originalContextKeyService = this.contextKeyService.createScoped(
|
|
734
|
+
(this.originalEditor.monacoEditor as any)._contextKeyService,
|
|
735
|
+
);
|
|
736
|
+
this.diffResourceKeys = [
|
|
737
|
+
new ResourceContextKey(modifiedContextKeyService, undefined, 'diffResource'),
|
|
738
|
+
new ResourceContextKey(originalContextKeyService, undefined, 'diffResource'),
|
|
739
|
+
];
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
layout(): void {
|
|
743
|
+
return this.monacoDiffEditor.layout();
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
focus(): void {
|
|
747
|
+
this.monacoDiffEditor.focus();
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
dispose(): void {
|
|
751
|
+
super.dispose();
|
|
752
|
+
this.collectionService.removeEditors([this.originalEditor, this.modifiedEditor]);
|
|
753
|
+
this.collectionService.removeDiffEditors([this]);
|
|
754
|
+
this.monacoDiffEditor.dispose();
|
|
755
|
+
this._disposed = true;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// utils
|
|
760
|
+
|
|
761
|
+
function bindPreventNavigation(div: HTMLElement) {
|
|
762
|
+
div.addEventListener('mousewheel', preventNavigation as any);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function preventNavigation(this: HTMLDivElement, e: WheelEvent) {
|
|
766
|
+
e.preventDefault();
|
|
767
|
+
e.stopPropagation();
|
|
768
|
+
if (this.offsetWidth + this.scrollLeft + e.deltaX > this.scrollWidth) {
|
|
769
|
+
e.preventDefault();
|
|
770
|
+
e.stopPropagation();
|
|
771
|
+
} else if (this.scrollLeft + e.deltaX < 0) {
|
|
772
|
+
e.preventDefault();
|
|
773
|
+
e.stopPropagation();
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
@Injectable({ multiple: true })
|
|
778
|
+
class DiffEditorPart extends BaseMonacoEditorWrapper implements IEditor {
|
|
779
|
+
get currentDocumentModel() {
|
|
780
|
+
return this.getDocumentModel();
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
constructor(
|
|
784
|
+
monacoEditor: IMonacoCodeEditor,
|
|
785
|
+
private getDocumentModel: () => IEditorDocumentModel | null,
|
|
786
|
+
type: EditorType,
|
|
787
|
+
) {
|
|
788
|
+
super(monacoEditor, type);
|
|
789
|
+
}
|
|
790
|
+
}
|