Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 6485cc5

Browse files
committed
Implement copy as a local shortcut on OS X
Potential workaround for #1060 Auditors: @bbondy
1 parent 65e5321 commit 6485cc5

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

app/localShortcuts.js

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ module.exports.register = (win) => {
3636
const focusedWindow = win || BrowserWindow.getFocusedWindow()
3737
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
3838
})
39+
} else {
40+
// Workaround for #1060
41+
simpleWebContentEvents.push([
42+
'Cmd+C',
43+
messages.SHORTCUT_ACTIVE_FRAME_COPY
44+
])
3945
}
4046

4147
// Tab ordering shortcuts

js/components/frame.js

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const contextMenus = require('../contextMenus')
1717
const config = require('../constants/config.js')
1818
const siteHacks = require('../data/siteHacks')
1919
const ipc = global.require('electron').ipcRenderer
20+
const clipboard = global.require('electron').clipboard
2021
const FullScreenWarning = require('./fullScreenWarning')
2122
const debounce = require('../lib/debounce.js')
2223
const getSetting = require('../settings').getSetting
@@ -297,6 +298,14 @@ class Frame extends ImmutableComponent {
297298
case 'load-non-navigatable-url':
298299
this.webview.loadURL(this.props.frame.get('activeShortcutDetails'))
299300
break
301+
case 'copy':
302+
let selection = window.getSelection()
303+
if (selection && selection.toString()) {
304+
clipboard.writeText(selection.toString())
305+
} else {
306+
this.webview.copy()
307+
}
308+
break
300309
}
301310
if (activeShortcut) {
302311
windowActions.setActiveFrameShortcut(this.props.frame, null, null)

js/constants/messages.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const messages = {
2727
SHORTCUT_ACTIVE_FRAME_BOOKMARK: _,
2828
SHORTCUT_ACTIVE_FRAME_REMOVE_BOOKMARK: _,
2929
SHORTCUT_ACTIVE_FRAME_LOAD_URL: _, /** @arg {string} url to load */
30+
SHORTCUT_ACTIVE_FRAME_COPY: _,
3031
// Frame management shortcuts
3132
SHORTCUT_NEW_FRAME: _, /** @arg {string} opt_url to load if any */
3233
SHORTCUT_CLOSE_FRAME: _, /** @arg {number} opt_key of frame, defaults to active frame */

js/stores/windowStore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ ipc.on(messages.IMPORT_BOOKMARKS, () => {
604604
}
605605
})
606606

607-
const frameShortcuts = ['stop', 'reload', 'zoom-in', 'zoom-out', 'zoom-reset', 'toggle-dev-tools', 'clean-reload', 'view-source', 'mute', 'save', 'print', 'show-findbar']
607+
const frameShortcuts = ['stop', 'reload', 'zoom-in', 'zoom-out', 'zoom-reset', 'toggle-dev-tools', 'clean-reload', 'view-source', 'mute', 'save', 'print', 'show-findbar', 'copy']
608608
frameShortcuts.forEach((shortcut) => {
609609
// Listen for actions on the active frame
610610
ipc.on(`shortcut-active-frame-${shortcut}`, () => {

0 commit comments

Comments
 (0)