git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 57bfe1f6e7673616a9afe3a855447833537af331

add 'Copy Link Ref' to context menu

Matt McKegg committed on 3/18/2017, 5:30:58 AM
Parent: 5751bfc7a66e62b9d47d5cc86f6a753fae3f41a0

Files changed

lib/context-menu-and-spellcheck.jschanged
lib/context-menu-and-spellcheck.jsView
@@ -1,7 +1,8 @@
11 var {remote, shell, clipboard, ipcRenderer} = require('electron')
22 var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker')
33 var {MenuItem, Menu} = remote
4+var ref = require('ssb-ref')
45
56 window.spellCheckHandler = new SpellCheckHandler()
67 window.spellCheckHandler.attachToInput()
78
@@ -13,8 +14,9 @@
1314 contextMenuBuilder.buildMenuForLink = function (menuInfo) {
1415 var menu = new Menu()
1516 var isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
1617 var isFile = menuInfo.linkURL.startsWith('file:')
18+ var extractedRef = ref.extract(menuInfo.linkURL)
1719
1820 if (!isFile) {
1921 var copyLink = new MenuItem({
2022 label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
@@ -34,8 +36,19 @@
3436 menu.append(copyLink)
3537 menu.append(openLink)
3638 }
3739
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+
3851 if (this.isSrcUrlValid(menuInfo)) {
3952 if (!isFile) this.addSeparator(menu)
4053 this.addImageItems(menu, menuInfo)
4154 }

Built with git-ssb-web