mirror of
https://github.com/mathuo/dockview
synced 2025-02-21 15:45:46 +00:00
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:
commit
f1357edbb5
@ -577,7 +577,7 @@ describe('tabsContainer', () => {
|
|||||||
expect(eventPreventDefaultSpy2).toBeCalledTimes(0);
|
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, []>(() => {
|
const accessorMock = jest.fn<DockviewComponent, []>(() => {
|
||||||
return (<Partial<DockviewComponent>>{
|
return (<Partial<DockviewComponent>>{
|
||||||
options: {},
|
options: {},
|
||||||
@ -592,6 +592,7 @@ describe('tabsContainer', () => {
|
|||||||
const groupPanelMock = jest.fn<DockviewGroupPanel, []>(() => {
|
const groupPanelMock = jest.fn<DockviewGroupPanel, []>(() => {
|
||||||
return (<Partial<DockviewGroupPanel>>{
|
return (<Partial<DockviewGroupPanel>>{
|
||||||
api: { isFloating: true } as any,
|
api: { isFloating: true } as any,
|
||||||
|
model: {} as any,
|
||||||
}) as DockviewGroupPanel;
|
}) as DockviewGroupPanel;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -600,9 +601,9 @@ describe('tabsContainer', () => {
|
|||||||
|
|
||||||
const cut = new TabsContainer(accessor, groupPanel);
|
const cut = new TabsContainer(accessor, groupPanel);
|
||||||
|
|
||||||
const panelMock = jest.fn<IDockviewPanel, []>(() => {
|
const panelMock = jest.fn<IDockviewPanel, [string]>((id: string) => {
|
||||||
const partial: Partial<IDockviewPanel> = {
|
const partial: Partial<IDockviewPanel> = {
|
||||||
id: 'test_id',
|
id,
|
||||||
|
|
||||||
view: {
|
view: {
|
||||||
tab: {
|
tab: {
|
||||||
@ -615,8 +616,8 @@ describe('tabsContainer', () => {
|
|||||||
};
|
};
|
||||||
return partial as IDockviewPanel;
|
return partial as IDockviewPanel;
|
||||||
});
|
});
|
||||||
const panel = new panelMock();
|
|
||||||
|
|
||||||
|
const panel = new panelMock('test_id');
|
||||||
cut.openPanel(panel);
|
cut.openPanel(panel);
|
||||||
|
|
||||||
const el = cut.element.querySelector('.tab')!;
|
const el = cut.element.querySelector('.tab')!;
|
||||||
@ -626,6 +627,14 @@ describe('tabsContainer', () => {
|
|||||||
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
|
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
|
||||||
fireEvent(el, event);
|
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(preventDefaultSpy).toBeCalledTimes(1);
|
||||||
expect(accessor.addFloatingGroup).toBeCalledTimes(1);
|
expect(accessor.addFloatingGroup).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
@ -296,7 +296,14 @@ export class TabsContainer
|
|||||||
const isFloatingGroupsEnabled =
|
const isFloatingGroupsEnabled =
|
||||||
!this.accessor.options.disableFloatingGroups;
|
!this.accessor.options.disableFloatingGroups;
|
||||||
|
|
||||||
if (isFloatingGroupsEnabled && event.shiftKey) {
|
const isFloatingWithOnePanel =
|
||||||
|
this.group.api.isFloating && this.size === 1;
|
||||||
|
|
||||||
|
if (
|
||||||
|
isFloatingGroupsEnabled &&
|
||||||
|
!isFloatingWithOnePanel &&
|
||||||
|
event.shiftKey
|
||||||
|
) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const panel = this.accessor.getGroupPanel(tabToAdd.panelId);
|
const panel = this.accessor.getGroupPanel(tabToAdd.panelId);
|
||||||
|
Loading…
Reference in New Issue
Block a user