code climate and enable Cmd+C copy

This commit is contained in:
Devin Howard 2016-10-07 13:56:30 +08:00
parent 26189edb74
commit 99be53225c
3 changed files with 12 additions and 11 deletions

View file

@ -11,7 +11,9 @@ import Selected from './Selected'
const Export = { const Export = {
data: null, data: null,
copySelection: function() { copySelection: function () {
// clipboard.copy can't be called in a different callback - it has to be directly
// inside an event listener. So to work around this, we require two Ctrl+C presses
if (Export.data === null) { if (Export.data === null) {
Export.loadCopyData() Export.loadCopyData()
} else { } else {
@ -27,16 +29,16 @@ const Export = {
} }
}, },
loadCopyData: function() { loadCopyData: function () {
if (!Active.Map) return // someday we can expand this if (!Active.Map) return // someday we can expand this
const topics = Selected.Nodes.map(node => node.getData('topic').id) const topics = Selected.Nodes.map(node => node.getData('topic').id)
// deselect synapses not joined to a selected topic // deselect synapses not joined to a selected topic
Selected.Edges.slice(0).forEach(edge => { Selected.Edges.slice(0).forEach(edge => {
const synapse = edge.getData('synapses')[edge.getData('displayIndex')] const synapse = edge.getData('synapses')[edge.getData('displayIndex')]
const topic1_id = synapse.get('topic1_id') const topic1Id = synapse.get('topic1_id')
const topic2_id = synapse.get('topic2_id') const topic2Id = synapse.get('topic2_id')
if (topics.indexOf(topic1_id) === -1 || topics.indexOf(topic2_id) === -1) { if (topics.indexOf(topic1Id) === -1 || topics.indexOf(topic2Id) === -1) {
Control.deselectEdge(edge) Control.deselectEdge(edge)
} }
}) })

View file

@ -280,8 +280,8 @@ const Import = {
topic1, topic2, { topic1, topic2, {
success: synapse => { success: synapse => {
Control.selectEdge(synapse.get('edge')) Control.selectEdge(synapse.get('edge'))
} }
} }
) )
}) })
}) })

View file

@ -1,7 +1,5 @@
/* global $ */ /* global $ */
import clipboard from 'clipboard-js'
import Active from './Active' import Active from './Active'
import Create from './Create' import Create from './Create'
import Control from './Control' import Control from './Control'
@ -94,7 +92,8 @@ const Listeners = {
break break
case 67: // if c or C is pressed case 67: // if c or C is pressed
if (e.ctrlKey && e.target.tagName === 'BODY') { // metaKey is OSX command key for Cmd+C
if ((e.ctrlKey || e.metaKey) && e.target.tagName === 'BODY') {
Export.copySelection() Export.copySelection()
} }
break break