@opensumi/ide-editor 3.3.0 → 3.3.1-next-1725288439.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,48 +585,30 @@ 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();
615
591
  }
616
592
  });
617
593
  }
618
- _layoutEditorWorker() {
594
+ doLayoutEditors() {
619
595
  if (this.codeEditor) {
620
596
  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;
597
+ this.codeEditor.layout({
598
+ width: this._prevDomWidth,
599
+ height: this._prevDomHeight,
600
+ }, true);
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;
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;
605
+ this.diffEditor.layout({
606
+ width: this._prevDomWidth,
607
+ height: this._prevDomHeight,
608
+ }, true);
644
609
  }
645
610
  }
646
611
  }
647
- doLayoutEditors() {
648
- this._layoutEditorWorker();
649
- }
650
612
  setContextKeys() {
651
613
  var _a;
652
614
  if (!this._resourceContext) {
@@ -865,15 +827,17 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
865
827
  [ide_core_browser_1.ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
866
828
  });
867
829
  setTimeout(() => {
868
- this.codeEditor.layout();
830
+ ide_core_browser_1.fastdom.mutate(() => {
831
+ this.codeEditor.layout();
832
+ });
869
833
  });
870
834
  this.addDispose(this.codeEditor.onRefOpen(() => {
871
835
  this.codeEditor.layout();
872
836
  }));
873
- this.toDispose.push(this.codeEditor.onCursorPositionChanged((e) => {
837
+ this.addDispose(this.codeEditor.onCursorPositionChanged((e) => {
874
838
  this._onCurrentEditorCursorChange.fire(e);
875
839
  }));
876
- this.toDispose.push(this.codeEditor.onSelectionsChanged((e) => {
840
+ this.addDispose(this.codeEditor.onSelectionsChanged((e) => {
877
841
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
878
842
  this.eventBus.fire(new types_2.EditorSelectionChangeEvent({
879
843
  group: this,
@@ -884,7 +848,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
884
848
  }));
885
849
  }
886
850
  }));
887
- this.toDispose.push(this.codeEditor.onVisibleRangesChanged((e) => {
851
+ this.addDispose(this.codeEditor.onVisibleRangesChanged((e) => {
888
852
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
889
853
  this.eventBus.fire(new types_2.EditorVisibleChangeEvent({
890
854
  group: this,
@@ -894,7 +858,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
894
858
  }));
895
859
  }
896
860
  }));
897
- this.toDispose.push(this.codeEditor.onConfigurationChanged(() => {
861
+ this.addDispose(this.codeEditor.onConfigurationChanged(() => {
898
862
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.code) {
899
863
  this.eventBus.fire(new types_2.EditorConfigurationChangedEvent({
900
864
  group: this,
@@ -921,7 +885,14 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
921
885
  [ide_core_browser_1.ServiceNames.CONTEXT_KEY_SERVICE]: this.contextKeyService.contextKeyService,
922
886
  });
923
887
  setTimeout(() => {
924
- this.diffEditor.layout();
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
+ });
925
896
  });
926
897
  this.addDiffEditorEventListeners(this.diffEditor.originalEditor, 'original');
927
898
  this.addDiffEditorEventListeners(this.diffEditor.modifiedEditor, 'modified');
@@ -938,7 +909,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
938
909
  this.diffEditorReady.ready();
939
910
  }
940
911
  addDiffEditorEventListeners(editor, side) {
941
- this.toDispose.push(editor.onSelectionsChanged((e) => {
912
+ this.addDispose(editor.onSelectionsChanged((e) => {
942
913
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
943
914
  this.eventBus.fire(new types_2.EditorSelectionChangeEvent({
944
915
  group: this,
@@ -950,7 +921,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
950
921
  }));
951
922
  }
952
923
  }));
953
- this.toDispose.push(editor.onVisibleRangesChanged((e) => {
924
+ this.addDispose(editor.onVisibleRangesChanged((e) => {
954
925
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
955
926
  this.eventBus.fire(new types_2.EditorVisibleChangeEvent({
956
927
  group: this,
@@ -960,7 +931,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
960
931
  }));
961
932
  }
962
933
  }));
963
- this.toDispose.push(editor.onConfigurationChanged(() => {
934
+ this.addDispose(editor.onConfigurationChanged(() => {
964
935
  if (this.currentOpenType && this.currentOpenType.type === types_2.EditorOpenType.diff) {
965
936
  this.eventBus.fire(new types_2.EditorConfigurationChangedEvent({
966
937
  group: this,
@@ -1467,11 +1438,7 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
1467
1438
  this.resolveTabChanged(_resource, this.currentResource);
1468
1439
  this._currentOpenType = activeOpenType;
1469
1440
  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
- }
1441
+ this.layoutEditors();
1475
1442
  this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1476
1443
  }
1477
1444
  }
@@ -1828,7 +1795,6 @@ let EditorGroup = class EditorGroup extends ide_core_common_1.WithEventBus {
1828
1795
  super.dispose();
1829
1796
  this.codeEditor && this.codeEditor.dispose();
1830
1797
  this.diffEditor && this.diffEditor.dispose();
1831
- this.toDispose.forEach((disposable) => disposable.dispose());
1832
1798
  this.eventBus.fire(new types_2.EditorGroupDisposeEvent({
1833
1799
  group: this,
1834
1800
  }));
@@ -2029,16 +1995,6 @@ tslib_1.__decorate([
2029
1995
  (0, di_1.Autowired)(ide_core_common_1.ILogger),
2030
1996
  tslib_1.__metadata("design:type", Object)
2031
1997
  ], 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
1998
  tslib_1.__decorate([
2043
1999
  (0, ide_core_common_1.OnEvent)(common_1.ResourceDecorationChangeEvent),
2044
2000
  tslib_1.__metadata("design:type", Function),