Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Reimplement copy/paste in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotdrew committed Feb 17, 2017
1 parent 1c47a21 commit 122b524
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
9 changes: 2 additions & 7 deletions keymaps/learn-ide.cson
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 4 additions & 0 deletions lib/learn-ide.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions lib/terminal-view.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{$, View} = require 'atom-space-pen-views'
{clipboard} = require 'electron'
TerminalEmulator = require 'xterm'
TerminalEmulator.loadAddon 'fit'

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/updater.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fs = require 'fs'
path = require 'path'
{shell} = require 'electron'
semver = require 'semver'
{learnCo} = require './config'
fetch = require './fetch'
Expand Down Expand Up @@ -172,6 +171,8 @@ module.exports =
false

_updateFailed: (detail) ->
{shell, clipboard} = require 'electron'

description = 'The installation seems to have been interrupted.'
buttons = [
{
Expand All @@ -191,7 +192,6 @@ module.exports =
buttons.push
text: 'Copy this log'
onDidClick: ->
{clipboard} = require 'electron'
clipboard.writeText(detail)

@updateNotification =
Expand Down
6 changes: 3 additions & 3 deletions menus/learn-ide.cson
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 122b524

Please sign in to comment.