From 122b52443b996e73aeb20374ddaec33aa44d034f Mon Sep 17 00:00:00 2001 From: drewprice Date: Fri, 17 Feb 2017 14:30:37 -0500 Subject: [PATCH] Reimplement copy/paste in terminal --- keymaps/learn-ide.cson | 9 ++------- lib/learn-ide.coffee | 4 ++++ lib/terminal-view.coffee | 14 ++++++++++++++ lib/updater.coffee | 4 ++-- menus/learn-ide.cson | 6 +++--- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/keymaps/learn-ide.cson b/keymaps/learn-ide.cson index b3d94d2..da91688 100644 --- a/keymaps/learn-ide.cson +++ b/keymaps/learn-ide.cson @@ -2,17 +2,12 @@ 'cmd-i': 'learn-ide:toggle-terminal' 'cmd-;': 'learn-ide:toggle-focus' -'.platform-darwin .learn-terminal': - 'cmd-c': 'learn-ide:copy' - 'cmd-v': 'learn-ide:paste' +'.platform-darwin .terminal': 'cmd-=': 'learn-ide:increase-font-size' 'cmd--': 'learn-ide:decrease-font-size' 'cmd-0': 'learn-ide:reset-font-size' -'.platform-win32 .learn-terminal': - # TODO: make these work & remove listeners in TerminalView - # 'ctrl-shift-C': 'learn-ide:copy' - # 'ctrl-shift-V': 'learn-ide:paste' +'.platform-win32 .terminal': 'ctrl-+': 'learn-ide:increase-font-size' 'ctrl-_': 'learn-ide:decrease-font-size' 'ctrl-0': 'learn-ide:reset-font-size' diff --git a/lib/learn-ide.coffee b/lib/learn-ide.coffee index 496ff83..56e9aaf 100644 --- a/lib/learn-ide.coffee +++ b/lib/learn-ide.coffee @@ -99,6 +99,10 @@ module.exports = 'learn-ide:update-check': -> updater.checkForUpdate() 'learn-ide:about': => @about() + @subscriptions.add atom.commands.add '.terminal', + 'core:copy': => @termView.copyText() + 'core:paste': => @termView.pasteText() + atom.config.onDidChange "#{name}.terminalFontColor", ({newValue}) => @termView.updateFontColor(newValue) diff --git a/lib/terminal-view.coffee b/lib/terminal-view.coffee index 7fcb7d7..f68cec6 100644 --- a/lib/terminal-view.coffee +++ b/lib/terminal-view.coffee @@ -1,4 +1,5 @@ {$, View} = require 'atom-space-pen-views' +{clipboard} = require 'electron' TerminalEmulator = require 'xterm' TerminalEmulator.loadAddon 'fit' @@ -28,6 +29,19 @@ class TerminalView extends View atom.workspace.addBottomPanel({item: this}) @emulator.open(@emulatorContainer[0]) + copyText: -> + selection = document.getSelection() + rawText = selection.toString() + preparedText = rawText.replace(/\u00A0/g, ' ').replace(/\s+(\n)?$/gm, '$1') + + clipboard.writeText(preparedText) + + pasteText: -> + rawText = clipboard.readText() + preparedText = rawText.replace(/\n/g, '\r') + + @terminal.send(preparedText) + resizeStarted: => $(document).on('mousemove', @resizeTerminal) $(document).on('mouseup', @resizeStopped) diff --git a/lib/updater.coffee b/lib/updater.coffee index 19e4c70..09607c5 100644 --- a/lib/updater.coffee +++ b/lib/updater.coffee @@ -1,6 +1,5 @@ fs = require 'fs' path = require 'path' -{shell} = require 'electron' semver = require 'semver' {learnCo} = require './config' fetch = require './fetch' @@ -172,6 +171,8 @@ module.exports = false _updateFailed: (detail) -> + {shell, clipboard} = require 'electron' + description = 'The installation seems to have been interrupted.' buttons = [ { @@ -191,7 +192,6 @@ module.exports = buttons.push text: 'Copy this log' onDidClick: -> - {clipboard} = require 'electron' clipboard.writeText(detail) @updateNotification = diff --git a/menus/learn-ide.cson b/menus/learn-ide.cson index 8611f29..6da6bb6 100644 --- a/menus/learn-ide.cson +++ b/menus/learn-ide.cson @@ -5,14 +5,14 @@ 'command': 'learn-ide:toggle-terminal' } ] - '.learn-terminal': [ + '.terminal': [ { 'label': 'Copy' - 'command': 'learn-ide:copy' + 'command': 'core:copy' } { 'label': 'Paste' - 'command': 'learn-ide:paste' + 'command': 'core:paste' } { 'label': 'Hide Learn IDE Terminal'