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