Skip to content

Commit

Permalink
Fix: Replace an unstable function to copy
Browse files Browse the repository at this point in the history
Fix: Change copy function for electron
  • Loading branch information
bbaa77770 committed Nov 19, 2020
1 parent 307432e commit 1325029
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/app/lib/uni-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/app/widgets/Console/Terminal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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());
}
}
);
Expand Down
1 change: 0 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1325029

Please sign in to comment.