@theia/core 1.77.0-next.88 → 1.77.0-next.89

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 (134) hide show
  1. package/lib/browser/catalog.json +12 -0
  2. package/lib/browser/color-application-contribution.d.ts +2 -2
  3. package/lib/browser/color-application-contribution.d.ts.map +1 -1
  4. package/lib/browser/color-application-contribution.js +7 -8
  5. package/lib/browser/color-application-contribution.js.map +1 -1
  6. package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
  7. package/lib/browser/common-frontend-contribution.js +7 -0
  8. package/lib/browser/common-frontend-contribution.js.map +1 -1
  9. package/lib/browser/frontend-application-module.d.ts.map +1 -1
  10. package/lib/browser/frontend-application-module.js +6 -0
  11. package/lib/browser/frontend-application-module.js.map +1 -1
  12. package/lib/browser/quick-input/quick-command-service.d.ts +2 -0
  13. package/lib/browser/quick-input/quick-command-service.d.ts.map +1 -1
  14. package/lib/browser/quick-input/quick-command-service.js +10 -2
  15. package/lib/browser/quick-input/quick-command-service.js.map +1 -1
  16. package/lib/browser/saveable-service.d.ts +4 -0
  17. package/lib/browser/saveable-service.d.ts.map +1 -1
  18. package/lib/browser/saveable-service.js +7 -0
  19. package/lib/browser/saveable-service.js.map +1 -1
  20. package/lib/browser/secondary-window-handler.d.ts +126 -3
  21. package/lib/browser/secondary-window-handler.d.ts.map +1 -1
  22. package/lib/browser/secondary-window-handler.js +354 -30
  23. package/lib/browser/secondary-window-handler.js.map +1 -1
  24. package/lib/browser/shell/application-shell-mouse-tracker.d.ts +2 -0
  25. package/lib/browser/shell/application-shell-mouse-tracker.d.ts.map +1 -1
  26. package/lib/browser/shell/application-shell-mouse-tracker.js +10 -0
  27. package/lib/browser/shell/application-shell-mouse-tracker.js.map +1 -1
  28. package/lib/browser/shell/application-shell.d.ts +11 -0
  29. package/lib/browser/shell/application-shell.d.ts.map +1 -1
  30. package/lib/browser/shell/application-shell.js +33 -4
  31. package/lib/browser/shell/application-shell.js.map +1 -1
  32. package/lib/browser/shell/index.d.ts +1 -0
  33. package/lib/browser/shell/index.d.ts.map +1 -1
  34. package/lib/browser/shell/index.js +1 -0
  35. package/lib/browser/shell/index.js.map +1 -1
  36. package/lib/browser/shell/native-tab-drag-service.d.ts +141 -0
  37. package/lib/browser/shell/native-tab-drag-service.d.ts.map +1 -0
  38. package/lib/browser/shell/native-tab-drag-service.js +349 -0
  39. package/lib/browser/shell/native-tab-drag-service.js.map +1 -0
  40. package/lib/browser/shell/native-tab-drag-service.spec.d.ts +2 -0
  41. package/lib/browser/shell/native-tab-drag-service.spec.d.ts.map +1 -0
  42. package/lib/browser/shell/native-tab-drag-service.spec.js +71 -0
  43. package/lib/browser/shell/native-tab-drag-service.spec.js.map +1 -0
  44. package/lib/browser/shell/shell-layout-restorer.d.ts +3 -0
  45. package/lib/browser/shell/shell-layout-restorer.d.ts.map +1 -1
  46. package/lib/browser/shell/shell-layout-restorer.js +20 -0
  47. package/lib/browser/shell/shell-layout-restorer.js.map +1 -1
  48. package/lib/browser/shell/shell-layout-restorer.spec.js +31 -0
  49. package/lib/browser/shell/shell-layout-restorer.spec.js.map +1 -1
  50. package/lib/browser/shell/side-panel-handler.d.ts +8 -0
  51. package/lib/browser/shell/side-panel-handler.d.ts.map +1 -1
  52. package/lib/browser/shell/side-panel-handler.js +14 -0
  53. package/lib/browser/shell/side-panel-handler.js.map +1 -1
  54. package/lib/browser/shell/tab-bars.d.ts +39 -0
  55. package/lib/browser/shell/tab-bars.d.ts.map +1 -1
  56. package/lib/browser/shell/tab-bars.js +127 -2
  57. package/lib/browser/shell/tab-bars.js.map +1 -1
  58. package/lib/browser/shell/tab-bars.spec.js +48 -0
  59. package/lib/browser/shell/tab-bars.spec.js.map +1 -1
  60. package/lib/browser/shell/tab-drop-helper.d.ts +32 -0
  61. package/lib/browser/shell/tab-drop-helper.d.ts.map +1 -0
  62. package/lib/browser/shell/tab-drop-helper.js +75 -0
  63. package/lib/browser/shell/tab-drop-helper.js.map +1 -0
  64. package/lib/browser/shell/theia-dock-panel.d.ts +25 -0
  65. package/lib/browser/shell/theia-dock-panel.d.ts.map +1 -1
  66. package/lib/browser/shell/theia-dock-panel.js +107 -11
  67. package/lib/browser/shell/theia-dock-panel.js.map +1 -1
  68. package/lib/browser/styling-service.d.ts +2 -2
  69. package/lib/browser/styling-service.d.ts.map +1 -1
  70. package/lib/browser/styling-service.js +7 -8
  71. package/lib/browser/styling-service.js.map +1 -1
  72. package/lib/browser/widget-open-handler.d.ts +10 -0
  73. package/lib/browser/widget-open-handler.d.ts.map +1 -1
  74. package/lib/browser/widget-open-handler.js +24 -1
  75. package/lib/browser/widget-open-handler.js.map +1 -1
  76. package/lib/browser/window/default-secondary-window-service.d.ts +17 -3
  77. package/lib/browser/window/default-secondary-window-service.d.ts.map +1 -1
  78. package/lib/browser/window/default-secondary-window-service.js +76 -23
  79. package/lib/browser/window/default-secondary-window-service.js.map +1 -1
  80. package/lib/browser/window/default-secondary-window-service.spec.d.ts +2 -0
  81. package/lib/browser/window/default-secondary-window-service.spec.d.ts.map +1 -0
  82. package/lib/browser/window/default-secondary-window-service.spec.js +49 -0
  83. package/lib/browser/window/default-secondary-window-service.spec.js.map +1 -0
  84. package/lib/browser/window/secondary-window-close-contribution.d.ts +23 -0
  85. package/lib/browser/window/secondary-window-close-contribution.d.ts.map +1 -0
  86. package/lib/browser/window/secondary-window-close-contribution.js +39 -0
  87. package/lib/browser/window/secondary-window-close-contribution.js.map +1 -0
  88. package/lib/browser/window/secondary-window-service.d.ts +24 -1
  89. package/lib/browser/window/secondary-window-service.d.ts.map +1 -1
  90. package/lib/browser/window/secondary-window-service.js.map +1 -1
  91. package/lib/browser/window/window-focus-service.d.ts +4 -0
  92. package/lib/browser/window/window-focus-service.d.ts.map +1 -1
  93. package/lib/browser/window/window-focus-service.js +8 -2
  94. package/lib/browser/window/window-focus-service.js.map +1 -1
  95. package/lib/common/core-preferences.d.ts +2 -0
  96. package/lib/common/core-preferences.d.ts.map +1 -1
  97. package/lib/common/core-preferences.js +15 -0
  98. package/lib/common/core-preferences.js.map +1 -1
  99. package/lib/electron-browser/menu/electron-context-menu-renderer.d.ts.map +1 -1
  100. package/lib/electron-browser/menu/electron-context-menu-renderer.js +2 -1
  101. package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
  102. package/lib/electron-browser/window/electron-secondary-window-service.d.ts.map +1 -1
  103. package/lib/electron-browser/window/electron-secondary-window-service.js +1 -0
  104. package/lib/electron-browser/window/electron-secondary-window-service.js.map +1 -1
  105. package/package.json +4 -4
  106. package/src/browser/color-application-contribution.ts +6 -7
  107. package/src/browser/common-frontend-contribution.ts +8 -0
  108. package/src/browser/frontend-application-module.ts +6 -0
  109. package/src/browser/quick-input/quick-command-service.ts +8 -2
  110. package/src/browser/saveable-service.ts +8 -0
  111. package/src/browser/secondary-window-handler.ts +397 -34
  112. package/src/browser/shell/application-shell-mouse-tracker.ts +10 -0
  113. package/src/browser/shell/application-shell.ts +38 -5
  114. package/src/browser/shell/index.ts +1 -0
  115. package/src/browser/shell/native-tab-drag-service.spec.ts +86 -0
  116. package/src/browser/shell/native-tab-drag-service.ts +402 -0
  117. package/src/browser/shell/shell-layout-restorer.spec.ts +42 -0
  118. package/src/browser/shell/shell-layout-restorer.ts +20 -0
  119. package/src/browser/shell/side-panel-handler.ts +15 -0
  120. package/src/browser/shell/tab-bars.spec.ts +56 -2
  121. package/src/browser/shell/tab-bars.ts +146 -3
  122. package/src/browser/shell/tab-drop-helper.ts +79 -0
  123. package/src/browser/shell/theia-dock-panel.ts +122 -11
  124. package/src/browser/style/dockpanel.css +9 -0
  125. package/src/browser/styling-service.ts +6 -7
  126. package/src/browser/widget-open-handler.ts +24 -3
  127. package/src/browser/window/default-secondary-window-service.spec.ts +54 -0
  128. package/src/browser/window/default-secondary-window-service.ts +78 -26
  129. package/src/browser/window/secondary-window-close-contribution.ts +47 -0
  130. package/src/browser/window/secondary-window-service.ts +20 -1
  131. package/src/browser/window/window-focus-service.ts +9 -2
  132. package/src/common/core-preferences.ts +19 -0
  133. package/src/electron-browser/menu/electron-context-menu-renderer.ts +2 -1
  134. package/src/electron-browser/window/electron-secondary-window-service.ts +1 -0
