diff --git a/src/app/lib/uni-api.js b/src/app/lib/uni-api.js index c9c6ef74c4..ebd073af4c 100644 --- a/src/app/lib/uni-api.js +++ b/src/app/lib/uni-api.js @@ -241,6 +241,17 @@ const Window = { title = `${this.initTitle} / ${filename}`; } this.window.setTitle(title); + }, + + copySelection(text) { + if (isElectron()) { + const clipboard = window.require('electron').clipboard; + clipboard.writeText(text, 'selection'); + } else { + navigator.clipboard.writeText(text); + // execCommand is unstable + // document.execCommand('copy', true, text); + } } }; diff --git a/src/app/widgets/Console/Terminal.jsx b/src/app/widgets/Console/Terminal.jsx index 1346d668bb..d7334e5793 100644 --- a/src/app/widgets/Console/Terminal.jsx +++ b/src/app/widgets/Console/Terminal.jsx @@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; import React, { PureComponent } from 'react'; import { Terminal } from 'xterm'; import { FitAddon } from 'xterm-addon-fit'; +import UniApi from '../../lib/uni-api'; import log from '../../lib/log'; import styles from './index.styl'; @@ -101,7 +102,7 @@ class TerminalWrapper extends PureComponent { // } // control + c if (domEvent.ctrlKey && domEvent.key === 'c') { - document.execCommand('copy'); + UniApi.Window.copySelection(this.term.getSelection()); } } ); diff --git a/src/package.json b/src/package.json index 7cef2d4804..8acb9a1648 100755 --- a/src/package.json +++ b/src/package.json @@ -37,7 +37,6 @@ "express": "~4.16.3", "express-jwt": "~5.3.1", "express-session": "~1.15.6", - "font-manager": "^0.3.1", "hogan.js": "~3.0.2", "i18next": "~11.4.0", "i18next-express-middleware": "~1.2.0",