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