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