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

View file

@ -12,6 +12,8 @@ import { StateNode } from '../../StateNode'
export class Idle extends StateNode { export class Idle extends StateNode {
static override id = 'idle' static override id = 'idle'
isDarwin = window.navigator.userAgent.toLowerCase().indexOf('mac') > -1
onPointerEnter: TLEventHandlers['onPointerEnter'] = (info) => { onPointerEnter: TLEventHandlers['onPointerEnter'] = (info) => {
switch (info.target) { switch (info.target) {
case 'canvas': { case 'canvas': {
@ -61,9 +63,17 @@ export class Idle extends StateNode {
const shouldEnterCropMode = this.shouldEnterCropMode(info, true) const shouldEnterCropMode = this.shouldEnterCropMode(info, true)
if (info.ctrlKey && !shouldEnterCropMode) { 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) this.parent.transition('brushing', info)
return return
} }
switch (info.target) { switch (info.target) {
case 'canvas': { case 'canvas': {
this.parent.transition('pointing_canvas', info) this.parent.transition('pointing_canvas', info)