Merge pull request #300 from mathuo/230-explore-floating-groups

feat: resrict new floating groups if floating with 1 tab
This commit is contained in:
mathuo 2023-07-13 18:40:25 +01:00 committed by GitHub
commit f1357edbb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View File

@ -577,7 +577,7 @@ describe('tabsContainer', () => {
expect(eventPreventDefaultSpy2).toBeCalledTimes(0);
});
test('that selecting a tab which shift down will move that tab into a new floating group', () => {
test('that selecting a tab with shift down will move that tab into a new floating group', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return (<Partial<DockviewComponent>>{
options: {},
@ -592,6 +592,7 @@ describe('tabsContainer', () => {
const groupPanelMock = jest.fn<DockviewGroupPanel, []>(() => {
return (<Partial<DockviewGroupPanel>>{
api: { isFloating: true } as any,
model: {} as any,
}) as DockviewGroupPanel;
});
@ -600,9 +601,9 @@ describe('tabsContainer', () => {
const cut = new TabsContainer(accessor, groupPanel);
const panelMock = jest.fn<IDockviewPanel, []>(() => {
const panelMock = jest.fn<IDockviewPanel, [string]>((id: string) => {
const partial: Partial<IDockviewPanel> = {
id: 'test_id',
id,
view: {
tab: {
@ -615,8 +616,8 @@ describe('tabsContainer', () => {
};
return partial as IDockviewPanel;
});
const panel = new panelMock();
const panel = new panelMock('test_id');
cut.openPanel(panel);
const el = cut.element.querySelector('.tab')!;
@ -626,6 +627,14 @@ describe('tabsContainer', () => {
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
fireEvent(el, event);
// a floating group with a single tab shouldn't be eligible
expect(preventDefaultSpy).toBeCalledTimes(0);
expect(accessor.addFloatingGroup).toBeCalledTimes(0);
const panel2 = new panelMock('test_id_2');
cut.openPanel(panel2);
fireEvent(el, event);
expect(preventDefaultSpy).toBeCalledTimes(1);
expect(accessor.addFloatingGroup).toBeCalledTimes(1);
});

View File

@ -296,7 +296,14 @@ export class TabsContainer
const isFloatingGroupsEnabled =
!this.accessor.options.disableFloatingGroups;
if (isFloatingGroupsEnabled && event.shiftKey) {
const isFloatingWithOnePanel =
this.group.api.isFloating && this.size === 1;
if (
isFloatingGroupsEnabled &&
!isFloatingWithOnePanel &&
event.shiftKey
) {
event.preventDefault();
const panel = this.accessor.getGroupPanel(tabToAdd.panelId);