Commit 57bfe1f6e7673616a9afe3a855447833537af331
add 'Copy Link Ref' to context menu
Matt McKegg committed on 3/18/2017, 5:30:58 AMParent: 5751bfc7a66e62b9d47d5cc86f6a753fae3f41a0
Files changed
lib/context-menu-and-spellcheck.js | changed |
lib/context-menu-and-spellcheck.js | ||
---|---|---|
@@ -1,7 +1,8 @@ | ||
1 | 1 … | var {remote, shell, clipboard, ipcRenderer} = require('electron') |
2 | 2 … | var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker') |
3 | 3 … | var {MenuItem, Menu} = remote |
4 … | +var ref = require('ssb-ref') | |
4 | 5 … | |
5 | 6 … | window.spellCheckHandler = new SpellCheckHandler() |
6 | 7 … | window.spellCheckHandler.attachToInput() |
7 | 8 … | |
@@ -13,8 +14,9 @@ | ||
13 | 14 … | contextMenuBuilder.buildMenuForLink = function (menuInfo) { |
14 | 15 … | var menu = new Menu() |
15 | 16 … | var isEmailAddress = menuInfo.linkURL.startsWith('mailto:') |
16 | 17 … | var isFile = menuInfo.linkURL.startsWith('file:') |
18 … | + var extractedRef = ref.extract(menuInfo.linkURL) | |
17 | 19 … | |
18 | 20 … | if (!isFile) { |
19 | 21 … | var copyLink = new MenuItem({ |
20 | 22 … | label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(), |
@@ -34,8 +36,19 @@ | ||
34 | 36 … | menu.append(copyLink) |
35 | 37 … | menu.append(openLink) |
36 | 38 … | } |
37 | 39 … | |
40 … | + if (extractedRef) { | |
41 … | + var copyRef = new MenuItem({ | |
42 … | + label: `Copy Link Ref (${extractedRef.slice(0, 10)}...)`, | |
43 … | + click: () => { | |
44 … | + // Omit the mailto: portion of the link; we just want the address | |
45 … | + clipboard.writeText(extractedRef) | |
46 … | + } | |
47 … | + }) | |
48 … | + menu.append(copyRef) | |
49 … | + } | |
50 … | + | |
38 | 51 … | if (this.isSrcUrlValid(menuInfo)) { |
39 | 52 … | if (!isFile) this.addSeparator(menu) |
40 | 53 … | this.addImageItems(menu, menuInfo) |
41 | 54 … | } |
Built with git-ssb-web