diff --git a/js/background.js b/js/background.js index 420e5ee9b..65ad3e24a 100644 --- a/js/background.js +++ b/js/background.js @@ -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') ) { diff --git a/ts/components/CompositionArea.tsx b/ts/components/CompositionArea.tsx index 4aa1bd091..4a2403822 100644 --- a/ts/components/CompositionArea.tsx +++ b/ts/components/CompositionArea.tsx @@ -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); } diff --git a/ts/components/CompositionInput.tsx b/ts/components/CompositionInput.tsx index b30721b98..8dab07a6f 100644 --- a/ts/components/CompositionInput.tsx +++ b/ts/components/CompositionInput.tsx @@ -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); } diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 3afa6ca96..e9a97c6a5 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -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 { }; public handleKeyDown = (event: React.KeyboardEvent) => { - 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); diff --git a/ts/components/MainHeader.tsx b/ts/components/MainHeader.tsx index 68eaaf3c9..dbfe8eb6e 100644 --- a/ts/components/MainHeader.tsx +++ b/ts/components/MainHeader.tsx @@ -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 { } = 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(); diff --git a/ts/components/SearchResults.tsx b/ts/components/SearchResults.tsx index 1fba614aa..09ee9a70c 100644 --- a/ts/components/SearchResults.tsx +++ b/ts/components/SearchResults.tsx @@ -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 { public handleKeyDown = (event: React.KeyboardEvent) => { 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; diff --git a/ts/components/conversation/Timeline.tsx b/ts/components/conversation/Timeline.tsx index 8aa4dd276..ee548d16c 100644 --- a/ts/components/conversation/Timeline.tsx +++ b/ts/components/conversation/Timeline.tsx @@ -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 { public handleKeyDown = (event: React.KeyboardEvent) => { 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; diff --git a/ts/components/emoji/EmojiButton.tsx b/ts/components/emoji/EmojiButton.tsx index b9b702f7c..022ddc49b 100644 --- a/ts/components/emoji/EmojiButton.tsx +++ b/ts/components/emoji/EmojiButton.tsx @@ -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(); diff --git a/ts/components/stickers/StickerButton.tsx b/ts/components/stickers/StickerButton.tsx index bafd4a566..0f0611989 100644 --- a/ts/components/stickers/StickerButton.tsx +++ b/ts/components/stickers/StickerButton.tsx @@ -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(); diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 9e8fa9913..bf1f7b2a7 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -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"