@opensumi/ide-editor 2.27.3-rc-1713515623.0 → 2.27.3-rc-1713838390.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.
Files changed (41) hide show
  1. package/lib/browser/diff/compare.d.ts.map +1 -1
  2. package/lib/browser/diff/compare.js +1 -1
  3. package/lib/browser/diff/compare.js.map +1 -1
  4. package/lib/browser/diff/index.d.ts.map +1 -1
  5. package/lib/browser/diff/index.js +2 -2
  6. package/lib/browser/diff/index.js.map +1 -1
  7. package/lib/browser/editor-collection.service.d.ts +8 -7
  8. package/lib/browser/editor-collection.service.d.ts.map +1 -1
  9. package/lib/browser/editor-collection.service.js +22 -22
  10. package/lib/browser/editor-collection.service.js.map +1 -1
  11. package/lib/browser/editor.contribution.d.ts.map +1 -1
  12. package/lib/browser/editor.contribution.js +4 -2
  13. package/lib/browser/editor.contribution.js.map +1 -1
  14. package/lib/browser/editor.view.js +3 -3
  15. package/lib/browser/editor.view.js.map +1 -1
  16. package/lib/browser/navigation.view.js +5 -5
  17. package/lib/browser/navigation.view.js.map +1 -1
  18. package/lib/browser/preference/converter.d.ts.map +1 -1
  19. package/lib/browser/preference/converter.js +11 -0
  20. package/lib/browser/preference/converter.js.map +1 -1
  21. package/lib/browser/preference/schema.d.ts +3 -0
  22. package/lib/browser/preference/schema.d.ts.map +1 -1
  23. package/lib/browser/preference/schema.js +7 -0
  24. package/lib/browser/preference/schema.js.map +1 -1
  25. package/lib/browser/tab.view.d.ts.map +1 -1
  26. package/lib/browser/tab.view.js +13 -13
  27. package/lib/browser/tab.view.js.map +1 -1
  28. package/lib/browser/workbench-editor.service.d.ts.map +1 -1
  29. package/lib/browser/workbench-editor.service.js +1 -3
  30. package/lib/browser/workbench-editor.service.js.map +1 -1
  31. package/package.json +14 -14
  32. package/src/browser/diff/compare.ts +2 -2
  33. package/src/browser/diff/index.ts +3 -2
  34. package/src/browser/editor-collection.service.ts +28 -22
  35. package/src/browser/editor.contribution.ts +5 -2
  36. package/src/browser/editor.view.tsx +3 -3
  37. package/src/browser/navigation.view.tsx +5 -5
  38. package/src/browser/preference/converter.ts +11 -0
  39. package/src/browser/preference/schema.ts +7 -0
  40. package/src/browser/tab.view.tsx +25 -13
  41. package/src/browser/workbench-editor.service.ts +1 -3
