Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3221 - add shortcut shift+tab for switching selection mode #3287

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ketcher-autotests/tests/User-Interface/Hot-Keys/hotkeys.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable no-magic-numbers */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this line? I don't see any magic numbers here

import { expect, test } from '@playwright/test';
import {
waitForIndigoToLoad,
selectNestedTool,
SelectTool,
selectTool,
LeftPanelButton,
clickInTheMiddleOfTheScreen,
} from '@utils';

test.describe('Hot keys', () => {
test.beforeEach(async ({ page }) => {
await page.goto('');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please use waitForPageInit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use waitForPageInit, there is no need to use await page.goto('') as it is already inside that function

await waitForIndigoToLoad(page);
});

test.afterEach(async ({ page }) => {
await expect(page).toHaveScreenshot();
});

test('select last chosen selected tool when user press ESC', async ({
page,
}) => {
await selectNestedTool(page, SelectTool.FRAGMENT_SELECTION);
await selectTool(LeftPanelButton.AddText, page);
await page.keyboard.press('Escape');
expect(page.getByTestId('select-fragment')).toBeTruthy();
StarlaStarla marked this conversation as resolved.
Show resolved Hide resolved
});

test('Shift+Tab to switch selection tool', async ({ page }) => {
await clickInTheMiddleOfTheScreen(page);
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Shift+Tab');
expect(page.getByTestId('select-fragment')).toBeTruthy();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/ketcher-react/src/script/ui/action/atoms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const atomCuts = {
S: 's',
P: 'p',
F: 'f',
Cl: 'Shift+c',
Cl: 'l',
Br: 'b',
I: 'i',
A: 'a',
Expand Down
14 changes: 7 additions & 7 deletions packages/ketcher-react/src/script/ui/action/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ const toolActions = {
action: { tool: 'hand' },
hidden: (options) => isHidden(options, 'hand'),
},
'select-lasso': {
title: 'Lasso Selection',
shortcut: 'Escape',
action: { tool: 'select', opts: 'lasso' },
},
'select-rectangle': {
title: 'Rectangle Selection',
shortcut: 'Escape',
shortcut: ['Shift+Tab', 'Escape'],
action: { tool: 'select', opts: 'rectangle' },
hidden: (options) => isHidden(options, 'select-rectangle'),
},
'select-lasso': {
title: 'Lasso Selection',
shortcut: ['Shift+Tab', 'Escape'],
action: { tool: 'select', opts: 'lasso' },
},
'select-fragment': {
title: 'Fragment Selection',
shortcut: 'Escape',
shortcut: ['Shift+Tab', 'Escape'],
action: { tool: 'select', opts: 'fragment' },
hidden: (options) => isHidden(options, 'select-fragment'),
},
Expand Down
69 changes: 69 additions & 0 deletions packages/ketcher-react/src/script/ui/state/hotkeys.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { screen, fireEvent, render as rtlRender } from '@testing-library/react';
import { LeftToolbarContainer } from '../views/toolbars';
import { Provider } from 'react-redux';
import createStore from '../state';
import { initKeydownListener } from './hotkeys';
import { act } from 'react-dom/test-utils';

jest.mock('react-intersection-observer', () => {
return {
observe: jest.fn(),
disconnect: jest.fn(),
useInView: jest.fn().mockReturnValue([]),
};
});

describe('Hot keys', () => {
it('should select last chosen selected tool when user press ESC', async () => {
renderWithMockStore(<LeftToolbarContainer />);
const text = screen.getByTestId('text');
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => {
fireEvent.click(text);
fireEvent.keyDown(text, {
keyCode: 27,
});
});
expect(screen.getByTestId('select-rectangle').className).toContain(
'selected',
);
});

it('Shift+Tab to switch selection tool', async () => {
renderWithMockStore(<LeftToolbarContainer />);
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => {
fireEvent.keyDown(document, {
keyCode: 9,
shiftKey: true,
});
});
expect(screen.getByTestId('select-lasso').className).toContain('selected');
});
});

function renderWithMockStore(component) {
const store = createStore({}, {}, () => null);
store.dispatch(initKeydownListener(document));
store.dispatch({
type: 'INIT',
editor: {
tool: jest.fn().mockReturnValue(true),
historySize: () => {
return { undo: [] };
},
selection: jest.fn(),
struct: () => {
return { atoms: { keys: () => new Set() } };
},
render: { ctab: {} },
zoom: jest.fn(),
_tool: { mode: '' },
rotateController: { isRotating: false },
},
});
return {
...rtlRender(<Provider store={store}>{component}</Provider>),
store,
};
}
7 changes: 5 additions & 2 deletions packages/ketcher-react/src/script/ui/state/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ function keyHandle(dispatch, getState, hotKeys, event) {
});
} else {
if (newAction.tool === 'select') {
newAction = SettingsManager.getSettings().selectionTool;
if (key === 'Escape') {
newAction = SettingsManager.getSettings().selectionTool;
} else if (index === -1) {
newAction = {};
}
}

dispatch(onAction(newAction));
}

Expand Down
Loading