From 99be53225cd2795c1a6f7565fd89f490a234b588 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 7 Oct 2016 13:56:30 +0800 Subject: [PATCH] code climate and enable Cmd+C copy --- frontend/src/Metamaps/Export.js | 14 ++++++++------ frontend/src/Metamaps/Import.js | 4 ++-- frontend/src/Metamaps/Listeners.js | 5 ++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/frontend/src/Metamaps/Export.js b/frontend/src/Metamaps/Export.js index 4f8ab8b9..115de12c 100644 --- a/frontend/src/Metamaps/Export.js +++ b/frontend/src/Metamaps/Export.js @@ -11,7 +11,9 @@ import Selected from './Selected' const Export = { 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) { Export.loadCopyData() } else { @@ -27,16 +29,16 @@ const Export = { } }, - loadCopyData: function() { + loadCopyData: function () { if (!Active.Map) return // someday we can expand this const topics = Selected.Nodes.map(node => node.getData('topic').id) // deselect synapses not joined to a selected topic Selected.Edges.slice(0).forEach(edge => { const synapse = edge.getData('synapses')[edge.getData('displayIndex')] - const topic1_id = synapse.get('topic1_id') - const topic2_id = synapse.get('topic2_id') - if (topics.indexOf(topic1_id) === -1 || topics.indexOf(topic2_id) === -1) { + const topic1Id = synapse.get('topic1_id') + const topic2Id = synapse.get('topic2_id') + if (topics.indexOf(topic1Id) === -1 || topics.indexOf(topic2Id) === -1) { Control.deselectEdge(edge) } }) @@ -44,7 +46,7 @@ const Export = { const synapses = Selected.Edges.map(edge => { return edge.getData('synapses')[edge.getData('displayIndex')].id }) - + const url = `/maps/${Active.Map.id}/export.json` const query = `topic_ids=${topics.join(',')}&synapse_ids=${synapses.join(',')}` $.ajax(`${url}?${query}`, { diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index a7727c5d..535058dc 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -280,8 +280,8 @@ const Import = { topic1, topic2, { success: synapse => { Control.selectEdge(synapse.get('edge')) - } - } + } + } ) }) }) diff --git a/frontend/src/Metamaps/Listeners.js b/frontend/src/Metamaps/Listeners.js index c60ba2dc..edcb0161 100644 --- a/frontend/src/Metamaps/Listeners.js +++ b/frontend/src/Metamaps/Listeners.js @@ -1,7 +1,5 @@ /* global $ */ -import clipboard from 'clipboard-js' - import Active from './Active' import Create from './Create' import Control from './Control' @@ -94,7 +92,8 @@ const Listeners = { break 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() } break