@@ -30,6 +30,7 @@ import { WindowService } from '../window/window-service';
30
30
  import { StopReason } from '../../common/frontend-application-state';
31
31
  import { isFunction, isObject, MaybePromise } from '../../common';
32
32
  import { PerspectiveServiceInternal } from '../perspective-service';
33
+ import { SecondaryWindowHandler } from '../secondary-window-handler';
33
34
 
34
35
  /**
35
36
  * A contract for widgets that want to store and restore their inner state, between sessions.
@@ -156,6 +157,9 @@ export class ShellLayoutRestorer implements CommandContribution {
156
157
  @inject(SidePanelItemVisibility)
157
158
  protected readonly sidePanelItemVisibility: SidePanelItemVisibility;
158
159
 
160
+ @inject(SecondaryWindowHandler)
161
+ protected readonly secondaryWindowHandler: SecondaryWindowHandler;
162
+
159
163
  constructor(
160
164
  @inject(WidgetManager) protected widgetManager: WidgetManager,
161
165
  @inject(ILogger) @named('core:ShellLayoutRestorer')
@@ -202,6 +206,10 @@ export class ShellLayoutRestorer implements CommandContribution {
202
206
  // Snapshot current shell as the active perspective's layout
203
207
  try {
204
208
  const currentLayout = app.shell.getLayoutData();
209
+ const secondaryWindows = this.secondaryWindowHandler.getLayoutData();
210
+ if (secondaryWindows.length) {
211
+ currentLayout.secondaryWindows = secondaryWindows;
212
+ }
205
213
  layouts[activeId] = this.deflate(currentLayout);
206
214
  } catch (error) {
207
215
  this.logger.warn(`Could not deflate layout for active perspective '${activeId}'`, error);
@@ -307,6 +315,7 @@ export class ShellLayoutRestorer implements CommandContribution {
307
315
 
308
316
  if (activeLayout) {
309
317
  await app.shell.setLayoutData(activeLayout);
318
+ this.restoreSecondaryWindows(activeLayout);
310
319
  const restoredId = this.perspectiveService.getActivePerspectiveId();
311
320
  this.perspectiveService.onLayoutRestored(restoredId);
312
321
  this.logger.info('<<< The layout has been successfully restored.');
@@ -319,6 +328,17 @@ export class ShellLayoutRestorer implements CommandContribution {
319
328
  return false;
320
329
  }
321
330
 
331
+ protected restoreSecondaryWindows(layout: ApplicationShell.LayoutData): void {
332
+ const { secondaryWindows } = layout;
333
+ if (secondaryWindows) {
334
+ // the windows are restored on startup only, not when switching to the perspective later on
335
+ delete layout.secondaryWindows;
336
+ this.secondaryWindowHandler.setLayoutData(secondaryWindows).catch(error => {
337
+ this.logger.warn('Could not restore the secondary windows', error);
338
+ });
339
+ }
340
+ }
341
+
322
342
  protected isWidgetProperty(propertyName: string): boolean {
323
343
  return propertyName === 'widget';
324
344
  }
@@ -195,6 +195,7 @@ export class SidePanelHandler {
195
195
  // even when it turns out hidden, the same as opening a hidden item.
196
196
  this.itemVisibility.onDidReset(() => sideBar.update());
197
197
  this.itemVisibility.ready.then(() => sideBar.update());
198
+ sideBar.widgetDropped.connect(this.onWidgetDropped, this);
198
199
  return sideBar;
199
200
  }
200
201
 
@@ -728,6 +729,20 @@ export class SidePanelHandler {
728
729
  });
729
730
  }
730
731
 
732
+ /**
733
+ * Handle a `widgetDropped` signal from the sidebar. The widget is moved to this side panel, if necessary,
734
+ * and its tab is moved to the position where it was dropped.
735
+ */
736
+ protected onWidgetDropped(sender: SideTabBar, { widget, index }: { widget: Widget, index: number }): void {
737
+ const previousIndex = this.tabBar.titles.indexOf(widget.title);
738
+ if (previousIndex === -1) {
739
+ // inserts the tab according to the widget's rank, see `onWidgetAdded`
740
+ this.dockPanel.addWidget(widget);
741
+ }
742
+ this.tabBar.insertTab(previousIndex !== -1 && index > previousIndex ? index - 1 : index, widget.title);
743
+ this.activate(widget.id);
744
+ }
745
+
731
746
  protected onTabsOverflowChanged(sender: SideTabBar, event: { titles: Title<Widget>[], startIndex: number }): void {
732
747
  if (event.startIndex > 0 && event.startIndex <= sender.currentIndex) {
733
748
  sender.revealTab(sender.currentIndex);
@@ -18,11 +18,25 @@ import { enableJSDOM } from '../test/jsdom';
18
18
  let disableJSDOM = enableJSDOM();
19
19
  import { expect } from 'chai';
20
20
 
21
- import { Title, Widget } from '@lumino/widgets';
22
- import { SideTabBar, TabBarRenderer } from './tab-bars';
21
+ import { MessageLoop } from '@lumino/messaging';
22
+ import { TabBar, Title, Widget } from '@lumino/widgets';
23
+ import { BreadcrumbsRenderer } from '../breadcrumbs/breadcrumbs-renderer';
24
+ import { NativeTabDragService } from './native-tab-drag-service';
25
+ import { TabBarToolbar, TabBarToolbarRegistry } from './tab-bar-toolbar';
26
+ import { SideTabBar, TabBarRenderer, ToolbarAwareTabBar } from './tab-bars';
23
27
 
24
28
  disableJSDOM();
25
29
 
30
+ /** A toolbar without items, it does not need the services that it would get injected otherwise */
31
+ class EmptyTabBarToolbar extends TabBarToolbar {
32
+ override updateTarget(): void { }
33
+ }
34
+
35
+ /** Breadcrumbs that are never shown, they do not need the services that they would get injected otherwise */
36
+ class EmptyBreadcrumbsRenderer extends BreadcrumbsRenderer {
37
+ override async refresh(): Promise<void> { }
38
+ }
39
+
26
40
  describe('tab bar', () => {
27
41
 
28
42
  before(() => {
@@ -155,4 +169,44 @@ describe('tab bar', () => {
155
169
  expect(bar.firstOverflowingIndex()).to.equal(-1);
156
170
  });
157
171
  });
172
+
173
+ describe('native tab drag', () => {
174
+
175
+ function addTab(tabBar: TabBar<Widget>): HTMLElement {
176
+ tabBar.addTab(new Widget().title);
177
+ MessageLoop.sendMessage(tabBar, Widget.Msg.UpdateRequest);
178
+ const tab = tabBar.contentNode.children[0] as HTMLElement;
179
+ tab.getBoundingClientRect = () => new DOMRect(0, 0, 100, 20);
180
+ return tab;
181
+ }
182
+
183
+ function pressTab(tabBar: TabBar<Widget>, tab: HTMLElement): MouseEvent {
184
+ const event = new MouseEvent('pointerdown', { button: 0, clientX: 10, clientY: 10, cancelable: true });
185
+ Object.defineProperty(event, 'target', { value: tab });
186
+ tabBar.handleEvent(event);
187
+ return event;
188
+ }
189
+
190
+ // Native tab drags rely on skipping Lumino's `preventDefault`, see `ToolbarAwareTabBar.handleNativeTabDragEvent`.
191
+ // If Lumino stops preventing the default action of tab presses, that override can be removed.
192
+ it('Lumino should prevent the default action of a press on a tab', () => {
193
+ const tabBar = new TabBar<Widget>();
194
+ try {
195
+ expect(pressTab(tabBar, addTab(tabBar)).defaultPrevented).to.be.true;
196
+ } finally {
197
+ tabBar.dispose();
198
+ }
199
+ });
200
+
201
+ it('should not prevent the default action of a press on a tab when native tab drag is enabled', () => {
202
+ const tabBar = new ToolbarAwareTabBar(new TabBarToolbarRegistry(), () => new EmptyTabBarToolbar(), () => new EmptyBreadcrumbsRenderer());
203
+ try {
204
+ tabBar.nativeTabDragService = {} as NativeTabDragService;
205
+ tabBar.enableNativeTabDrag();
206
+ expect(pressTab(tabBar, addTab(tabBar)).defaultPrevented).to.be.false;
207
+ } finally {
208
+ tabBar.dispose();
209
+ }
210
+ });
211
+ });
158
212
  });
@@ -40,6 +40,8 @@ import { createElement } from 'react';
40
40
  import { PreviewableWidget } from '../widgets/previewable-widget';
41
41
  import { EnhancedPreviewWidget } from '../widgets/enhanced-preview-widget';
42
42
  import { isContextMenuEvent } from '../browser';
43
+ import { NativeTabDragService } from './native-tab-drag-service';
44
+ import { TabDropHelper } from './tab-drop-helper';
43
45
  import { ContextKeyService } from '../context-key-service';
44
46
 
45
47
  /** The class name added to hidden content nodes, which are required to render vertical side bars. */
@@ -204,10 +206,12 @@ export class TabBarRenderer extends TabBar.Renderer {
204
206
  });
205
207
 
206
208
  const tabContents = tabCloseIconStart ? [tabCloseIcon, tabLabel] : [tabLabel, tabCloseIcon];
209
+ const draggable = this.tabBar instanceof ToolbarAwareTabBar && this.tabBar.isNativeTabDragEnabled ? { draggable: 'true' } : {};
207
210
 
208
211
  return h.li(
209
212
  {
210
213
  ...hover,
214
+ ...draggable,
211
215
  key, className, id, style, dataset,
212
216
  oncontextmenu: this.handleContextMenuEvent,
213
217
  ondblclick: this.handleDblClickEvent,
@@ -1016,6 +1020,93 @@ export class ToolbarAwareTabBar extends ScrollableTabBar {
1016
1020
  this.dockPanel = panel;
1017
1021
  }
1018
1022
 
1023
+ /**
1024
+ * The service used to drag tabs with native drag and drop. Tabs are only dragged natively once
1025
+ * {@link enableNativeTabDrag} has been called.
1026
+ */
1027
+ nativeTabDragService: NativeTabDragService | undefined;
1028
+ protected nativeTabDragEnabled = false;
1029
+
1030
+ get isNativeTabDragEnabled(): boolean {
1031
+ return this.nativeTabDragEnabled;
1032
+ }
1033
+
1034
+ /**
1035
+ * Drags tabs with native drag and drop instead of Lumino's tab dragging, which allows dragging them to other windows.
1036
+ * Does nothing if no {@link nativeTabDragService} is set.
1037
+ */
1038
+ enableNativeTabDrag(): void {
1039
+ if (this.nativeTabDragEnabled || !this.nativeTabDragService) {
1040
+ return;
1041
+ }
1042
+ this.nativeTabDragEnabled = true;
1043
+ // Lumino must not move or detach tabs itself, they are moved by the drop targets of the native drag
1044
+ this.tabsMovable = false;
1045
+ this.node.addEventListener('mousedown', this);
1046
+ this.node.addEventListener('dragstart', this);
1047
+ this.node.addEventListener('dragend', this);
1048
+ this.update();
1049
+ }
1050
+
1051
+ protected handleNativeTabDragEvent(event: Event): void {
1052
+ switch (event.type) {
1053
+ case 'pointerdown':
1054
+ if (this.isTabPress(event as PointerEvent)) {
1055
+ // Lumino prevents the default action of presses on tabs (see `TabBar._evtPointerDown`), which would keep the browser
1056
+ // from starting a native drag. Lumino offers no hook to skip this, hence the override of `preventDefault` on the event.
1057
+ // `tab-bars.spec.ts` verifies that Lumino still calls `preventDefault` and that it is skipped.
1058
+ Object.defineProperty(event, 'preventDefault', { value: () => { }, configurable: true });
1059
+ }
1060
+ break;
1061
+ case 'mousedown':
1062
+ if (this.isTabPress(event as MouseEvent)) {
1063
+ this.restoreFocusAfterTabPress();
1064
+ }
1065
+ break;
1066
+ case 'dragstart':
1067
+ this.startNativeTabDrag(event as DragEvent);
1068
+ break;
1069
+ case 'dragend':
1070
+ this.nativeTabDragService?.endDrag(event as DragEvent);
1071
+ break;
1072
+ }
1073
+ }
1074
+
1075
+ /**
1076
+ * Whether Lumino handles the given event as a press on a tab that may start a drag, i.e. a left button press that
1077
+ * hits a tab and not its title input. Uses the same hit test as `TabBar._evtPointerDown`.
1078
+ */
1079
+ protected isTabPress(event: MouseEvent): boolean {
1080
+ // not using `instanceof`, the tab bar may be in a secondary window, i.e. in another JavaScript realm
1081
+ const target = event.target as Element | null;
1082
+ if (event.button !== 0 || target?.classList?.contains('lm-TabBar-tabInput')) {
1083
+ return false;
1084
+ }
1085
+ return ArrayExt.findFirstIndex(this.contentNode.children, tab => ElementExt.hitTest(tab, event.clientX, event.clientY)) !== -1;
1086
+ }
1087
+
1088
+ /**
1089
+ * Without preventing the default action of a press on a tab, the browser moves the focus away from the widget that Lumino activated on the press.
1090
+ */
1091
+ protected restoreFocusAfterTabPress(): void {
1092
+ setTimeout(() => {
1093
+ const current = this.currentTitle?.owner;
1094
+ if (current && !current.isDisposed && !current.node.contains(current.node.ownerDocument.activeElement)) {
1095
+ current.activate();
1096
+ }
1097
+ });
1098
+ }
1099
+
1100
+ protected startNativeTabDrag(event: DragEvent): void {
1101
+ const tab = (event.target as Element | null)?.closest?.('.lm-TabBar-tab');
1102
+ const title = tab ? this.titles[Array.prototype.indexOf.call(this.contentNode.children, tab)] : undefined;
1103
+ if (!title || !this.dockPanel || !this.nativeTabDragService) {
1104
+ event.preventDefault();
1105
+ return;
1106
+ }
1107
+ this.nativeTabDragService.startDrag(event, this, title, this.dockPanel);
1108
+ }
1109
+
1019
1110
  protected async updateBreadcrumbs(): Promise<void> {
1020
1111
  const current = this.currentTitle?.owner;
1021
1112
  const uri = NavigatableWidget.is(current) ? current.getResourceUri() : undefined;
@@ -1058,6 +1149,13 @@ export class ToolbarAwareTabBar extends ScrollableTabBar {
1058
1149
  }
1059
1150
 
1060
1151
  override handleEvent(event: Event): void {
1152
+ if (this.nativeTabDragEnabled) {
1153
+ this.handleNativeTabDragEvent(event);
1154
+ }
1155
+ if (event.type === 'mousedown' || event.type === 'dragstart' || event.type === 'dragend') {
1156
+ // only listened to for native tab drags
1157
+ return;
1158
+ }
1061
1159
  if (event instanceof MouseEvent) {
1062
1160
  if (isContextMenuEvent(event)) {
1063
1161
  // Let this bubble up to handle the context menu
@@ -1098,6 +1196,14 @@ export class SideTabBar extends ScrollableTabBar {
1098
1196
  */
1099
1197
  readonly tabsOverflowChanged = new Signal<this, { titles: Title<Widget>[], startIndex: number }>(this);
1100
1198
 
1199
+ /**
1200
+ * Emitted when a widget is dragged onto the tab bar and dropped. Its tab is to be inserted before the tab at `index`,
1201
+ * or appended if `index` is the number of tabs.
1202
+ */
1203
+ readonly widgetDropped = new Signal<this, { widget: Widget, index: number }>(this);
1204
+
1205
+ protected readonly widgetDropHelper = new TabDropHelper({ before: 'drop-target-top', after: 'drop-target-bottom' });
1206
+
1101
1207
  protected mouseData?: {
1102
1208
  pressX: number,
1103
1209
  pressY: number,
@@ -1149,6 +1255,7 @@ export class SideTabBar extends ScrollableTabBar {
1149
1255
  this.node.addEventListener('lm-dragenter', this);
1150
1256
  this.node.addEventListener('lm-dragover', this);
1151
1257
  this.node.addEventListener('lm-dragleave', this);
1258
+ this.node.addEventListener('lm-drop', this);
1152
1259
  document.addEventListener('lm-drop', this);
1153
1260
  }
1154
1261
 
@@ -1157,6 +1264,7 @@ export class SideTabBar extends ScrollableTabBar {
1157
1264
  this.node.removeEventListener('lm-dragenter', this);
1158
1265
  this.node.removeEventListener('lm-dragover', this);
1159
1266
  this.node.removeEventListener('lm-dragleave', this);
1267
+ this.node.removeEventListener('lm-drop', this);
1160
1268
  document.removeEventListener('lm-drop', this);
1161
1269
  }
1162
1270
 
@@ -1372,8 +1480,17 @@ export class SideTabBar extends ScrollableTabBar {
1372
1480
  case 'lm-dragover':
1373
1481
  this.onDragOver(event as Drag.Event);
1374
1482
  break;
1375
- case 'lm-dragleave': case 'lm-drop':
1483
+ case 'lm-dragleave':
1376
1484
  this.cancelViewContainerDND();
1485
+ this.widgetDropHelper.hideInsertionMarker();
1486
+ break;
1487
+ case 'lm-drop':
1488
+ this.cancelViewContainerDND();
1489
+ this.widgetDropHelper.hideInsertionMarker();
1490
+ // `lm-drop` is also listened to on the document to clean up dragged view container parts
1491
+ if (event.currentTarget === this.node) {
1492
+ this.onWidgetDrop(event as Drag.Event);
1493
+ }
1377
1494
  break;
1378
1495
  case 'contextmenu':
1379
1496
  // Let the event bubble up instead of quashing it in the superclass
@@ -1453,7 +1570,7 @@ export class SideTabBar extends ScrollableTabBar {
1453
1570
  */
1454
1571
  protected onDragEnter = (event: Drag.Event) => {
1455
1572
  this.cancelViewContainerDND();
1456
- if (event.mimeData.getData('application/vnd.lumino.view-container-factory')) {
1573
+ if (event.mimeData.getData('application/vnd.lumino.view-container-factory') || this.widgetDropHelper.getDraggedWidget(event)) {
1457
1574
  event.preventDefault();
1458
1575
  event.stopPropagation();
1459
1576
  }
@@ -1467,7 +1584,7 @@ export class SideTabBar extends ScrollableTabBar {
1467
1584
  const factory = event.mimeData.getData('application/vnd.lumino.view-container-factory');
1468
1585
  const widget = factory && factory();
1469
1586
  if (!widget) {
1470
- event.dropAction = 'none';
1587
+ this.onWidgetDragOver(event);
1471
1588
  return;
1472
1589
  }
1473
1590
  event.preventDefault();
@@ -1517,4 +1634,30 @@ export class SideTabBar extends ScrollableTabBar {
1517
1634
  }
1518
1635
  };
1519
1636
 
1637
+ /**
1638
+ * Handles dragging a widget, e.g. the tab of an editor or of a view in another side panel, over the tab bar.
1639
+ */
1640
+ protected onWidgetDragOver(event: Drag.Event): void {
1641
+ if (!this.widgetDropHelper.getDraggedWidget(event)) {
1642
+ event.dropAction = 'none';
1643
+ this.widgetDropHelper.hideInsertionMarker();
1644
+ return;
1645
+ }
1646
+ event.preventDefault();
1647
+ event.stopPropagation();
1648
+ event.dropAction = event.proposedAction;
1649
+ this.widgetDropHelper.showInsertionMarker(this, this.widgetDropHelper.findInsertionIndex(this, event.clientX, event.clientY));
1650
+ }
1651
+
1652
+ protected onWidgetDrop(event: Drag.Event): void {
1653
+ const widget = this.widgetDropHelper.getDraggedWidget(event);
1654
+ if (!widget) {
1655
+ return;
1656
+ }
1657
+ event.preventDefault();
1658
+ event.stopPropagation();
1659
+ event.dropAction = event.proposedAction;
1660
+ this.widgetDropped.emit({ widget, index: this.widgetDropHelper.findInsertionIndex(this, event.clientX, event.clientY) });
1661
+ }
1662
+
1520
1663
  }
@@ -0,0 +1,79 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 EclipseSource and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Drag } from '@lumino/dragdrop';
18
+ import { TabBar, Widget } from '@lumino/widgets';
19
+ import { WIDGET_FACTORY_MIME_TYPE } from './native-tab-drag-service';
20
+
21
+ /**
22
+ * Supports drop targets that insert a dragged widget as a tab of a tab bar where it is dropped:
23
+ * finds the dragged widget and the insertion index, and marks the tab before or after which the widget is inserted.
24
+ */
25
+ export class TabDropHelper {
26
+
27
+ protected insertionMarker?: { tab: Element, className: string };
28
+
29
+ /**
30
+ * @param markerClassNames the classes marking the tab before (`before`) or after (`after`) which a dropped widget is inserted
31
+ */
32
+ constructor(protected readonly markerClassNames: { before: string, after: string }) { }
33
+
34
+ getDraggedWidget(event: Drag.Event): Widget | undefined {
35
+ const factory = event.mimeData.getData(WIDGET_FACTORY_MIME_TYPE);
36
+ const widget = typeof factory === 'function' ? factory() : undefined;
37
+ return widget instanceof Widget ? widget : undefined;
38
+ }
39
+
40
+ /**
41
+ * @returns the index of the tab before which a widget dropped at the given position is inserted,
42
+ * or the number of tabs if it is appended
43
+ */
44
+ findInsertionIndex(tabBar: TabBar<Widget>, clientX: number, clientY: number): number {
45
+ const horizontal = tabBar.orientation === 'horizontal';
46
+ const tabs = tabBar.contentNode.children;
47
+ for (let i = 0; i < tabs.length; i++) {
48
+ const rect = tabs[i].getBoundingClientRect();
49
+ const start = horizontal ? rect.left : rect.top;
50
+ const size = horizontal ? rect.width : rect.height;
51
+ if (size > 0 && (horizontal ? clientX : clientY) < start + size / 2) {
52
+ return i;
53
+ }
54
+ }
55
+ return tabs.length;
56
+ }
57
+
58
+ showInsertionMarker(tabBar: TabBar<Widget>, index: number): void {
59
+ const tabs = tabBar.contentNode.children;
60
+ const tab = index < tabs.length ? tabs[index] : tabs[tabs.length - 1];
61
+ const className = index < tabs.length ? this.markerClassNames.before : this.markerClassNames.after;
62
+ if (this.insertionMarker?.tab === tab && this.insertionMarker.className === className) {
63
+ return;
64
+ }
65
+ this.hideInsertionMarker();
66
+ if (tab) {
67
+ tab.classList.add(className);
68
+ this.insertionMarker = { tab, className };
69
+ }
70
+ }
71
+
72
+ hideInsertionMarker(): void {
73
+ if (this.insertionMarker) {
74
+ this.insertionMarker.tab.classList.remove(this.insertionMarker.className);
75
+ this.insertionMarker = undefined;
76
+ }
77
+ }
78
+
79
+ }
@@ -17,10 +17,12 @@
17
17
  import { find, toArray } from '@lumino/algorithm';
18
18
  import { TabBar, Widget, DockPanel, Title } from '@lumino/widgets';
19
19
  import { Signal } from '@lumino/signaling';
20
+ import { Drag } from '@lumino/dragdrop';
20
21
  import { Disposable, DisposableCollection } from '../../common/disposable';
21
22
  import { CorePreferences } from '../../common/core-preferences';
22
23
  import { Emitter, Event, environment } from '../../common';
23
24
  import { ToolbarAwareTabBar } from './tab-bars';
25
+ import { TabDropHelper } from './tab-drop-helper';
24
26
 
25
27
  export const ACTIVE_TABBAR_CLASS = 'theia-tabBar-active';
26
28
 
@@ -49,6 +51,9 @@ export class TheiaDockPanel extends DockPanel {
49
51
  protected readonly onDidChangeCurrentEmitter = new Emitter<Title<Widget> | undefined>();
50
52
  protected disableDND: boolean | undefined = false;
51
53
  protected tabWithDNDDisabledStyling?: HTMLElement = undefined;
54
+ protected readonly tabDropHelper = new TabDropHelper({ before: 'theia-mod-drop-before', after: 'theia-mod-drop-after' });
55
+ protected canDropWidget?: (widget: Widget) => boolean;
56
+ protected onWillDropWidget?: (widget: Widget) => void;
52
57
 
53
58
  get onDidChangeCurrent(): Event<Title<Widget> | undefined> {
54
59
  return this.onDidChangeCurrentEmitter.event;
@@ -60,6 +65,10 @@ export class TheiaDockPanel extends DockPanel {
60
65
  ) {
61
66
  super(options);
62
67
  this.disableDND = TheiaDockPanel.isTheiaDockPanelIOptions(options) && options.disableDragAndDrop;
68
+ if (TheiaDockPanel.isTheiaDockPanelIOptions(options)) {
69
+ this.canDropWidget = options.canDropWidget;
70
+ this.onWillDropWidget = options.onWillDropWidget;
71
+ }
63
72
  this['_onCurrentChanged'] = (sender: TabBar<Widget>, args: TabBar.ICurrentChangedArgs<Widget>) => {
64
73
  this.markAsCurrent(args.currentTitle || undefined);
65
74
  super['_onCurrentChanged'](sender, args);
@@ -70,6 +79,9 @@ export class TheiaDockPanel extends DockPanel {
70
79
  const tabBar = super['_createTabBar']();
71
80
  if (tabBar instanceof ToolbarAwareTabBar) {
72
81
  tabBar.setDockPanel(this);
82
+ if (!this.disableDND) {
83
+ tabBar.enableNativeTabDrag();
84
+ }
73
85
  }
74
86
  if (this.disableDND) {
75
87
  tabBar['tabDetachRequested'].disconnect(this['_onTabDetachRequested'], this);
@@ -124,21 +136,110 @@ export class TheiaDockPanel extends DockPanel {
124
136
  }
125
137
 
126
138
  override handleEvent(event: globalThis.Event): void {
127
- if (this.disableDND) {
128
- switch (event.type) {
129
- case 'lm-dragenter':
130
- case 'lm-dragleave':
131
- case 'lm-dragover':
132
- case 'lm-drop':
133
- /* no-op */
134
- break;
135
- default:
136
- super.handleEvent(event);
137
- }
139
+ switch (event.type) {
140
+ case 'lm-dragenter':
141
+ case 'lm-dragleave':
142
+ case 'lm-dragover':
143
+ case 'lm-drop':
144
+ if (this.disableDND) {
145
+ return;
146
+ }
147
+ if ((event.type === 'lm-dragenter' || event.type === 'lm-drop') && !this.isDropAllowed(event as Drag.Event)) {
148
+ // not accepting the drag enter keeps this panel from becoming the drop target
149
+ return;
150
+ }
151
+ if (event.type === 'lm-drop') {
152
+ this.notifyWillDrop(event as Drag.Event);
153
+ }
154
+ if (this.handleTabBarDragEvent(event as Drag.Event)) {
155
+ return;
156
+ }
157
+ break;
138
158
  }
139
159
  super.handleEvent(event);
140
160
  }
141
161
 
162
+ protected isDropAllowed(event: Drag.Event): boolean {
163
+ const widget = this.canDropWidget && this.getDraggedWidget(event);
164
+ return !widget || this.canDropWidget!(widget);
165
+ }
166
+
167
+ protected notifyWillDrop(event: Drag.Event): void {
168
+ const widget = this.onWillDropWidget && this.getDraggedWidget(event);
169
+ if (widget) {
170
+ this.onWillDropWidget!(widget);
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Handles dragging a widget over the tab bars of this panel: the widget is inserted as a tab where it is dropped,
176
+ * instead of after the current tab of the tab bar as Lumino does.
177
+ *
178
+ * @returns `true` if the event has been handled
179
+ */
180
+ protected handleTabBarDragEvent(event: Drag.Event): boolean {
181
+ if (event.type !== 'lm-dragover' && event.type !== 'lm-drop') {
182
+ if (event.type === 'lm-dragleave' && !(event.relatedTarget && this.node.contains(event.relatedTarget as Node))) {
183
+ this.tabDropHelper.hideInsertionMarker();
184
+ }
185
+ return false;
186
+ }
187
+ const tabBar = this.findTabBarAt(event.clientX, event.clientY);
188
+ const widget = tabBar && this.getDraggedWidget(event);
189
+ if (!tabBar || !widget) {
190
+ this.tabDropHelper.hideInsertionMarker();
191
+ return false;
192
+ }
193
+ event.preventDefault();
194
+ event.stopPropagation();
195
+ this.overlay.hide(0);
196
+ const index = this.tabDropHelper.findInsertionIndex(tabBar, event.clientX, event.clientY);
197
+ if (event.type === 'lm-dragover') {
198
+ this.tabDropHelper.showInsertionMarker(tabBar, index);
199
+ } else {
200
+ this.tabDropHelper.hideInsertionMarker();
201
+ this.insertTab(tabBar, index, widget);
202
+ }
203
+ event.dropAction = event.proposedAction;
204
+ return true;
205
+ }
206
+
207
+ protected getDraggedWidget(event: Drag.Event): Widget | undefined {
208
+ if (this['_tabsConstrained'] && event.source !== this) {
209
+ return undefined;
210
+ }
211
+ const widget = this.tabDropHelper.getDraggedWidget(event);
212
+ return widget && !widget.contains(this) ? widget : undefined;
213
+ }
214
+
215
+ protected findTabBarAt(clientX: number, clientY: number): TabBar<Widget> | undefined {
216
+ return find(this.tabBars(), tabBar => {
217
+ const barRect = tabBar.node.getBoundingClientRect();
218
+ const contentRect = tabBar.contentNode.getBoundingClientRect();
219
+ return clientX >= barRect.left && clientX < barRect.right && clientY >= contentRect.top && clientY < contentRect.bottom;
220
+ });
221
+ }
222
+
223
+ protected insertTab(tabBar: TabBar<Widget>, index: number, widget: Widget): void {
224
+ const titles = tabBar.titles;
225
+ const currentIndex = titles.indexOf(widget.title);
226
+ if (currentIndex !== -1) {
227
+ const toIndex = index > currentIndex ? index - 1 : index;
228
+ if (toIndex !== currentIndex) {
229
+ tabBar.insertTab(toIndex, widget.title);
230
+ // `insertTab` does not emit the signal that Lumino emits when a tab is moved with the pointer
231
+ (tabBar.tabMoved as Signal<TabBar<Widget>, TabBar.ITabMovedArgs<Widget>>).emit({ fromIndex: currentIndex, toIndex, title: widget.title });
232
+ }
233
+ } else if (index < titles.length) {
234
+ this.addWidget(widget, { mode: 'tab-before', ref: titles[index].owner });
235
+ } else if (titles.length > 0) {
236
+ this.addWidget(widget, { mode: 'tab-after', ref: titles[titles.length - 1].owner });
237
+ } else {
238
+ this.addWidget(widget);
239
+ }
240
+ this.activateWidget(widget);
241
+ }
242
+
142
243
  toggleMaximized(): void {
143
244
  if (this.maximizeCallback) {
144
245
  this.maximizeCallback(this);
@@ -265,6 +366,16 @@ export namespace TheiaDockPanel {
265
366
  * @returns true if the request was handled by this handler, false if the tabbar should handle the request
266
367
  */
267
368
  closeHandler?: (sender: TabBar<Widget>, args: TabBar.ITabCloseRequestedArgs<Widget>) => boolean;
369
+
370
+ /**
371
+ * Whether the given widget may be dropped on this panel. By default, any widget may be dropped.
372
+ */
373
+ canDropWidget?: (widget: Widget) => boolean;
374
+
375
+ /**
376
+ * Called when the given widget is dropped on this panel, before it is added to the panel.
377
+ */
378
+ onWillDropWidget?: (widget: Widget) => void;
268
379
  }
269
380
 
270
381
  export function isTheiaDockPanelIOptions(options: DockPanel.IOptions | undefined): options is IOptions {
@@ -86,6 +86,15 @@
86
86
  background: var(--theia-panel-dropBackground);
87
87
  }
88
88
 
89
+ /* marks where a dragged tab is inserted when it is dropped on a tab bar */
90
+ .lm-TabBar-tab.theia-mod-drop-before {
91
+ box-shadow: inset 2px 0 0 var(--theia-tab-dragAndDropBorder) !important;
92
+ }
93
+
94
+ .lm-TabBar-tab.theia-mod-drop-after {
95
+ box-shadow: inset -2px 0 0 var(--theia-tab-dragAndDropBorder) !important;
96
+ }
97
+
89
98
  .lm-TabBar-tab.theia-drag-not-allowed {
90
99
  cursor: not-allowed !important;
91
100
  background-color: var(--theia-errorBackground) !important;