@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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EditorGroup = exports.WorkbenchEditorServiceImpl = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const mobx_1 = require("mobx");
5
6
  const di_1 = require("@opensumi/di");
6
7
  const ide_core_browser_1 = require("@opensumi/ide-core-browser");
7
8
  const resource_1 = require("@opensumi/ide-core-browser/lib/contextkey/resource");
@@ -120,37 +121,44 @@ let WorkbenchEditorServiceImpl = class WorkbenchEditorServiceImpl extends ide_co
120
121
  createEditorGroup() {
121
122
  const editorGroup = this.injector.get(EditorGroup, [this.generateRandomEditorGroupName(), this.editorGroupIdGen++]);
122
123
  this.editorGroups.push(editorGroup);
123
- editorGroup.addDispose([
124
- editorGroup.onDidEditorGroupBodyChanged(() => {
125
- if (editorGroup === this.currentEditorGroup) {
126
- if (!editorGroup.currentOpenType && editorGroup.currentResource) {
127
- // 暂时状态,不发事件
128
- }
129
- else {
130
- this._onActiveResourceChange.fire(editorGroup.currentResource);
131
- }
124
+ const currentWatchDisposer = new ide_core_common_1.Disposable(editorGroup.onDidEditorGroupBodyChanged(() => {
125
+ if (editorGroup === this.currentEditorGroup) {
126
+ if (!editorGroup.currentOpenType && editorGroup.currentResource) {
127
+ // 暂时状态,不发事件
132
128
  }
133
- }),
134
- editorGroup.onDidEditorFocusChange(() => {
135
- var _a;
136
- if (editorGroup === this.currentEditorGroup) {
137
- if (!editorGroup.currentOpenType && editorGroup.currentResource) {
138
- // 暂时状态,不发事件
139
- }
140
- else {
141
- this._onActiveEditorUriChange.fire((_a = editorGroup.currentOrPreviousFocusedEditor) === null || _a === void 0 ? void 0 : _a.currentUri);
142
- }
129
+ else {
130
+ this._onActiveResourceChange.fire(editorGroup.currentResource);
143
131
  }
144
- }),
145
- editorGroup.onDidEditorGroupTabChanged(() => {
146
- this.saveOpenedResourceState();
147
- }),
148
- editorGroup.onCurrentEditorCursorChange((e) => {
149
- if (this._currentEditorGroup === editorGroup) {
150
- this._onCursorChange.fire(e);
132
+ }
133
+ }), editorGroup.onDidEditorFocusChange(() => {
134
+ var _a;
135
+ if (editorGroup === this.currentEditorGroup) {
136
+ if (!editorGroup.currentOpenType && editorGroup.currentResource) {
137
+ // 暂时状态,不发事件
151
138
  }
152
- }),
153
- ]);
139
+ else {
140
+ this._onActiveEditorUriChange.fire((_a = editorGroup.currentOrPreviousFocusedEditor) === null || _a === void 0 ? void 0 : _a.currentUri);
141
+ }
142
+ }
143
+ }));
144
+ editorGroup.addDispose({
145
+ dispose: () => {
146
+ currentWatchDisposer.dispose();
147
+ },
148
+ });
149
+ const groupChangeDisposer = editorGroup.onDidEditorGroupTabChanged(() => {
150
+ this.saveOpenedResourceState();
151
+ });
152
+ editorGroup.addDispose({
153
+ dispose: () => {
154
+ groupChangeDisposer.dispose();
155
+ },
156
+ });
157
+ editorGroup.onCurrentEditorCursorChange((e) => {
158
+ if (this._currentEditorGroup === editorGroup) {
159
+ this._onCursorChange.fire(e);
160
+ }
161
+ });
154
162
  return editorGroup;
155
163
  }
156
164
  /**
@@ -489,22 +497,22 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
489
497
  /**
490
498
  * 当编辑器的tab部分发生变更
491
499
  */
492
- this._onDidEditorGroupTabChanged = this.registerDispose(new ide_core_common_1.Emitter());
500
+ this._onDidEditorGroupTabChanged = new ide_core_common_1.Emitter();
493
501
  this.onDidEditorGroupTabChanged = this._onDidEditorGroupTabChanged.event;
494
502
  /**
495
503
  * 当编辑器的tab部分发生变更
496
504
  */
497
- this._onDidEditorGroupTabOperation = this.registerDispose(new ide_core_common_1.Emitter());
505
+ this._onDidEditorGroupTabOperation = new ide_core_common_1.Emitter();
498
506
  this.onDidEditorGroupTabOperation = this._onDidEditorGroupTabOperation.event;
499
507
  /**
500
508
  * 当编辑器的主体部分发生变更
501
509
  */
502
- this._onDidEditorGroupBodyChanged = this.registerDispose(new ide_core_common_1.Emitter());
510
+ this._onDidEditorGroupBodyChanged = new ide_core_common_1.Emitter();
503
511
  this.onDidEditorGroupBodyChanged = this._onDidEditorGroupBodyChanged.event;
504
512
  /**
505
513
  * 当编辑器有内容处于加载状态
506
514
  */
507
- this._onDidEditorGroupContentLoading = this.registerDispose(new ide_core_common_1.Emitter());
515
+ this._onDidEditorGroupContentLoading = new ide_core_common_1.Emitter();
508
516
  this.onDidEditorGroupContentLoading = this._onDidEditorGroupContentLoading.event;
509
517
  /**
510
518
  * 每个group只能有一个preview
@@ -524,10 +532,14 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
524
532
  this.activeComponents = new Map();
525
533
  this.activateComponentsProps = new Map();
526
534
  this.holdDocumentModelRefs = new Map();
535
+ this.toDispose = [];
527
536
  this._prevDomHeight = 0;
528
537
  this._prevDomWidth = 0;
538
+ this._codeEditorPendingLayout = false;
539
+ this._diffEditorPendingLayout = false;
540
+ this._mergeEditorPendingLayout = false;
529
541
  // 当前为EditorComponent,且monaco光标变化时触发
530
- this._onCurrentEditorCursorChange = this.registerDispose(new ide_core_common_1.Emitter());
542
+ this._onCurrentEditorCursorChange = new ide_core_common_1.Emitter();
531
543
  this.onCurrentEditorCursorChange = this._onCurrentEditorCursorChange.event;
532
544
  this.resourceOpenHistory = [];
533
545
  this._domNode = null;
@@ -541,24 +553,32 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
541
553
  this.mergeEditorReady = new ide_core_common_1.ReadyEvent();
542
554
  this.mergeEditorDomReady = new ide_core_common_1.ReadyEvent();
543
555
  this._restoringState = false;
544
- this.addDispose(this.eventBus.onDirective(ide_core_browser_1.ResizeEvent.createDirective((0, ide_core_browser_1.getSlotLocation)('@opensumi/ide-editor', this.config.layoutConfig)), () => {
545
- this.layoutEditors();
546
- }));
547
- this.addDispose(this.eventBus.on(types_2.GridResizeEvent, (e) => {
556
+ let toDispose;
557
+ this.eventBus.onDirective(ide_core_browser_1.ResizeEvent.createDirective((0, ide_core_browser_1.getSlotLocation)('@opensumi/ide-editor', this.config.layoutConfig)), () => {
558
+ if (toDispose) {
559
+ toDispose.dispose();
560
+ }
561
+ toDispose = ide_core_browser_1.fastdom.mutate(() => {
562
+ this._layoutEditorWorker();
563
+ });
564
+ });
565
+ this.eventBus.on(types_2.GridResizeEvent, (e) => {
548
566
  if (e.payload.gridId === this.grid.uid) {
549
- this.layoutEditors();
567
+ this.doLayoutEditors();
550
568
  }
551
- }));
552
- this.addDispose(this.eventBus.on(types_2.EditorComponentDisposeEvent, (e) => {
569
+ });
570
+ this.eventBus.on(types_2.EditorComponentDisposeEvent, (e) => {
553
571
  this.activeComponents.delete(e.payload);
554
572
  this.activateComponentsProps.delete(e.payload);
555
- }));
573
+ });
556
574
  this.listenToExplorerAutoRevealConfig();
557
575
  }
558
576
  listenToExplorerAutoRevealConfig() {
559
577
  this.explorerAutoRevealConfig = !!this.preferenceService.get('explorer.autoReveal');
560
- this.disposables.push(this.preferenceService.onSpecificPreferenceChange('explorer.autoReveal', (change) => {
561
- this.explorerAutoRevealConfig = change.newValue;
578
+ this.disposables.push(this.preferenceService.onPreferenceChanged((change) => {
579
+ if (change.preferenceName === 'explorer.autoReveal') {
580
+ this.explorerAutoRevealConfig = change.newValue;
581
+ }
562
582
  }));
563
583
  }
564
584
  attachDiffEditorDom(domNode) {
@@ -585,30 +605,48 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
585
605
  layoutEditors() {
586
606
  ide_core_browser_1.fastdom.measure(() => {
587
607
  if (this._domNode) {
588
- this._prevDomWidth = this._domNode.offsetWidth;
589
- this._prevDomHeight = this._domNode.offsetHeight;
590
- this.doLayoutEditors();
608
+ const currentWidth = this._domNode.offsetWidth;
609
+ const currentHeight = this._domNode.offsetHeight;
610
+ if (currentWidth !== this._prevDomWidth || currentHeight !== this._prevDomHeight) {
611
+ this.doLayoutEditors();
612
+ }
613
+ this._prevDomWidth = currentWidth;
614
+ this._prevDomHeight = currentHeight;
591
615
  }
592
616
  });
593
617
  }
594
- doLayoutEditors() {
618
+ _layoutEditorWorker() {
595
619
  if (this.codeEditor) {
596
620
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
597
- this.codeEditor.layout({
598
- width: this._prevDomWidth,
599
- height: this._prevDomHeight,
600
- }, true);
621
+ this.codeEditor.layout();
622
+ this._codeEditorPendingLayout = false;
623
+ }
624
+ else {
625
+ this._codeEditorPendingLayout = true;
601
626
  }
602
627
  }
603
628
  if (this.diffEditor) {
604
629
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
605
- this.diffEditor.layout({
606
- width: this._prevDomWidth,
607
- height: this._prevDomHeight,
608
- }, true);
630
+ this.diffEditor.layout();
631
+ this._diffEditorPendingLayout = false;
632
+ }
633
+ else {
634
+ this._diffEditorPendingLayout = true;
635
+ }
636
+ }
637
+ if (this.mergeEditor) {
638
+ if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.mergeEditor) {
639
+ // this.mergeEditor.layout();
640
+ this._mergeEditorPendingLayout = false;
641
+ }
642
+ else {
643
+ this._mergeEditorPendingLayout = true;
609
644
  }
610
645
  }
611
646
  }
647
+ doLayoutEditors() {
648
+ this._layoutEditorWorker();
649
+ }
612
650
  setContextKeys() {
613
651
  var _a;
614
652
  if (!this._resourceContext) {
@@ -827,17 +865,15 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
827
865
  [ide_core_browser_1.ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
828
866
  });
829
867
  setTimeout(() => {
830
- ide_core_browser_1.fastdom.mutate(() => {
831
- this.codeEditor.layout();
832
- });
868
+ this.codeEditor.layout();
833
869
  });
834
870
  this.addDispose(this.codeEditor.onRefOpen(() => {
835
871
  this.codeEditor.layout();
836
872
  }));
837
- this.addDispose(this.codeEditor.onCursorPositionChanged((e) => {
873
+ this.toDispose.push(this.codeEditor.onCursorPositionChanged((e) => {
838
874
  this._onCurrentEditorCursorChange.fire(e);
839
875
  }));
840
- this.addDispose(this.codeEditor.onSelectionsChanged((e) => {
876
+ this.toDispose.push(this.codeEditor.onSelectionsChanged((e) => {
841
877
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
842
878
  this.eventBus.fire(new types_2.EditorSelectionChangeEvent({
843
879
  group: this,
@@ -848,7 +884,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
848
884
  }));
849
885
  }
850
886
  }));
851
- this.addDispose(this.codeEditor.onVisibleRangesChanged((e) => {
887
+ this.toDispose.push(this.codeEditor.onVisibleRangesChanged((e) => {
852
888
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
853
889
  this.eventBus.fire(new types_2.EditorVisibleChangeEvent({
854
890
  group: this,
@@ -858,7 +894,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
858
894
  }));
859
895
  }
860
896
  }));
861
- this.addDispose(this.codeEditor.onConfigurationChanged(() => {
897
+ this.toDispose.push(this.codeEditor.onConfigurationChanged(() => {
862
898
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
863
899
  this.eventBus.fire(new types_2.EditorConfigurationChangedEvent({
864
900
  group: this,
@@ -885,14 +921,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
885
921
  [ide_core_browser_1.ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
886
922
  });
887
923
  setTimeout(() => {
888
- ide_core_browser_1.fastdom.mutate(() => {
889
- this.diffEditor.layout();
890
- });
891
- });
892
- this.diffEditor.onRefOpen(() => {
893
- ide_core_browser_1.fastdom.mutate(() => {
894
- this.diffEditor.layout();
895
- });
924
+ this.diffEditor.layout();
896
925
  });
897
926
  this.addDiffEditorEventListeners(this.diffEditor.originalEditor, 'original');
898
927
  this.addDiffEditorEventListeners(this.diffEditor.modifiedEditor, 'modified');
@@ -909,7 +938,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
909
938
  this.diffEditorReady.ready();
910
939
  }
911
940
  addDiffEditorEventListeners(editor, side) {
912
- this.addDispose(editor.onSelectionsChanged((e) => {
941
+ this.toDispose.push(editor.onSelectionsChanged((e) => {
913
942
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
914
943
  this.eventBus.fire(new types_2.EditorSelectionChangeEvent({
915
944
  group: this,
@@ -921,7 +950,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
921
950
  }));
922
951
  }
923
952
  }));
924
- this.addDispose(editor.onVisibleRangesChanged((e) => {
953
+ this.toDispose.push(editor.onVisibleRangesChanged((e) => {
925
954
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
926
955
  this.eventBus.fire(new types_2.EditorVisibleChangeEvent({
927
956
  group: this,
@@ -931,7 +960,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
931
960
  }));
932
961
  }
933
962
  }));
934
- this.addDispose(editor.onConfigurationChanged(() => {
963
+ this.toDispose.push(editor.onConfigurationChanged(() => {
935
964
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
936
965
  this.eventBus.fire(new types_2.EditorConfigurationChangedEvent({
937
966
  group: this,
@@ -1438,7 +1467,11 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
1438
1467
  this.resolveTabChanged(_resource, this.currentResource);
1439
1468
  this._currentOpenType = activeOpenType;
1440
1469
  this.notifyBodyChanged();
1441
- this.layoutEditors();
1470
+ if ((!this._codeEditorPendingLayout && activeOpenType.type === types_2.EditorOpenType.code) ||
1471
+ (!this._diffEditorPendingLayout && activeOpenType.type === types_2.EditorOpenType.diff) ||
1472
+ (!this._mergeEditorPendingLayout && activeOpenType.type === types_2.EditorOpenType.mergeEditor)) {
1473
+ this.doLayoutEditors();
1474
+ }
1442
1475
  this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1443
1476
  }
1444
1477
  }
@@ -1795,6 +1828,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
1795
1828
  super.dispose();
1796
1829
  this.codeEditor && this.codeEditor.dispose();
1797
1830
  this.diffEditor && this.diffEditor.dispose();
1831
+ this.toDispose.forEach((disposable) => disposable.dispose());
1798
1832
  this.eventBus.fire(new types_2.EditorGroupDisposeEvent({
1799
1833
  group: this,
1800
1834
  }));
@@ -1995,6 +2029,16 @@ tslib_1.__decorate([
1995
2029
  (0, di_1.Autowired)(ide_core_common_1.ILogger),
1996
2030
  tslib_1.__metadata("design:type", Object)
1997
2031
  ], EditorGroup.prototype, "logger", void 0);
2032
+ tslib_1.__decorate([
2033
+ mobx_1.observable.shallow,
2034
+ tslib_1.__metadata("design:type", Array)
2035
+ ], EditorGroup.prototype, "availableOpenTypes", void 0);
2036
+ tslib_1.__decorate([
2037
+ (0, ide_core_common_1.debounce)(16 * 5),
2038
+ tslib_1.__metadata("design:type", Function),
2039
+ tslib_1.__metadata("design:paramtypes", []),
2040
+ tslib_1.__metadata("design:returntype", void 0)
2041
+ ], EditorGroup.prototype, "doLayoutEditors", null);
1998
2042
  tslib_1.__decorate([
1999
2043
  (0, ide_core_common_1.OnEvent)(common_1.ResourceDecorationChangeEvent),
2000
2044
  tslib_1.__metadata("design:type", Function),