Skip to content

Commit

Permalink
bug: fix floating->popout->floating group transition
Browse files Browse the repository at this point in the history
  • Loading branch information
mathuo committed Jan 9, 2025
1 parent 872ec7c commit b912be2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5021,6 +5021,66 @@ describe('dockviewComponent', () => {
expect(panel3.api.location.type).toBe('grid');
});

test('grid -> floating -> popout -> floating', async () => {
const container = document.createElement('div');

window.open = () => setupMockWindow();

const dockview = new DockviewComponent(container, {
createComponent(options) {
switch (options.name) {
case 'default':
return new PanelContentPartTest(
options.id,
options.name
);
default:
throw new Error(`unsupported`);
}
},
});

dockview.layout(1000, 500);

const panel1 = dockview.addPanel({
id: 'panel_1',
component: 'default',
});

const panel2 = dockview.addPanel({
id: 'panel_2',
component: 'default',
});

const panel3 = dockview.addPanel({
id: 'panel_3',
component: 'default',
position: { direction: 'right' },
});

expect(panel1.api.location.type).toBe('grid');
expect(panel2.api.location.type).toBe('grid');
expect(panel3.api.location.type).toBe('grid');

dockview.addFloatingGroup(panel2.group);

expect(panel1.api.location.type).toBe('floating');
expect(panel2.api.location.type).toBe('floating');
expect(panel3.api.location.type).toBe('grid');

await dockview.addPopoutGroup(panel2.group);

expect(panel1.api.location.type).toBe('popout');
expect(panel2.api.location.type).toBe('popout');
expect(panel3.api.location.type).toBe('grid');

dockview.addFloatingGroup(panel2.group);

expect(panel1.api.location.type).toBe('floating');
expect(panel2.api.location.type).toBe('floating');
expect(panel3.api.location.type).toBe('grid');
});

test('that panel is rendered when moving from popout to new group', async () => {
const container = document.createElement('div');

Expand Down
14 changes: 14 additions & 0 deletions packages/dockview-core/src/dockview/dockviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,20 @@ export class DockviewComponent
this.overlayRenderContainer;
returnedGroup = group;

const alreadyRemoved = !this._popoutGroups.find(
(p) => p.popoutGroup === group
);

if (alreadyRemoved) {
/**
* If this popout group was explicitly removed then we shouldn't run the additional
* steps. To tell if the running of this disposable is the result of this popout group
* being explicitly removed we can check if this popout group is still referenced in
* the `this._popoutGroups` list.
*/
return;
}

if (floatingBox) {
this.addFloatingGroup(group, {
height: floatingBox.height,
Expand Down

0 comments on commit b912be2

Please sign in to comment.