@@ -5,9 +5,11 @@ import { MonacoService } from '@opensumi/ide-core-browser/lib/monaco';
5
5
  import {
6
6
  Disposable,
7
7
  Emitter,
8
+ Event,
8
9
  Emitter as EventEmitter,
9
10
  ILineChange,
10
11
  ISelection,
12
+ LRUCache,
11
13
  OnEvent,
12
14
  URI,
13
15
  WithEventBus,
@@ -19,6 +21,7 @@ import { IConfigurationService } from '@opensumi/monaco-editor-core/esm/vs/platf
19
21
 
20
22
  import {
21
23
  CursorStatus,
24
+ DIFF_SCHEME,
22
25
  EditorCollectionService,
23
26
  EditorType,
24
27
  ICodeEditor,
@@ -559,6 +562,8 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
559
562
 
560
563
  private modifiedDocModelRef: IEditorDocumentModelRef | null;
561
564
 
565
+ private diffEditorModelCache = new LRUCache<string, monaco.editor.IDiffEditorViewModel>(100);
566
+
562
567
  get originalDocModel() {
563
568
  if (this.originalDocModelRef && !this.originalDocModelRef.disposed) {
564
569
  return this.originalDocModelRef.instance;
@@ -622,7 +627,7 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
622
627
  this.configurationService.onDidChangeConfiguration((e) => {
623
628
  const changedEditorKeys = Array.from(e.affectedKeys.values()).filter((key) => isDiffEditorOption(key));
624
629
  if (changedEditorKeys.length > 0) {
625
- this.doUpdateDiffOptions();
630
+ this.updateDiffOptions();
626
631
  }
627
632
  }),
628
633
  );
@@ -642,16 +647,20 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
642
647
  }
643
648
  const original = this.originalDocModel.getMonacoModel();
644
649
  const modified = this.modifiedDocModel.getMonacoModel();
645
- this.monacoDiffEditor.setModel({
646
- original,
647
- modified,
648
- });
650
+ const key = `${original.uri.toString()}-${modified.uri.toString()}`;
651
+ let model = this.diffEditorModelCache.get(key);
652
+ if (!model) {
653
+ model = this.monacoDiffEditor.createViewModel({ original, modified });
654
+ this.diffEditorModelCache.set(key, model);
655
+ }
656
+
657
+ this.monacoDiffEditor.setModel(model);
649
658
 
650
659
  if (rawUri) {
651
660
  this.currentUri = rawUri;
652
661
  } else {
653
662
  this.currentUri = URI.from({
654
- scheme: 'diff',
663
+ scheme: DIFF_SCHEME,
655
664
  query: URI.stringifyQuery({
656
665
  name,
657
666
  original: this.originalDocModel!.uri.toString(),
@@ -663,16 +672,15 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
663
672
  if (options.range || options.originalRange) {
664
673
  const range = (options.range || options.originalRange) as monaco.IRange;
665
674
  const currentEditor = options.range ? this.modifiedEditor.monacoEditor : this.originalEditor.monacoEditor;
666
- // 必须使用 setTimeout, 因为两边的 editor 出现时机问题,diffEditor是异步显示和渲染
675
+ // 必须使用 setTimeout, 因为两边的 editor 出现时机问题,diffEditor 是异步显示和渲染
667
676
  setTimeout(() => {
668
677
  currentEditor.revealRangeInCenter(range);
669
678
  currentEditor.setSelection(range);
670
679
  });
671
- // monaco diffEditor 在setModel后,计算diff完成后, 左侧 originalEditor 会发出一个异步的onScroll,
680
+ // monaco diffEditor 在 setModel 后,计算 diff 完成后, 左侧 originalEditor 会发出一个异步的onScroll,
672
681
  // 这个行为可能会带动右侧 modifiedEditor 进行滚动, 导致 revealRange 错位
673
- // 此处 添加一个onDidUpdateDiff 监听
674
- const disposer = this.monacoDiffEditor.onDidUpdateDiff(() => {
675
- disposer.dispose();
682
+ // 此处 添加一个 onDidUpdateDiff 监听
683
+ Event.once(this.monacoDiffEditor.onDidUpdateDiff)(() => {
676
684
  currentEditor.setSelection(range);
677
685
  setTimeout(() => {
678
686
  currentEditor.revealRangeInCenter(range);
@@ -682,14 +690,15 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
682
690
  this.restoreState();
683
691
  }
684
692
  const enableHideUnchanged = this.preferenceService.get('diffEditor.hideUnchangedRegions.enabled');
693
+
685
694
  if (options.revealFirstDiff && !enableHideUnchanged) {
686
695
  // 仅在非折叠模式下自动滚动到第一个 Diff
687
696
  const diffs = this.monacoDiffEditor.getLineChanges();
688
697
  if (diffs && diffs.length > 0) {
689
- this.showFirstDiff();
698
+ this.showFirstDiff(model);
690
699
  } else {
691
700
  const disposer = this.monacoDiffEditor.onDidUpdateDiff(() => {
692
- this.showFirstDiff();
701
+ this.showFirstDiff(model);
693
702
  disposer.dispose();
694
703
  });
695
704
  }
@@ -698,13 +707,9 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
698
707
  this.diffResourceKeys.forEach((r) => r.set(this.currentUri));
699
708
  }
700
709
 
701
- showFirstDiff() {
702
- const diffs = this.monacoDiffEditor.getLineChanges();
703
- if (diffs && diffs.length > 0) {
704
- setTimeout(() => {
705
- this.monacoDiffEditor.revealLineInCenter(diffs[0].modifiedStartLineNumber);
706
- }, 0);
707
- }
710
+ private async showFirstDiff(model?: monaco.editor.IDiffEditorViewModel) {
711
+ await model?.waitForDiff();
712
+ this.monacoDiffEditor.revealFirstDiff();
708
713
  }
709
714
 
710
715
  private async updateOptionsOnModelChange() {
@@ -741,8 +746,8 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
741
746
  }
742
747
  }
743
748
 
744
- updateDiffOptions(options: Partial<monaco.editor.IDiffEditorOptions>) {
745
- this.specialOptions = removeUndefined({ ...this.specialOptions, ...options });
749
+ updateDiffOptions() {
750
+ this.diffEditorModelCache.clear();
746
751
  this.doUpdateDiffOptions();
747
752
  }
748
753
 
@@ -812,6 +817,7 @@ export class BrowserDiffEditor extends WithEventBus implements IDiffEditor {
812
817
  super.dispose();
813
818
  this.collectionService.removeEditors([this.originalEditor, this.modifiedEditor]);
814
819
  this.collectionService.removeDiffEditors([this]);
820
+ this.diffEditorModelCache.clear();
815
821
  this.monacoDiffEditor.dispose();
816
822
  this._disposed = true;
817
823
  }
@@ -56,6 +56,7 @@ import { ContextKeyExpr } from '@opensumi/monaco-editor-core/esm/vs/platform/con
56
56
  import { SyncDescriptor } from '@opensumi/monaco-editor-core/esm/vs/platform/instantiation/common/descriptors';
57
57
 
58
58
  import {
59
+ DIFF_SCHEME,
59
60
  Direction,
60
61
  EditorGroupSplitAction,
61
62
  IDocPersistentCacheProvider,
@@ -509,7 +510,7 @@ export class EditorContribution
509
510
  name = name || `${original.displayName} <=> ${modified.displayName}`;
510
511
  return this.workbenchEditorService.open(
511
512
  URI.from({
512
- scheme: 'diff',
513
+ scheme: DIFF_SCHEME,
513
514
  query: URI.stringifyQuery({
514
515
  name,
515
516
  original,
@@ -881,7 +882,9 @@ export class EditorContribution
881
882
  }
882
883
 
883
884
  const uris =
884
- resource.uri.scheme === 'diff' ? [resource.metadata.original, resource.metadata.modified] : [resource.uri];
885
+ resource.uri.scheme === DIFF_SCHEME
886
+ ? [resource.metadata.original, resource.metadata.modified]
887
+ : [resource.uri];
885
888
  uris.forEach((uri) => {
886
889
  this.editorDocumentModelService.changeModelOptions(uri, {
887
890
  encoding: selectedFileEncoding,
@@ -58,7 +58,7 @@ export const EditorView = () => {
58
58
  const rightWidgetInfo = componentRegistry.getComponentRegistryInfo('editor-widget-right');
59
59
  const RightWidget: React.ComponentType<any> | undefined = rightWidgetInfo && rightWidgetInfo.views[0].component;
60
60
  const [ready, setReady] = React.useState<boolean>(workbenchEditorService.gridReady);
61
- const styles_kt_workbench_editor = useDesignStyles(styles.kt_workbench_editor);
61
+ const styles_kt_workbench_editor = useDesignStyles(styles.kt_workbench_editor, 'kt_workbench_editor');
62
62
 
63
63
  React.useEffect(() => {
64
64
  if (!ready) {
@@ -240,7 +240,7 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
240
240
 
241
241
  const preferenceService = useInjectable(PreferenceService) as PreferenceService;
242
242
  const [isEmpty, setIsEmpty] = React.useState(group.resources.length === 0);
243
- const styles_kt_editor_group = useDesignStyles(styles.kt_editor_group);
243
+ const styles_kt_editor_group = useDesignStyles(styles.kt_editor_group, 'kt_editor_group');
244
244
 
245
245
  const appConfig = useInjectable(AppConfig);
246
246
  const { editorBackgroundImage } = appConfig;
@@ -327,7 +327,7 @@ export const EditorGroupBody = observer(({ group }: { group: EditorGroup }) => {
327
327
  const editorBodyRef = React.useRef<HTMLDivElement>(null);
328
328
  const editorService = useInjectable(WorkbenchEditorService) as WorkbenchEditorServiceImpl;
329
329
  const eventBus = useInjectable(IEventBus) as IEventBus;
330
- const styles_kt_editor_component = useDesignStyles(styles.kt_editor_component);
330
+ const styles_kt_editor_component = useDesignStyles(styles.kt_editor_component, 'kt_editor_component');
331
331
  const components: React.ReactNode[] = [];
332
332
  const codeEditorRef = React.useRef<HTMLDivElement>(null);
333
333
  const diffEditorRef = React.useRef<HTMLDivElement>(null);
@@ -22,8 +22,8 @@ import { EditorGroup } from './workbench-editor.service';
22
22
 
23
23
  export const NavigationBar = ({ editorGroup }: { editorGroup: EditorGroup }) => {
24
24
  const breadCrumbService = useInjectable<IBreadCrumbService>(IBreadCrumbService);
25
- const styles_navigation_container = useDesignStyles(styles.navigation_container);
26
- const styles_navigation_icon = useDesignStyles(styles.navigation_icon);
25
+ const styles_navigation_container = useDesignStyles(styles.navigation_container, 'navigation_container');
26
+ const styles_navigation_icon = useDesignStyles(styles.navigation_icon, 'navigation_icon');
27
27
 
28
28
  useUpdateOnGroupTabChange(editorGroup);
29
29
 
@@ -74,7 +74,7 @@ export const NavigationItem = memo(({ part, editorGroup }: { part: IBreadCrumbPa
74
74
  const viewService = useInjectable<NavigationBarViewService>(NavigationBarViewService);
75
75
  const breadcrumbsMenuService = useInjectable<BreadCrumbsMenuService>(BreadCrumbsMenuService);
76
76
  const itemRef = useRef<HTMLSpanElement>();
77
- const styles_navigation_part = useDesignStyles(styles['navigation-part']);
77
+ const styles_navigation_part = useDesignStyles(styles['navigation-part'], 'navigation-part');
78
78
 
79
79
  const onClick = useCallback(async () => {
80
80
  if (part.getSiblings && itemRef.current) {
@@ -117,8 +117,8 @@ export const NavigationMenu = observer(({ model }: { model: NavigationMenuModel
117
117
  }
118
118
 
119
119
  const scrollerContainer = useRef<HTMLDivElement | null>();
120
- const styles_navigation_menu = useDesignStyles(styles.navigation_menu);
121
- const styles_navigation_menu_item = useDesignStyles(styles.navigation_menu_item);
120
+ const styles_navigation_menu = useDesignStyles(styles.navigation_menu, 'navigation_menu');
121
+ const styles_navigation_menu_item = useDesignStyles(styles.navigation_menu_item, 'navigation_menu_item');
122
122
  const viewService = useInjectable(NavigationBarViewService) as NavigationBarViewService;
123
123
 
124
124
  const scrollToCurrent = useCallback(() => {
@@ -820,6 +820,17 @@ export const diffEditorOptionsConverters: Map<KaitianPreferenceKey, NoConverter
820
820
  }),
821
821
  },
822
822
  ],
823
+ [
824
+ 'diffEditor.experimental.stickyScroll.enabled',
825
+ {
826
+ monaco: 'experimental',
827
+ convert: (value) => ({
828
+ stickyScroll: {
829
+ enabled: value,
830
+ },
831
+ }),
832
+ },
833
+ ],
823
834
 
824
835
  /**
825
836
  * Controls whether the diff editor shows unchanged regions.
@@ -256,6 +256,9 @@ export const DIFF_EDITOR_DEFAULTS = {
256
256
  showMoves: false,
257
257
  showEmptyDecorations: true,
258
258
  collapseUnchangedRegions: true,
259
+ stickyScroll: {
260
+ enable: false,
261
+ },
259
262
  },
260
263
  };
261
264
 
@@ -1452,6 +1455,10 @@ const monacoEditorSchema: PreferenceSchemaProperties = {
1452
1455
  type: 'boolean',
1453
1456
  default: DIFF_EDITOR_DEFAULTS.minimap,
1454
1457
  },
1458
+ 'diffEditor.experimental.stickyScroll.enabled': {
1459
+ type: 'boolean',
1460
+ default: DIFF_EDITOR_DEFAULTS.experimental.stickyScroll.enable,
1461
+ },
1455
1462
  };
1456
1463
 
1457
1464
  const customEditorSchema: PreferenceSchemaProperties = {
@@ -72,18 +72,30 @@ export const Tabs = ({ group }: ITabsProps) => {
72
72
  const editorTabService = useInjectable<IEditorTabService>(IEditorTabService);
73
73
  const appConfig = useInjectable<AppConfig>(AppConfig);
74
74
 
75
- const styles_tab_right = useDesignStyles(styles.tab_right);
76
- const styles_close_tab = useDesignStyles(styles.close_tab);
77
- const styles_kt_editor_close_icon = useDesignStyles(styles.kt_editor_close_icon);
78
- const styles_kt_editor_tabs_content = useDesignStyles(styles.kt_editor_tabs_content);
79
- const styles_kt_editor_tabs_current_last = useDesignStyles(styles.kt_editor_tabs_current_last);
80
- const styles_kt_editor_tab = useDesignStyles(styles.kt_editor_tab);
81
- const styles_kt_editor_tab_current_prev = useDesignStyles(styles.kt_editor_tab_current_prev);
82
- const styles_kt_editor_tab_current_next = useDesignStyles(styles.kt_editor_tab_current_next);
83
- const styles_kt_editor_tab_current = useDesignStyles(styles.kt_editor_tab_current);
84
- const styles_kt_editor_tab_dirty = useDesignStyles(styles.kt_editor_tab_dirty);
85
- const styles_kt_editor_tabs = useDesignStyles(styles.kt_editor_tabs);
86
- const styles_kt_editor_tabs_scroll_wrapper = useDesignStyles(styles.kt_editor_tabs_scroll_wrapper);
75
+ const styles_tab_right = useDesignStyles(styles.tab_right, 'tab_right');
76
+ const styles_close_tab = useDesignStyles(styles.close_tab, 'close_tab');
77
+ const styles_kt_editor_close_icon = useDesignStyles(styles.kt_editor_close_icon, 'kt_editor_close_icon');
78
+ const styles_kt_editor_tabs_content = useDesignStyles(styles.kt_editor_tabs_content, 'kt_editor_tabs_content');
79
+ const styles_kt_editor_tabs_current_last = useDesignStyles(
80
+ styles.kt_editor_tabs_current_last,
81
+ 'kt_editor_tabs_current_last',
82
+ );
83
+ const styles_kt_editor_tab = useDesignStyles(styles.kt_editor_tab, 'kt_editor_tab');
84
+ const styles_kt_editor_tab_current_prev = useDesignStyles(
85
+ styles.kt_editor_tab_current_prev,
86
+ 'kt_editor_tab_current_prev',
87
+ );
88
+ const styles_kt_editor_tab_current_next = useDesignStyles(
89
+ styles.kt_editor_tab_current_next,
90
+ 'kt_editor_tab_current_next',
91
+ );
92
+ const styles_kt_editor_tab_current = useDesignStyles(styles.kt_editor_tab_current, 'kt_editor_tab_current');
93
+ const styles_kt_editor_tab_dirty = useDesignStyles(styles.kt_editor_tab_dirty, 'kt_editor_tab_dirty');
94
+ const styles_kt_editor_tabs = useDesignStyles(styles.kt_editor_tabs, 'kt_editor_tabs');
95
+ const styles_kt_editor_tabs_scroll_wrapper = useDesignStyles(
96
+ styles.kt_editor_tabs_scroll_wrapper,
97
+ 'kt_editor_tabs_scroll_wrapper',
98
+ );
87
99
 
88
100
  const [tabsLoadingMap, setTabsLoadingMap] = useState<{ [resource: string]: boolean }>({});
89
101
  const [wrapMode, setWrapMode] = useState<boolean>(!!preferenceService.get<boolean>('editor.wrapTab'));
@@ -500,7 +512,7 @@ export type IEditorActionsProps = IEditorActionsBaseProps & HTMLAttributes<HTMLD
500
512
 
501
513
  export const EditorActions = forwardRef<HTMLDivElement, IEditorActionsProps>(
502
514
  (props: IEditorActionsProps, ref: Ref<typeof EditorActions>) => {
503
- const styles_editor_actions = useDesignStyles(styles.editor_actions);
515
+ const styles_editor_actions = useDesignStyles(styles.editor_actions, 'editor_actions');
504
516
  const { group, className } = props;
505
517
 
506
518
  const acquireArgs = useCallback(
@@ -1530,9 +1530,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1530
1530
 
1531
1531
  disposeDocumentRef(uri: URI) {
1532
1532
  if (uri.scheme === 'diff') {
1533
- const query = uri.getParsedQuery();
1534
- this.doDisposeDocRef(new URI(query.original));
1535
- this.doDisposeDocRef(new URI(query.modified));
1533
+ // 针对 diff 编辑器,需要保留 DocumentModelRef,以保留实现对 DiffEditor 的状态恢复
1536
1534
  } else if (uri.scheme === 'mergeEditor') {
1537
1535
  this.mergeEditor.dispose();
1538
1536
  } else {