@opensumi/ide-editor 3.3.1-next-1725521092.0 → 3.3.1-next-1725534862.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.
@@ -1,3 +1,5 @@
1
+ import { observable } from 'mobx';
2
+
1
3
  import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
2
4
  import {
3
5
  AppConfig,
@@ -16,7 +18,6 @@ import {
16
18
  toMarkdown,
17
19
  } from '@opensumi/ide-core-browser';
18
20
  import { ResourceContextKey } from '@opensumi/ide-core-browser/lib/contextkey/resource';
19
- import { IDimension } from '@opensumi/ide-core-browser/lib/dom/resize-observer';
20
21
  import { IMergeEditorEditor, MergeEditorInputData } from '@opensumi/ide-core-browser/lib/monaco/merge-editor-widget';
21
22
  import {
22
23
  CUSTOM_EDITOR_SCHEME,
@@ -161,8 +162,6 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
161
162
 
162
163
  public editorContextKeyService: IScopedContextKeyService;
163
164
 
164
- private _domNode: HTMLElement;
165
-
166
165
  @Autowired(IOpenerService)
167
166
  openner: IOpenerService;
168
167
 
@@ -278,7 +277,7 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
278
277
  createEditorGroup(): EditorGroup {
279
278
  const editorGroup = this.injector.get(EditorGroup, [this.generateRandomEditorGroupName(), this.editorGroupIdGen++]);
280
279
  this.editorGroups.push(editorGroup);
281
- editorGroup.addDispose([
280
+ const currentWatchDisposer = new Disposable(
282
281
  editorGroup.onDidEditorGroupBodyChanged(() => {
283
282
  if (editorGroup === this.currentEditorGroup) {
284
283
  if (!editorGroup.currentOpenType && editorGroup.currentResource) {
@@ -297,15 +296,25 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
297
296
  }
298
297
  }
299
298
  }),
300
- editorGroup.onDidEditorGroupTabChanged(() => {
301
- this.saveOpenedResourceState();
302
- }),
303
- editorGroup.onCurrentEditorCursorChange((e) => {
304
- if (this._currentEditorGroup === editorGroup) {
305
- this._onCursorChange.fire(e);
306
- }
307
- }),
308
- ]);
299
+ );
300
+ editorGroup.addDispose({
301
+ dispose: () => {
302
+ currentWatchDisposer.dispose();
303
+ },
304
+ });
305
+ const groupChangeDisposer = editorGroup.onDidEditorGroupTabChanged(() => {
306
+ this.saveOpenedResourceState();
307
+ });
308
+ editorGroup.addDispose({
309
+ dispose: () => {
310
+ groupChangeDisposer.dispose();
311
+ },
312
+ });
313
+ editorGroup.onCurrentEditorCursorChange((e) => {
314
+ if (this._currentEditorGroup === editorGroup) {
315
+ this._onCursorChange.fire(e);
316
+ }
317
+ });
309
318
 
310
319
  return editorGroup;
311
320
  }
@@ -463,7 +472,6 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
463
472
  }
464
473
 
465
474
  onDomCreated(domNode: HTMLElement) {
466
- this._domNode = domNode;
467
475
  if (this.editorContextKeyService) {
468
476
  this.editorContextKeyService.attachToDomNode(domNode);
469
477
  }
@@ -677,25 +685,25 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
677
685
  /**
678
686
  * 当编辑器的tab部分发生变更
679
687
  */
680
- _onDidEditorGroupTabChanged = this.registerDispose(new EventEmitter<void>());
688
+ _onDidEditorGroupTabChanged = new EventEmitter<void>();
681
689
  onDidEditorGroupTabChanged: Event<void> = this._onDidEditorGroupTabChanged.event;
682
690
 
683
691
  /**
684
692
  * 当编辑器的tab部分发生变更
685
693
  */
686
- _onDidEditorGroupTabOperation = this.registerDispose(new EventEmitter<IResourceTabOperation>());
694
+ _onDidEditorGroupTabOperation = new EventEmitter<IResourceTabOperation>();
687
695
  onDidEditorGroupTabOperation: Event<IResourceTabOperation> = this._onDidEditorGroupTabOperation.event;
688
696
 
689
697
  /**
690
698
  * 当编辑器的主体部分发生变更
691
699
  */
692
- _onDidEditorGroupBodyChanged = this.registerDispose(new EventEmitter<void>());
700
+ _onDidEditorGroupBodyChanged = new EventEmitter<void>();
693
701
  onDidEditorGroupBodyChanged: Event<void> = this._onDidEditorGroupBodyChanged.event;
694
702
 
695
703
  /**
696
704
  * 当编辑器有内容处于加载状态
697
705
  */
698
- _onDidEditorGroupContentLoading = this.registerDispose(new EventEmitter<IResource>());
706
+ _onDidEditorGroupContentLoading = new EventEmitter<IResource>();
699
707
  onDidEditorGroupContentLoading: Event<IResource> = this._onDidEditorGroupContentLoading.event;
700
708
 
701
709
  /**
@@ -721,6 +729,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
721
729
 
722
730
  private cachedResourcesOpenTypes = new Map<string, IEditorOpenType[]>();
723
731
 
732
+ @observable.shallow
724
733
  availableOpenTypes: IEditorOpenType[] = [];
725
734
 
726
735
  activeComponents = new Map<IEditorComponent, IResource[]>();
@@ -731,6 +740,8 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
731
740
 
732
741
  private holdDocumentModelRefs: Map<string, IEditorDocumentModelRef> = new Map();
733
742
 
743
+ private readonly toDispose: monaco.IDisposable[] = [];
744
+
734
745
  private _contextKeyService: IContextKeyService;
735
746
 
736
747
  private _resourceContext: ResourceContextKey;
@@ -749,7 +760,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
749
760
  private _prevDomWidth = 0;
750
761
 
751
762
  // 当前为EditorComponent,且monaco光标变化时触发
752
- private _onCurrentEditorCursorChange = this.registerDispose(new EventEmitter<CursorStatus>());
763
+ private _onCurrentEditorCursorChange = new EventEmitter<CursorStatus>();
753
764
  public onCurrentEditorCursorChange = this._onCurrentEditorCursorChange.event;
754
765
 
755
766
  private resourceOpenHistory: URI[] = [];
@@ -776,28 +787,21 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
776
787
 
777
788
  constructor(public readonly name: string, public readonly groupId: number) {
778
789
  super();
779
-
780
- this.addDispose(
781
- this.eventBus.onDirective(
782
- ResizeEvent.createDirective(getSlotLocation('@opensumi/ide-editor', this.config.layoutConfig)),
783
- () => {
784
- this.layoutEditors();
785
- },
786
- ),
787
- );
788
- this.addDispose(
789
- this.eventBus.on(GridResizeEvent, (e: GridResizeEvent) => {
790
- if (e.payload.gridId === this.grid.uid) {
791
- this.layoutEditors();
792
- }
793
- }),
794
- );
795
- this.addDispose(
796
- this.eventBus.on(EditorComponentDisposeEvent, (e: EditorComponentDisposeEvent) => {
797
- this.activeComponents.delete(e.payload);
798
- this.activateComponentsProps.delete(e.payload);
799
- }),
790
+ this.eventBus.onDirective(
791
+ ResizeEvent.createDirective(getSlotLocation('@opensumi/ide-editor', this.config.layoutConfig)),
792
+ () => {
793
+ this.doLayoutEditors();
794
+ },
800
795
  );
796
+ this.eventBus.on(GridResizeEvent, (e: GridResizeEvent) => {
797
+ if (e.payload.gridId === this.grid.uid) {
798
+ this.doLayoutEditors();
799
+ }
800
+ });
801
+ this.eventBus.on(EditorComponentDisposeEvent, (e: EditorComponentDisposeEvent) => {
802
+ this.activeComponents.delete(e.payload);
803
+ this.activateComponentsProps.delete(e.payload);
804
+ });
801
805
 
802
806
  this.listenToExplorerAutoRevealConfig();
803
807
  }
@@ -806,8 +810,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
806
810
  private listenToExplorerAutoRevealConfig() {
807
811
  this.explorerAutoRevealConfig = !!this.preferenceService.get<boolean>('explorer.autoReveal');
808
812
  this.disposables.push(
809
- this.preferenceService.onSpecificPreferenceChange('explorer.autoReveal', (change) => {
810
- this.explorerAutoRevealConfig = change.newValue;
813
+ this.preferenceService.onPreferenceChanged((change) => {
814
+ if (change.preferenceName === 'explorer.autoReveal') {
815
+ this.explorerAutoRevealConfig = change.newValue;
816
+ }
811
817
  }),
812
818
  );
813
819
  }
@@ -839,32 +845,48 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
839
845
  layoutEditors() {
840
846
  fastdom.measure(() => {
841
847
  if (this._domNode) {
842
- this._prevDomWidth = this._domNode.offsetWidth;
843
- this._prevDomHeight = this._domNode.offsetHeight;
844
- this.doLayoutEditors(
845
- {
846
- width: this._prevDomWidth,
847
- height: this._prevDomHeight,
848
- },
849
- true,
850
- );
848
+ const currentWidth = this._domNode.offsetWidth;
849
+ const currentHeight = this._domNode.offsetHeight;
850
+ if (currentWidth !== this._prevDomWidth || currentHeight !== this._prevDomHeight) {
851
+ this.doLayoutEditors();
852
+ }
853
+ this._prevDomWidth = currentWidth;
854
+ this._prevDomHeight = currentHeight;
851
855
  }
852
856
  });
853
857
  }
854
858
 
855
- private doLayoutEditors(e: IDimension, postponeRendering?: boolean) {
856
- if (this.codeEditor) {
857
- if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
858
- this.codeEditor.layout(e, postponeRendering);
859
- }
859
+ private _layoutEditorWorker() {
860
+ if (!this.currentOpenType) {
861
+ return;
860
862
  }
861
- if (this.diffEditor) {
862
- if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
863
- this.diffEditor.layout(e, postponeRendering);
864
- }
863
+
864
+ switch (this.currentOpenType.type) {
865
+ case EditorOpenType.code:
866
+ if (this.codeEditor) {
867
+ this.codeEditor.layout();
868
+ }
869
+ break;
870
+ case EditorOpenType.diff:
871
+ if (this.diffEditor) {
872
+ this.diffEditor.layout();
873
+ }
874
+ break;
875
+ default:
876
+ break;
865
877
  }
866
878
  }
867
879
 
880
+ protected _measure: IDisposable | undefined;
881
+ doLayoutEditors() {
882
+ if (this._measure) {
883
+ this._measure.dispose();
884
+ }
885
+ this._measure = fastdom.mutate(() => {
886
+ this._layoutEditorWorker();
887
+ });
888
+ }
889
+
868
890
  setContextKeys() {
869
891
  if (!this._resourceContext) {
870
892
  const getLanguageFromModel = (uri: URI) => {
@@ -875,24 +897,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
875
897
  }
876
898
  return result;
877
899
  };
878
- this._resourceContext = new ResourceContextKey(this.contextKeyService, (uri: URI) => {
879
- const res = getLanguageFromModel(uri);
880
- if (res) {
881
- return res;
882
- } else {
883
- return getLanguageFromModel(uri);
884
- }
885
- });
900
+ this._resourceContext = new ResourceContextKey(this.contextKeyService, (uri: URI) => getLanguageFromModel(uri));
886
901
  this._diffResourceContextKey = new ResourceContextKey(
887
902
  this.contextKeyService,
888
- (uri: URI) => {
889
- const res = getLanguageFromModel(uri);
890
- if (res) {
891
- return res;
892
- } else {
893
- return getLanguageFromModel(uri);
894
- }
895
- },
903
+ (uri: URI) => getLanguageFromModel(uri),
896
904
  'diffResource',
897
905
  );
898
906
  this._editorLangIDContextKey = this.contextKeyService.createKey<string>('editorLangId', '');
@@ -988,6 +996,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
988
996
  }
989
997
  }
990
998
 
999
+ resetOpenType() {
1000
+ this._currentOpenType = null;
1001
+ }
1002
+
991
1003
  @OnEvent(ResourceOpenTypeChangedEvent)
992
1004
  oResourceOpenTypeChangedEvent(e: ResourceOpenTypeChangedEvent) {
993
1005
  const uri = e.payload;
@@ -995,7 +1007,8 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
995
1007
  this.cachedResourcesOpenTypes.delete(uri.toString());
996
1008
  }
997
1009
  if (this.currentResource && this.currentResource.uri.isEqual(uri)) {
998
- this._currentOpenType = null;
1010
+ this.resetOpenType();
1011
+
999
1012
  this.notifyBodyChanged();
1000
1013
  this.displayResourceComponent(this.currentResource, {});
1001
1014
  }
@@ -1101,23 +1114,20 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1101
1114
  [ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
1102
1115
  },
1103
1116
  );
1104
-
1105
1117
  setTimeout(() => {
1106
- fastdom.mutate(() => {
1107
- this.codeEditor.layout();
1108
- });
1118
+ this.doLayoutEditors();
1109
1119
  });
1110
1120
  this.addDispose(
1111
1121
  this.codeEditor.onRefOpen(() => {
1112
- this.codeEditor.layout();
1122
+ this.doLayoutEditors();
1113
1123
  }),
1114
1124
  );
1115
- this.addDispose(
1125
+ this.toDispose.push(
1116
1126
  this.codeEditor.onCursorPositionChanged((e) => {
1117
1127
  this._onCurrentEditorCursorChange.fire(e);
1118
1128
  }),
1119
1129
  );
1120
- this.addDispose(
1130
+ this.toDispose.push(
1121
1131
  this.codeEditor.onSelectionsChanged((e) => {
1122
1132
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1123
1133
  this.eventBus.fire(
@@ -1132,7 +1142,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1132
1142
  }
1133
1143
  }),
1134
1144
  );
1135
- this.addDispose(
1145
+ this.toDispose.push(
1136
1146
  this.codeEditor.onVisibleRangesChanged((e) => {
1137
1147
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1138
1148
  this.eventBus.fire(
@@ -1146,7 +1156,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1146
1156
  }
1147
1157
  }),
1148
1158
  );
1149
- this.addDispose(
1159
+ this.toDispose.push(
1150
1160
  this.codeEditor.onConfigurationChanged(() => {
1151
1161
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1152
1162
  this.eventBus.fire(
@@ -1189,15 +1199,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1189
1199
  },
1190
1200
  );
1191
1201
  setTimeout(() => {
1192
- fastdom.mutate(() => {
1193
- this.diffEditor.layout();
1194
- });
1202
+ this.doLayoutEditors();
1195
1203
  });
1196
-
1197
1204
  this.diffEditor.onRefOpen(() => {
1198
- fastdom.mutate(() => {
1199
- this.diffEditor.layout();
1200
- });
1205
+ this.doLayoutEditors();
1201
1206
  });
1202
1207
 
1203
1208
  this.addDiffEditorEventListeners(this.diffEditor.originalEditor, 'original');
@@ -1222,7 +1227,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1222
1227
  }
1223
1228
 
1224
1229
  private addDiffEditorEventListeners(editor: IEditor, side?: 'modified' | 'original') {
1225
- this.addDispose(
1230
+ this.toDispose.push(
1226
1231
  editor.onSelectionsChanged((e) => {
1227
1232
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1228
1233
  this.eventBus.fire(
@@ -1239,7 +1244,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1239
1244
  }),
1240
1245
  );
1241
1246
 
1242
- this.addDispose(
1247
+ this.toDispose.push(
1243
1248
  editor.onVisibleRangesChanged((e) => {
1244
1249
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1245
1250
  this.eventBus.fire(
@@ -1254,7 +1259,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1254
1259
  }),
1255
1260
  );
1256
1261
 
1257
- this.addDispose(
1262
+ this.toDispose.push(
1258
1263
  editor.onConfigurationChanged(() => {
1259
1264
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1260
1265
  this.eventBus.fire(
@@ -1809,8 +1814,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1809
1814
  this.resolveTabChanged(_resource, this.currentResource);
1810
1815
  this._currentOpenType = activeOpenType;
1811
1816
  this.notifyBodyChanged();
1812
-
1813
- this.layoutEditors();
1817
+ this.doLayoutEditors();
1814
1818
 
1815
1819
  this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1816
1820
  }
@@ -1962,7 +1966,8 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1962
1966
  const oldResource = this._currentResource;
1963
1967
 
1964
1968
  this._currentResource = null;
1965
- this._currentOpenType = null;
1969
+
1970
+ this.resetOpenType();
1966
1971
  this.notifyTabChanged();
1967
1972
  this.notifyBodyChanged();
1968
1973
  this._currentOrPreviousFocusedEditor = null;
@@ -2208,6 +2213,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
2208
2213
  super.dispose();
2209
2214
  this.codeEditor && this.codeEditor.dispose();
2210
2215
  this.diffEditor && this.diffEditor.dispose();
2216
+ this.toDispose.forEach((disposable) => disposable.dispose());
2211
2217
  this.eventBus.fire(
2212
2218
  new EditorGroupDisposeEvent({
2213
2219
  group: this,
@@ -310,7 +310,7 @@ export interface IDiffEditor extends IDisposable {
310
310
 
311
311
  modifiedEditor: IEditor;
312
312
 
313
- layout(dimension?: IDimension, postponeRendering?: boolean): void;
313
+ layout(): void;
314
314
 
315
315
  focus(): void;
316
316