@opensumi/ide-editor 3.3.1-next-1725288439.0 → 3.3.1-next-1725363936.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,
@@ -40,6 +42,7 @@ import {
40
42
  StorageProvider,
41
43
  URI,
42
44
  WithEventBus,
45
+ debounce,
43
46
  formatLocalize,
44
47
  getDebugLogger,
45
48
  isDefined,
@@ -277,7 +280,7 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
277
280
  createEditorGroup(): EditorGroup {
278
281
  const editorGroup = this.injector.get(EditorGroup, [this.generateRandomEditorGroupName(), this.editorGroupIdGen++]);
279
282
  this.editorGroups.push(editorGroup);
280
- editorGroup.addDispose([
283
+ const currentWatchDisposer = new Disposable(
281
284
  editorGroup.onDidEditorGroupBodyChanged(() => {
282
285
  if (editorGroup === this.currentEditorGroup) {
283
286
  if (!editorGroup.currentOpenType && editorGroup.currentResource) {
@@ -296,15 +299,25 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
296
299
  }
297
300
  }
298
301
  }),
299
- editorGroup.onDidEditorGroupTabChanged(() => {
300
- this.saveOpenedResourceState();
301
- }),
302
- editorGroup.onCurrentEditorCursorChange((e) => {
303
- if (this._currentEditorGroup === editorGroup) {
304
- this._onCursorChange.fire(e);
305
- }
306
- }),
307
- ]);
302
+ );
303
+ editorGroup.addDispose({
304
+ dispose: () => {
305
+ currentWatchDisposer.dispose();
306
+ },
307
+ });
308
+ const groupChangeDisposer = editorGroup.onDidEditorGroupTabChanged(() => {
309
+ this.saveOpenedResourceState();
310
+ });
311
+ editorGroup.addDispose({
312
+ dispose: () => {
313
+ groupChangeDisposer.dispose();
314
+ },
315
+ });
316
+ editorGroup.onCurrentEditorCursorChange((e) => {
317
+ if (this._currentEditorGroup === editorGroup) {
318
+ this._onCursorChange.fire(e);
319
+ }
320
+ });
308
321
 
309
322
  return editorGroup;
310
323
  }
@@ -676,25 +689,25 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
676
689
  /**
677
690
  * 当编辑器的tab部分发生变更
678
691
  */
679
- _onDidEditorGroupTabChanged = this.registerDispose(new EventEmitter<void>());
692
+ _onDidEditorGroupTabChanged = new EventEmitter<void>();
680
693
  onDidEditorGroupTabChanged: Event<void> = this._onDidEditorGroupTabChanged.event;
681
694
 
682
695
  /**
683
696
  * 当编辑器的tab部分发生变更
684
697
  */
685
- _onDidEditorGroupTabOperation = this.registerDispose(new EventEmitter<IResourceTabOperation>());
698
+ _onDidEditorGroupTabOperation = new EventEmitter<IResourceTabOperation>();
686
699
  onDidEditorGroupTabOperation: Event<IResourceTabOperation> = this._onDidEditorGroupTabOperation.event;
687
700
 
688
701
  /**
689
702
  * 当编辑器的主体部分发生变更
690
703
  */
691
- _onDidEditorGroupBodyChanged = this.registerDispose(new EventEmitter<void>());
704
+ _onDidEditorGroupBodyChanged = new EventEmitter<void>();
692
705
  onDidEditorGroupBodyChanged: Event<void> = this._onDidEditorGroupBodyChanged.event;
693
706
 
694
707
  /**
695
708
  * 当编辑器有内容处于加载状态
696
709
  */
697
- _onDidEditorGroupContentLoading = this.registerDispose(new EventEmitter<IResource>());
710
+ _onDidEditorGroupContentLoading = new EventEmitter<IResource>();
698
711
  onDidEditorGroupContentLoading: Event<IResource> = this._onDidEditorGroupContentLoading.event;
699
712
 
700
713
  /**
@@ -720,6 +733,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
720
733
 
721
734
  private cachedResourcesOpenTypes = new Map<string, IEditorOpenType[]>();
722
735
 
736
+ @observable.shallow
723
737
  availableOpenTypes: IEditorOpenType[] = [];
724
738
 
725
739
  activeComponents = new Map<IEditorComponent, IResource[]>();
@@ -730,6 +744,8 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
730
744
 
731
745
  private holdDocumentModelRefs: Map<string, IEditorDocumentModelRef> = new Map();
732
746
 
747
+ private readonly toDispose: monaco.IDisposable[] = [];
748
+
733
749
  private _contextKeyService: IContextKeyService;
734
750
 
735
751
  private _resourceContext: ResourceContextKey;
@@ -747,8 +763,12 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
747
763
  private _prevDomHeight = 0;
748
764
  private _prevDomWidth = 0;
749
765
 
766
+ private _codeEditorPendingLayout = false;
767
+ private _diffEditorPendingLayout = false;
768
+ private _mergeEditorPendingLayout = false;
769
+
750
770
  // 当前为EditorComponent,且monaco光标变化时触发
751
- private _onCurrentEditorCursorChange = this.registerDispose(new EventEmitter<CursorStatus>());
771
+ private _onCurrentEditorCursorChange = new EventEmitter<CursorStatus>();
752
772
  public onCurrentEditorCursorChange = this._onCurrentEditorCursorChange.event;
753
773
 
754
774
  private resourceOpenHistory: URI[] = [];
@@ -775,28 +795,28 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
775
795
 
776
796
  constructor(public readonly name: string, public readonly groupId: number) {
777
797
  super();
778
-
779
- this.addDispose(
780
- this.eventBus.onDirective(
781
- ResizeEvent.createDirective(getSlotLocation('@opensumi/ide-editor', this.config.layoutConfig)),
782
- () => {
783
- this.layoutEditors();
784
- },
785
- ),
786
- );
787
- this.addDispose(
788
- this.eventBus.on(GridResizeEvent, (e: GridResizeEvent) => {
789
- if (e.payload.gridId === this.grid.uid) {
790
- this.layoutEditors();
798
+ let toDispose: IDisposable | undefined;
799
+ this.eventBus.onDirective(
800
+ ResizeEvent.createDirective(getSlotLocation('@opensumi/ide-editor', this.config.layoutConfig)),
801
+ () => {
802
+ if (toDispose) {
803
+ toDispose.dispose();
791
804
  }
792
- }),
793
- );
794
- this.addDispose(
795
- this.eventBus.on(EditorComponentDisposeEvent, (e: EditorComponentDisposeEvent) => {
796
- this.activeComponents.delete(e.payload);
797
- this.activateComponentsProps.delete(e.payload);
798
- }),
805
+
806
+ toDispose = fastdom.mutate(() => {
807
+ this._layoutEditorWorker();
808
+ });
809
+ },
799
810
  );
811
+ this.eventBus.on(GridResizeEvent, (e: GridResizeEvent) => {
812
+ if (e.payload.gridId === this.grid.uid) {
813
+ this.doLayoutEditors();
814
+ }
815
+ });
816
+ this.eventBus.on(EditorComponentDisposeEvent, (e: EditorComponentDisposeEvent) => {
817
+ this.activeComponents.delete(e.payload);
818
+ this.activateComponentsProps.delete(e.payload);
819
+ });
800
820
 
801
821
  this.listenToExplorerAutoRevealConfig();
802
822
  }
@@ -805,8 +825,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
805
825
  private listenToExplorerAutoRevealConfig() {
806
826
  this.explorerAutoRevealConfig = !!this.preferenceService.get<boolean>('explorer.autoReveal');
807
827
  this.disposables.push(
808
- this.preferenceService.onSpecificPreferenceChange('explorer.autoReveal', (change) => {
809
- this.explorerAutoRevealConfig = change.newValue;
828
+ this.preferenceService.onPreferenceChanged((change) => {
829
+ if (change.preferenceName === 'explorer.autoReveal') {
830
+ this.explorerAutoRevealConfig = change.newValue;
831
+ }
810
832
  }),
811
833
  );
812
834
  }
@@ -838,36 +860,47 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
838
860
  layoutEditors() {
839
861
  fastdom.measure(() => {
840
862
  if (this._domNode) {
841
- this._prevDomWidth = this._domNode.offsetWidth;
842
- this._prevDomHeight = this._domNode.offsetHeight;
843
- this.doLayoutEditors();
863
+ const currentWidth = this._domNode.offsetWidth;
864
+ const currentHeight = this._domNode.offsetHeight;
865
+ if (currentWidth !== this._prevDomWidth || currentHeight !== this._prevDomHeight) {
866
+ this.doLayoutEditors();
867
+ }
868
+ this._prevDomWidth = currentWidth;
869
+ this._prevDomHeight = currentHeight;
844
870
  }
845
871
  });
846
872
  }
847
873
 
848
- private doLayoutEditors() {
874
+ private _layoutEditorWorker() {
849
875
  if (this.codeEditor) {
850
876
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
851
- this.codeEditor.layout(
852
- {
853
- width: this._prevDomWidth,
854
- height: this._prevDomHeight,
855
- },
856
- true,
857
- );
877
+ this.codeEditor.layout();
878
+ this._codeEditorPendingLayout = false;
879
+ } else {
880
+ this._codeEditorPendingLayout = true;
858
881
  }
859
882
  }
860
883
  if (this.diffEditor) {
861
884
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
862
- this.diffEditor.layout(
863
- {
864
- width: this._prevDomWidth,
865
- height: this._prevDomHeight,
866
- },
867
- true,
868
- );
885
+ this.diffEditor.layout();
886
+ this._diffEditorPendingLayout = false;
887
+ } else {
888
+ this._diffEditorPendingLayout = true;
869
889
  }
870
890
  }
891
+ if (this.mergeEditor) {
892
+ if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.mergeEditor) {
893
+ // this.mergeEditor.layout();
894
+ this._mergeEditorPendingLayout = false;
895
+ } else {
896
+ this._mergeEditorPendingLayout = true;
897
+ }
898
+ }
899
+ }
900
+
901
+ @debounce(16 * 5)
902
+ doLayoutEditors() {
903
+ this._layoutEditorWorker();
871
904
  }
872
905
 
873
906
  setContextKeys() {
@@ -1108,21 +1141,19 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1108
1141
  );
1109
1142
 
1110
1143
  setTimeout(() => {
1111
- fastdom.mutate(() => {
1112
- this.codeEditor.layout();
1113
- });
1144
+ this.codeEditor.layout();
1114
1145
  });
1115
1146
  this.addDispose(
1116
1147
  this.codeEditor.onRefOpen(() => {
1117
1148
  this.codeEditor.layout();
1118
1149
  }),
1119
1150
  );
1120
- this.addDispose(
1151
+ this.toDispose.push(
1121
1152
  this.codeEditor.onCursorPositionChanged((e) => {
1122
1153
  this._onCurrentEditorCursorChange.fire(e);
1123
1154
  }),
1124
1155
  );
1125
- this.addDispose(
1156
+ this.toDispose.push(
1126
1157
  this.codeEditor.onSelectionsChanged((e) => {
1127
1158
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1128
1159
  this.eventBus.fire(
@@ -1137,7 +1168,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1137
1168
  }
1138
1169
  }),
1139
1170
  );
1140
- this.addDispose(
1171
+ this.toDispose.push(
1141
1172
  this.codeEditor.onVisibleRangesChanged((e) => {
1142
1173
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1143
1174
  this.eventBus.fire(
@@ -1151,7 +1182,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1151
1182
  }
1152
1183
  }),
1153
1184
  );
1154
- this.addDispose(
1185
+ this.toDispose.push(
1155
1186
  this.codeEditor.onConfigurationChanged(() => {
1156
1187
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1157
1188
  this.eventBus.fire(
@@ -1194,15 +1225,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1194
1225
  },
1195
1226
  );
1196
1227
  setTimeout(() => {
1197
- fastdom.mutate(() => {
1198
- this.diffEditor.layout();
1199
- });
1200
- });
1201
-
1202
- this.diffEditor.onRefOpen(() => {
1203
- fastdom.mutate(() => {
1204
- this.diffEditor.layout();
1205
- });
1228
+ this.diffEditor.layout();
1206
1229
  });
1207
1230
 
1208
1231
  this.addDiffEditorEventListeners(this.diffEditor.originalEditor, 'original');
@@ -1227,7 +1250,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1227
1250
  }
1228
1251
 
1229
1252
  private addDiffEditorEventListeners(editor: IEditor, side?: 'modified' | 'original') {
1230
- this.addDispose(
1253
+ this.toDispose.push(
1231
1254
  editor.onSelectionsChanged((e) => {
1232
1255
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1233
1256
  this.eventBus.fire(
@@ -1244,7 +1267,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1244
1267
  }),
1245
1268
  );
1246
1269
 
1247
- this.addDispose(
1270
+ this.toDispose.push(
1248
1271
  editor.onVisibleRangesChanged((e) => {
1249
1272
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1250
1273
  this.eventBus.fire(
@@ -1259,7 +1282,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1259
1282
  }),
1260
1283
  );
1261
1284
 
1262
- this.addDispose(
1285
+ this.toDispose.push(
1263
1286
  editor.onConfigurationChanged(() => {
1264
1287
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1265
1288
  this.eventBus.fire(
@@ -1815,7 +1838,13 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1815
1838
  this._currentOpenType = activeOpenType;
1816
1839
  this.notifyBodyChanged();
1817
1840
 
1818
- this.layoutEditors();
1841
+ if (
1842
+ (!this._codeEditorPendingLayout && activeOpenType.type === EditorOpenType.code) ||
1843
+ (!this._diffEditorPendingLayout && activeOpenType.type === EditorOpenType.diff) ||
1844
+ (!this._mergeEditorPendingLayout && activeOpenType.type === EditorOpenType.mergeEditor)
1845
+ ) {
1846
+ this.doLayoutEditors();
1847
+ }
1819
1848
 
1820
1849
  this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1821
1850
  }
@@ -2213,6 +2242,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
2213
2242
  super.dispose();
2214
2243
  this.codeEditor && this.codeEditor.dispose();
2215
2244
  this.diffEditor && this.diffEditor.dispose();
2245
+ this.toDispose.forEach((disposable) => disposable.dispose());
2216
2246
  this.eventBus.fire(
2217
2247
  new EditorGroupDisposeEvent({
2218
2248
  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