[fix] control click on mac (#1535)

This PR fixes control click for right click on Mac.

### Change Type

- [x] `patch` — Bug Fix

### Test Plan

1. On a PC, ensure that control clicking does not select the thing under
your cursor
2. On a mac, ensure that control clicking does select the thing under
your cursor before the context menu opens

### Release Notes

- Fix control click to open menu on Mac
This commit is contained in:
Steve Ruiz 2023-06-06 12:30:52 +01:00 committed by GitHub
parent 7039c3772e
commit 6f8533df5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -3593,7 +3593,7 @@ export class Editor extends EventEmitter<TLEventMap> {
shiftKey: this.inputs.shiftKey,
ctrlKey: this.inputs.ctrlKey,
altKey: this.inputs.altKey,
code: 'CtrlLeft',
code: 'ControlLeft',
})
}
@ -3980,6 +3980,9 @@ export class Editor extends EventEmitter<TLEventMap> {
break
}
case 'keyboard': {
// please, please
if (info.code === 'ControlRight') info.code = 'ControlLeft'
switch (info.name) {
case 'key_down': {
// Add the key from the keys set

View file

@ -12,6 +12,8 @@ import { StateNode } from '../../StateNode'
export class Idle extends StateNode {
static override id = 'idle'
isDarwin = window.navigator.userAgent.toLowerCase().indexOf('mac') > -1
onPointerEnter: TLEventHandlers['onPointerEnter'] = (info) => {
switch (info.target) {
case 'canvas': {
@ -61,9 +63,17 @@ export class Idle extends StateNode {
const shouldEnterCropMode = this.shouldEnterCropMode(info, true)
if (info.ctrlKey && !shouldEnterCropMode) {
// On Mac, you can right click using the Control keys + Click.
if (info.target === 'shape' && this.isDarwin && this.editor.inputs.keys.has('ControlLeft')) {
if (!this.editor.isShapeOrAncestorLocked(info.shape)) {
this.parent.transition('pointing_shape', info)
return
}
}
this.parent.transition('brushing', info)
return
}
switch (info.target) {
case 'canvas': {
this.parent.transition('pointing_canvas', info)