@opensumi/ide-editor 3.3.1-next-1725432779.0 → 3.3.1-next-1725462155.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,
@@ -41,6 +42,7 @@ import {
41
42
  StorageProvider,
42
43
  URI,
43
44
  WithEventBus,
45
+ debounce,
44
46
  formatLocalize,
45
47
  getDebugLogger,
46
48
  isDefined,
@@ -278,7 +280,7 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
278
280
  createEditorGroup(): EditorGroup {
279
281
  const editorGroup = this.injector.get(EditorGroup, [this.generateRandomEditorGroupName(), this.editorGroupIdGen++]);
280
282
  this.editorGroups.push(editorGroup);
281
- editorGroup.addDispose([
283
+ const currentWatchDisposer = new Disposable(
282
284
  editorGroup.onDidEditorGroupBodyChanged(() => {
283
285
  if (editorGroup === this.currentEditorGroup) {
284
286
  if (!editorGroup.currentOpenType && editorGroup.currentResource) {
@@ -297,15 +299,25 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
297
299
  }
298
300
  }
299
301
  }),
300
- editorGroup.onDidEditorGroupTabChanged(() => {
301
- this.saveOpenedResourceState();
302
- }),
303
- editorGroup.onCurrentEditorCursorChange((e) => {
304
- if (this._currentEditorGroup === editorGroup) {
305
- this._onCursorChange.fire(e);
306
- }
307
- }),
308
- ]);
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
+ });
309
321
 
310
322
  return editorGroup;
311
323
  }
@@ -677,25 +689,25 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
677
689
  /**
678
690
  * 当编辑器的tab部分发生变更
679
691
  */
680
- _onDidEditorGroupTabChanged = this.registerDispose(new EventEmitter<void>());
692
+ _onDidEditorGroupTabChanged = new EventEmitter<void>();
681
693
  onDidEditorGroupTabChanged: Event<void> = this._onDidEditorGroupTabChanged.event;
682
694
 
683
695
  /**
684
696
  * 当编辑器的tab部分发生变更
685
697
  */
686
- _onDidEditorGroupTabOperation = this.registerDispose(new EventEmitter<IResourceTabOperation>());
698
+ _onDidEditorGroupTabOperation = new EventEmitter<IResourceTabOperation>();
687
699
  onDidEditorGroupTabOperation: Event<IResourceTabOperation> = this._onDidEditorGroupTabOperation.event;
688
700
 
689
701
  /**
690
702
  * 当编辑器的主体部分发生变更
691
703
  */
692
- _onDidEditorGroupBodyChanged = this.registerDispose(new EventEmitter<void>());
704
+ _onDidEditorGroupBodyChanged = new EventEmitter<void>();
693
705
  onDidEditorGroupBodyChanged: Event<void> = this._onDidEditorGroupBodyChanged.event;
694
706
 
695
707
  /**
696
708
  * 当编辑器有内容处于加载状态
697
709
  */
698
- _onDidEditorGroupContentLoading = this.registerDispose(new EventEmitter<IResource>());
710
+ _onDidEditorGroupContentLoading = new EventEmitter<IResource>();
699
711
  onDidEditorGroupContentLoading: Event<IResource> = this._onDidEditorGroupContentLoading.event;
700
712
 
