macOS shortcuts: Only listen for command key, not control key
This commit is contained in:
parent
d86e8ef7ec
commit
2c7baad68d
10 changed files with 59 additions and 39 deletions
|
@ -704,7 +704,9 @@
|
|||
const { altKey, ctrlKey, key, metaKey, shiftKey } = event;
|
||||
|
||||
const optionOrAlt = altKey;
|
||||
const ctrlOrCommand = metaKey || ctrlKey;
|
||||
const commandKey = window.platform === 'darwin' && metaKey;
|
||||
const controlKey = window.platform !== 'darwin' && ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
const state = store.getState();
|
||||
const selectedId = state.conversations.selectedConversation;
|
||||
|
@ -715,7 +717,7 @@
|
|||
|
||||
// Show keyboard shortcuts - handled by Electron-managed keyboard shortcuts
|
||||
// However, on linux Ctrl+/ selects all text, so we prevent that
|
||||
if (ctrlOrCommand && key === '/') {
|
||||
if (commandOrCtrl && key === '/') {
|
||||
window.showKeyboardShortcuts();
|
||||
|
||||
event.stopPropagation();
|
||||
|
@ -725,7 +727,7 @@
|
|||
}
|
||||
|
||||
// Navigate by section
|
||||
if (ctrlOrCommand && !shiftKey && (key === 't' || key === 'T')) {
|
||||
if (commandOrCtrl && !shiftKey && (key === 't' || key === 'T')) {
|
||||
window.enterKeyboardMode();
|
||||
const focusedElement = document.activeElement;
|
||||
|
||||
|
@ -924,7 +926,7 @@
|
|||
// Open the top-right menu for current conversation
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'l' || key === 'L')
|
||||
) {
|
||||
|
@ -965,7 +967,7 @@
|
|||
}
|
||||
|
||||
// Search
|
||||
if (ctrlOrCommand && !shiftKey && (key === 'f' || key === 'F')) {
|
||||
if (commandOrCtrl && !shiftKey && (key === 'f' || key === 'F')) {
|
||||
const { startSearch } = actions.search;
|
||||
startSearch();
|
||||
|
||||
|
@ -977,7 +979,7 @@
|
|||
// Search in conversation
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'f' || key === 'F')
|
||||
) {
|
||||
|
@ -995,7 +997,7 @@
|
|||
// Focus composer field
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 't' || key === 'T')
|
||||
) {
|
||||
|
@ -1008,7 +1010,7 @@
|
|||
// Open all media
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'm' || key === 'M')
|
||||
) {
|
||||
|
@ -1025,7 +1027,7 @@
|
|||
// Begin recording voice note
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'v' || key === 'V')
|
||||
) {
|
||||
|
@ -1039,7 +1041,7 @@
|
|||
if (
|
||||
conversation &&
|
||||
!conversation.get('isArchived') &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'a' || key === 'A')
|
||||
) {
|
||||
|
@ -1074,7 +1076,7 @@
|
|||
if (
|
||||
conversation &&
|
||||
conversation.get('isArchived') &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'u' || key === 'U')
|
||||
) {
|
||||
|
@ -1096,7 +1098,7 @@
|
|||
// Close conversation
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'c' || key === 'C')
|
||||
) {
|
||||
|
@ -1111,7 +1113,7 @@
|
|||
// Show message details
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
!shiftKey &&
|
||||
(key === 'd' || key === 'D')
|
||||
) {
|
||||
|
@ -1129,7 +1131,7 @@
|
|||
// Toggle reply to message
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'r' || key === 'R')
|
||||
) {
|
||||
|
@ -1144,7 +1146,7 @@
|
|||
// Save attachment
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
!shiftKey &&
|
||||
(key === 's' || key === 'S')
|
||||
) {
|
||||
|
@ -1161,7 +1163,7 @@
|
|||
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'd' || key === 'D')
|
||||
) {
|
||||
|
@ -1187,7 +1189,7 @@
|
|||
// Attach file
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
!shiftKey &&
|
||||
(key === 'u' || key === 'U')
|
||||
) {
|
||||
|
@ -1201,7 +1203,7 @@
|
|||
// Remove draft link preview
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
!shiftKey &&
|
||||
(key === 'p' || key === 'P')
|
||||
) {
|
||||
|
@ -1215,7 +1217,7 @@
|
|||
// Attach file
|
||||
if (
|
||||
conversation &&
|
||||
ctrlOrCommand &&
|
||||
commandOrCtrl &&
|
||||
shiftKey &&
|
||||
(key === 'p' || key === 'P')
|
||||
) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as React from 'react';
|
||||
import { Editor } from 'draft-js';
|
||||
import { noop } from 'lodash';
|
||||
import { get, noop } from 'lodash';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
EmojiButton,
|
||||
|
@ -293,9 +293,12 @@ export const CompositionArea = ({
|
|||
const { key, shiftKey, ctrlKey, metaKey } = e;
|
||||
// When using the ctrl key, `key` is `'X'`. When using the cmd key, `key` is `'x'`
|
||||
const xKey = key === 'x' || key === 'X';
|
||||
const cmdOrCtrl = ctrlKey || metaKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
// cmd/ctrl-shift-x
|
||||
if (xKey && shiftKey && cmdOrCtrl) {
|
||||
if (xKey && shiftKey && commandOrCtrl) {
|
||||
e.preventDefault();
|
||||
setLarge(x => !x);
|
||||
}
|
||||
|
|
|
@ -653,6 +653,9 @@ export const CompositionInput = ({
|
|||
const editorKeybindingFn = React.useCallback(
|
||||
// tslint:disable-next-line cyclomatic-complexity
|
||||
(e: React.KeyboardEvent): CompositionInputEditorCommand | null => {
|
||||
const commandKey = get(window, 'platform') === 'darwin' && e.metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && e.ctrlKey;
|
||||
|
||||
if (e.key === 'Enter' && emojiResults.length > 0) {
|
||||
e.preventDefault();
|
||||
|
||||
|
@ -660,7 +663,7 @@ export const CompositionInput = ({
|
|||
}
|
||||
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
if (large && !(e.ctrlKey || e.metaKey)) {
|
||||
if (large && !(controlKey || commandKey)) {
|
||||
return getDefaultKeyBinding(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import { AutoSizer, List } from 'react-virtualized';
|
||||
import { debounce } from 'lodash';
|
||||
import { debounce, get } from 'lodash';
|
||||
|
||||
import {
|
||||
ConversationListItem,
|
||||
|
@ -128,7 +128,9 @@ export class LeftPane extends React.Component<PropsType> {
|
|||
};
|
||||
|
||||
public handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
const commandOrCtrl = event.metaKey || event.ctrlKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && event.metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && event.ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
if (commandOrCtrl && !event.shiftKey && event.key === 'ArrowUp') {
|
||||
this.scrollToRow(0);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { debounce } from 'lodash';
|
||||
import { debounce, get } from 'lodash';
|
||||
import { Manager, Popper, Reference } from 'react-popper';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
|
@ -222,10 +222,12 @@ export class MainHeader extends React.Component<PropsType, StateType> {
|
|||
} = this.props;
|
||||
|
||||
const { ctrlKey, metaKey, key } = event;
|
||||
const ctrlOrCommand = ctrlKey || metaKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
// On linux, this keyboard combination selects all text
|
||||
if (ctrlOrCommand && key === '/') {
|
||||
if (commandOrCtrl && key === '/') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
CellMeasurerCache,
|
||||
List,
|
||||
} from 'react-virtualized';
|
||||
import { debounce, isNumber } from 'lodash';
|
||||
import { debounce, get, isNumber } from 'lodash';
|
||||
|
||||
import { Intl } from './Intl';
|
||||
import { Emojify } from './conversation/Emojify';
|
||||
|
@ -136,7 +136,9 @@ export class SearchResults extends React.Component<PropsType, StateType> {
|
|||
|
||||
public handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
const { items } = this.props;
|
||||
const commandOrCtrl = event.metaKey || event.ctrlKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && event.metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && event.ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
if (!items || items.length < 1) {
|
||||
return;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { debounce, isNumber } from 'lodash';
|
||||
import { debounce, get, isNumber } from 'lodash';
|
||||
import React from 'react';
|
||||
import {
|
||||
AutoSizer,
|
||||
|
@ -926,7 +926,9 @@ export class Timeline extends React.PureComponent<Props, State> {
|
|||
|
||||
public handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
const { selectMessage, selectedMessageId, items, id } = this.props;
|
||||
const commandOrCtrl = event.metaKey || event.ctrlKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && event.metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && event.ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
if (!items || items.length < 1) {
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { noop } from 'lodash';
|
||||
import { get, noop } from 'lodash';
|
||||
import { Manager, Popper, Reference } from 'react-popper';
|
||||
import { createPortal } from 'react-dom';
|
||||
import {
|
||||
|
@ -86,7 +86,9 @@ export const EmojiButton = React.memo(
|
|||
() => {
|
||||
const handleKeydown = (event: KeyboardEvent) => {
|
||||
const { ctrlKey, key, metaKey, shiftKey } = event;
|
||||
const ctrlOrCommand = metaKey || ctrlKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
// We don't want to open up if the conversation has any panels open
|
||||
const panels = document.querySelectorAll('.conversation .panel');
|
||||
|
@ -94,7 +96,7 @@ export const EmojiButton = React.memo(
|
|||
return;
|
||||
}
|
||||
|
||||
if (ctrlOrCommand && shiftKey && (key === 'j' || key === 'J')) {
|
||||
if (commandOrCtrl && shiftKey && (key === 'j' || key === 'J')) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { noop } from 'lodash';
|
||||
import { get, noop } from 'lodash';
|
||||
import { Manager, Popper, Reference } from 'react-popper';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { StickerPicker } from './StickerPicker';
|
||||
|
@ -152,7 +152,9 @@ export const StickerButton = React.memo(
|
|||
() => {
|
||||
const handleKeydown = (event: KeyboardEvent) => {
|
||||
const { ctrlKey, key, metaKey, shiftKey } = event;
|
||||
const ctrlOrCommand = metaKey || ctrlKey;
|
||||
const commandKey = get(window, 'platform') === 'darwin' && metaKey;
|
||||
const controlKey = get(window, 'platform') !== 'darwin' && ctrlKey;
|
||||
const commandOrCtrl = commandKey || controlKey;
|
||||
|
||||
// We don't want to open up if the conversation has any panels open
|
||||
const panels = document.querySelectorAll('.conversation .panel');
|
||||
|
@ -160,7 +162,7 @@ export const StickerButton = React.memo(
|
|||
return;
|
||||
}
|
||||
|
||||
if (ctrlOrCommand && shiftKey && (key === 's' || key === 'S')) {
|
||||
if (commandOrCtrl && shiftKey && (key === 's' || key === 'S')) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
|
|
|
@ -7577,7 +7577,7 @@
|
|||
"rule": "React-createRef",
|
||||
"path": "ts/components/MainHeader.js",
|
||||
"line": " this.inputRef = react_1.default.createRef();",
|
||||
"lineNumber": 142,
|
||||
"lineNumber": 144,
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2019-08-09T21:17:57.798Z",
|
||||
"reasonDetail": "Used only to set focus"
|
||||
|
|
Loading…
Reference in a new issue