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

Fix to make Copy/Paste keyboard shortcuts working with useSelection #302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/selection/useSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,17 @@ export const useSelection = ({
);

const onKeyDown = useCallback((event: KeyboardEvent) => {
const element = event.target as any;
const element = event.target as HTMLElement;
const isSafe =
element.tagName !== 'INPUT' &&
element.tagName !== 'SELECT' &&
element.tagName !== 'TEXTAREA' &&
!element.isContentEditable;

const isMeta = event.metaKey || event.ctrlKey;
const isSystemShortcut = ['c', 'x', 'v'].includes(event.key.toLowerCase());
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is the right approach considering this could change based on user hotkey or locale. I think removing the preventDefault is probably the right move, I don't remember why we added that in the first place, can u test it doesn't break anything if removed and update to just remove that instead?

Copy link
Author

Choose a reason for hiding this comment

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

It seems better indeed. I just tested and it works fine.


if (isSafe && isMeta) {
if (isSafe && isMeta && !isSystemShortcut) {
event.preventDefault();
setMetaKeyDown(true);
}
Expand Down
Loading