701
713
  /**
@@ -721,6 +733,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
721
733
 
722
734
  private cachedResourcesOpenTypes = new Map<string, IEditorOpenType[]>();
723
735
 
736
+ @observable.shallow
724
737
  availableOpenTypes: IEditorOpenType[] = [];
725
738
 
726
739
  activeComponents = new Map<IEditorComponent, IResource[]>();
@@ -731,6 +744,8 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
731
744
 
732
745
  private holdDocumentModelRefs: Map<string, IEditorDocumentModelRef> = new Map();
733
746
 
747
+ private readonly toDispose: monaco.IDisposable[] = [];
748
+
734
749
  private _contextKeyService: IContextKeyService;
735
750
 
736
751
  private _resourceContext: ResourceContextKey;
@@ -748,8 +763,12 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
748
763
  private _prevDomHeight = 0;
749
764
  private _prevDomWidth = 0;
750
765
 
766
+ private _codeEditorPendingLayout = false;
767
+ private _diffEditorPendingLayout = false;
768
+ private _mergeEditorPendingLayout = false;
769
+
751
770
  // 当前为EditorComponent,且monaco光标变化时触发
752
- private _onCurrentEditorCursorChange = this.registerDispose(new EventEmitter<CursorStatus>());
771
+ private _onCurrentEditorCursorChange = new EventEmitter<CursorStatus>();
753
772
  public onCurrentEditorCursorChange = this._onCurrentEditorCursorChange.event;
754
773
 
755
774
  private resourceOpenHistory: URI[] = [];
@@ -776,28 +795,28 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
776
795
 
777
796
  constructor(public readonly name: string, public readonly groupId: number) {
778
797
  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();
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();
792
804
  }
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
- }),
805
+
806
+ toDispose = fastdom.mutate(() => {
807
+ this._layoutEditorWorker();
808
+ });
809
+ },
800
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
+ });
801
820
 
802
821
  this.listenToExplorerAutoRevealConfig();
803
822
  }
@@ -806,8 +825,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
806
825
  private listenToExplorerAutoRevealConfig() {
807
826
  this.explorerAutoRevealConfig = !!this.preferenceService.get<boolean>('explorer.autoReveal');
808
827
  this.disposables.push(
809
- this.preferenceService.onSpecificPreferenceChange('explorer.autoReveal', (change) => {
810
- this.explorerAutoRevealConfig = change.newValue;
828
+ this.preferenceService.onPreferenceChanged((change) => {
829
+ if (change.preferenceName === 'explorer.autoReveal') {
830
+ this.explorerAutoRevealConfig = change.newValue;
831
+ }
811
832
  }),
812
833
  );
813
834
  }
@@ -839,32 +860,49 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
839
860
  layoutEditors() {
840
861
  fastdom.measure(() => {
841
862
  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
- );
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;
851
870
  }
852
871
  });
853
872
  }
854
873
 
855
- private doLayoutEditors(e: IDimension, postponeRendering?: boolean) {
874
+ private _layoutEditorWorker() {
856
875
  if (this.codeEditor) {
857
876
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
858
- this.codeEditor.layout(e, postponeRendering);
877
+ this.codeEditor.layout();
878
+ this._codeEditorPendingLayout = false;
879
+ } else {
880
+ this._codeEditorPendingLayout = true;
859
881
  }
860
882
  }
861
883
  if (this.diffEditor) {
862
884
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
863
- this.diffEditor.layout(e, postponeRendering);
885
+ this.diffEditor.layout();
886
+ this._diffEditorPendingLayout = false;
887
+ } else {
888
+ this._diffEditorPendingLayout = true;
889
+ }
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;
864
897
  }
865
898
  }
866
899
  }
867
900
 
901
+ @debounce(16 * 5)
902
+ doLayoutEditors() {
903
+ this._layoutEditorWorker();
904
+ }
905
+
868
906
  setContextKeys() {
869
907
  if (!this._resourceContext) {
870
908
  const getLanguageFromModel = (uri: URI) => {
@@ -996,6 +1034,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
996
1034
  }
997
1035
  if (this.currentResource && this.currentResource.uri.isEqual(uri)) {
998
1036
  this._currentOpenType = null;
1037
+ this._codeEditorPendingLayout = false;
1038
+ this._diffEditorPendingLayout = false;
1039
+ this._mergeEditorPendingLayout = false;
1040
+
999
1041
  this.notifyBodyChanged();
1000
1042
  this.displayResourceComponent(this.currentResource, {});
1001
1043
  }
@@ -1103,21 +1145,19 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1103
1145
  );
1104
1146
 
1105
1147
  setTimeout(() => {
1106
- fastdom.mutate(() => {
1107
- this.codeEditor.layout();
1108
- });
1148
+ this.codeEditor.layout();
1109
1149
  });
1110
1150
  this.addDispose(
1111
1151
  this.codeEditor.onRefOpen(() => {
1112
1152
  this.codeEditor.layout();
1113
1153
  }),
1114
1154
  );
1115
- this.addDispose(
1155
+ this.toDispose.push(
1116
1156
  this.codeEditor.onCursorPositionChanged((e) => {
1117
1157
  this._onCurrentEditorCursorChange.fire(e);
1118
1158
  }),
1119
1159
  );
1120
- this.addDispose(
1160
+ this.toDispose.push(
1121
1161
  this.codeEditor.onSelectionsChanged((e) => {
1122
1162
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1123
1163
  this.eventBus.fire(
@@ -1132,7 +1172,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1132
1172
  }
1133
1173
  }),
1134
1174
  );
1135
- this.addDispose(
1175
+ this.toDispose.push(
1136
1176
  this.codeEditor.onVisibleRangesChanged((e) => {
1137
1177
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1138
1178
  this.eventBus.fire(
@@ -1146,7 +1186,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1146
1186
  }
1147
1187
  }),
1148
1188
  );
1149
- this.addDispose(
1189
+ this.toDispose.push(
1150
1190
  this.codeEditor.onConfigurationChanged(() => {
1151
1191
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
1152
1192
  this.eventBus.fire(
@@ -1189,15 +1229,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1189
1229
  },
1190
1230
  );
1191
1231
  setTimeout(() => {
1192
- fastdom.mutate(() => {
1193
- this.diffEditor.layout();
1194
- });
1195
- });
1196
-
1197
- this.diffEditor.onRefOpen(() => {
1198
- fastdom.mutate(() => {
1199
- this.diffEditor.layout();
1200
- });
1232
+ this.diffEditor.layout();
1201
1233
  });
1202
1234
 
1203
1235
  this.addDiffEditorEventListeners(this.diffEditor.originalEditor, 'original');
@@ -1222,7 +1254,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1222
1254
  }
1223
1255
 
1224
1256
  private addDiffEditorEventListeners(editor: IEditor, side?: 'modified' | 'original') {
1225
- this.addDispose(
1257
+ this.toDispose.push(
1226
1258
  editor.onSelectionsChanged((e) => {
1227
1259
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1228
1260
  this.eventBus.fire(
@@ -1239,7 +1271,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1239
1271
  }),
1240
1272
  );
1241
1273
 
1242
- this.addDispose(
1274
+ this.toDispose.push(
1243
1275
  editor.onVisibleRangesChanged((e) => {
1244
1276
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1245
1277
  this.eventBus.fire(
@@ -1254,7 +1286,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1254
1286
  }),
1255
1287
  );
1256
1288
 
1257
- this.addDispose(
1289
+ this.toDispose.push(
1258
1290
  editor.onConfigurationChanged(() => {
1259
1291
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
1260
1292
  this.eventBus.fire(
@@ -1810,7 +1842,13 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1810
1842
  this._currentOpenType = activeOpenType;
1811
1843
  this.notifyBodyChanged();
1812
1844
 
1813
- this.layoutEditors();
1845
+ if (
1846
+ (!this._codeEditorPendingLayout && activeOpenType.type === EditorOpenType.code) ||
1847
+ (!this._diffEditorPendingLayout && activeOpenType.type === EditorOpenType.diff) ||
1848
+ (!this._mergeEditorPendingLayout && activeOpenType.type === EditorOpenType.mergeEditor)
1849
+ ) {
1850
+ this.doLayoutEditors();
1851
+ }
1814
1852
 
1815
1853
  this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1816
1854
  }
@@ -1963,6 +2001,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1963
2001
 
1964
2002
  this._currentResource = null;
1965
2003
  this._currentOpenType = null;
2004
+ this._codeEditorPendingLayout = false;
2005
+ this._diffEditorPendingLayout = false;
2006
+ this._mergeEditorPendingLayout = false;
2007
+
1966
2008
  this.notifyTabChanged();
1967
2009
  this.notifyBodyChanged();
1968
2010
  this._currentOrPreviousFocusedEditor = null;
@@ -2208,6 +2250,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
2208
2250
  super.dispose();
2209
2251
  this.codeEditor && this.codeEditor.dispose();
2210
2252
  this.diffEditor && this.diffEditor.dispose();
2253
+ this.toDispose.forEach((disposable) => disposable.dispose());
2211
2254
  this.eventBus.fire(
2212
2255
  new EditorGroupDisposeEvent({
2213
2256
  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