Merge pull request #598 from mathuo/596-moving-a-group-leaves-ghost-groups-that-cant-be-removed

bug: duplicate group added when added group with absolute position
This commit is contained in:
mathuo 2024-05-05 19:44:55 +01:00 committed by GitHub
commit 87d42c96e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 2 deletions

View File

@ -5331,4 +5331,48 @@ describe('dockviewComponent', () => {
expect(addGroupCount).toBe(2);
});
});
test('addGroup with absolute position', () => {
const container = document.createElement('div');
const dockview = new DockviewComponent({
parentElement: container,
createComponent(options) {
switch (options.name) {
case 'default':
return new PanelContentPartTest(
options.id,
options.name
);
default:
throw new Error(`unsupported`);
}
},
});
const api = new DockviewApi(dockview);
dockview.layout(1000, 1000);
api.addPanel({
id: 'panel_1',
component: 'default',
});
api.addPanel({
id: 'panel_2',
component: 'default',
});
const panel3 = api.addPanel({
id: 'panel_3',
component: 'default',
position: { direction: 'right' },
});
expect(api.panels.length).toBe(3);
expect(api.groups.length).toBe(2);
api.addGroup({direction:'left'});
expect(api.panels.length).toBe(3);
expect(api.groups.length).toBe(3);
});
});

View File

@ -1620,8 +1620,6 @@ export class DockviewComponent
}
addGroup(options?: AddGroupOptions): DockviewGroupPanel {
const group = this.createGroup(options);
if (options) {
let referenceGroup: DockviewGroupPanel | undefined;
@ -1675,12 +1673,16 @@ export class DockviewComponent
location,
target
);
const group = this.createGroup(options);
this.doAddGroup(group, relativeLocation);
if (!options.skipSetActive) {
this.doSetGroupAndPanelActive(group);
}
return group;
} else {
const group = this.createGroup(options);
this.doAddGroup(group);
this.doSetGroupAndPanelActive(group);
return group;