git ssb

16+

Dominic / patchbay



Commit 0e255bdfe32790e9ab40d3c4329f6513dd107d6e

add right-click copy options!

mix irving committed on 2/10/2017, 10:00:15 AM
Parent: cdd29b4f3b975fc5d52747af2ee7173ae1bf0958

Files changed

modules_basic/message/render.jschanged
modules_core/tabs.jschanged
modules_basic/message/render.jsView
@@ -34,9 +34,11 @@
3434
3535 var msgEl = h('Message', {
3636 'ev-keydown': navigateToMessageOnEnter,
3737 attributes: {
38- tabindex: '0'
38 + tabindex: '0',
39 + 'data-key': msg.key,
40 + 'data-text': msg.value.content.text
3941 }
4042 }, [
4143 h('header.author', api.message_author(msg)),
4244 h('section.title', api.message_title(msg)),
@@ -70,9 +72,10 @@
7072
7173 function mini(msg, el) {
7274 return h('Message -mini', {
7375 attributes: {
74- tabindex: '0'
76 + tabindex: '0',
77 + 'data-key': msg.key
7578 }
7679 }, [
7780 h('header.author', api.message_author(msg, { size: 'mini' })),
7881 h('section.meta', api.message_meta(msg)),
modules_core/tabs.jsView
@@ -1,16 +1,10 @@
11 const Tabs = require('hypertabs')
22 const h = require('../h')
33 const keyscroll = require('../keyscroll')
44 const open = require('open-external')
5-const { webFrame, remote } = require('electron')
5 +const { webFrame, remote, clipboard } = require('electron')
66
7-function ancestor (el) {
8- if(!el) return
9- if(el.tagName !== 'A') return ancestor(el.parentElement)
10- return el
11-}
12-
137 exports.needs = {
148 build_error: 'first',
159 build_scroller: 'first',
1610 screen_view: 'first',
@@ -79,9 +73,9 @@
7973 search.input.value = null // start with an empty field to show placeholder
8074
8175 //handle link clicks
8276 window.onclick = function (ev) {
83- var link = ancestor(ev.target)
77 + var link = ancestorAnchor(ev.target)
8478 if(!link) return
8579 var path = link.hash.substring(1)
8680
8781 ev.preventDefault()
@@ -222,12 +216,43 @@
222216 click: () => {
223217 remote.getCurrentWindow().inspectElement(ev.x, ev.y)
224218 }
225219 }))
220 +
221 + var message = ancestorMessage(ev.target)
222 + if (message && message.dataset.key) {
223 + menu.append(new MenuItem({
224 + label: 'Copy id',
225 + click: () => clipboard.writeText(message.dataset.key)
226 + }))
227 + }
228 + if (message && message.dataset.text) {
229 + menu.append(new MenuItem({
230 + label: 'Copy text',
231 + click: () => clipboard.writeText(message.dataset.text)
232 + }))
233 + }
226234 menu.popup(remote.getCurrentWindow())
227235 })
228236 }
229237
230238 return tabs
231239 }
240 +}
232241
242 +function ancestorAnchor (el) {
243 + if(!el) return
244 + if(el.tagName !== 'A') return ancestorAnchor(el.parentElement)
245 + return el
233246 }
247 +
248 +function ancestorMessage (el) {
249 + if(!el) return
250 + if(!el.classList.contains('Message')) {
251 + if (el.parentElement)
252 + return ancestorMessage(el.parentElement)
253 + else
254 + return null
255 + }
256 + return el
257 +}
258 +

Built with git-ssb-web