Add copy text on contex menu.
This commit is contained in:
parent
0cd5ef9ab4
commit
5cbd366cf2
4 changed files with 40 additions and 34 deletions
|
@ -7,6 +7,7 @@ import ReactModal from 'react-modal';
|
||||||
import throttle from 'util/throttle';
|
import throttle from 'util/throttle';
|
||||||
import SideBar from 'component/sideBar';
|
import SideBar from 'component/sideBar';
|
||||||
import Header from 'component/header';
|
import Header from 'component/header';
|
||||||
|
import { openContextMenu } from '../../util/contextMenu';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
alertError: (string | {}) => void,
|
alertError: (string | {}) => void,
|
||||||
|
@ -79,7 +80,7 @@ class App extends React.PureComponent<Props> {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div id="window">
|
<div id="window" onContextMenu={e => openContextMenu(e)}>
|
||||||
<Theme />
|
<Theme />
|
||||||
<main className="page">
|
<main className="page">
|
||||||
<SideBar />
|
<SideBar />
|
||||||
|
|
|
@ -62,6 +62,8 @@ class FileCard extends React.PureComponent<Props> {
|
||||||
const shouldObscureNsfw = obscureNsfw && metadata && metadata.nsfw;
|
const shouldObscureNsfw = obscureNsfw && metadata && metadata.nsfw;
|
||||||
const isRewardContent = claim && rewardedContentClaimIds.includes(claim.claim_id);
|
const isRewardContent = claim && rewardedContentClaimIds.includes(claim.claim_id);
|
||||||
const handleContextMenu = event => {
|
const handleContextMenu = event => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
openCopyLinkMenu(convertToShareLink(uri), event);
|
openCopyLinkMenu(convertToShareLink(uri), event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ import store from 'store';
|
||||||
import app from './app';
|
import app from './app';
|
||||||
import analytics from './analytics';
|
import analytics from './analytics';
|
||||||
import doLogWarningConsoleMessage from './logWarningConsoleMessage';
|
import doLogWarningConsoleMessage from './logWarningConsoleMessage';
|
||||||
import { initContextMenu } from './util/contextMenu';
|
|
||||||
|
|
||||||
const { autoUpdater } = remote.require('electron-updater');
|
const { autoUpdater } = remote.require('electron-updater');
|
||||||
const APPPAGEURL = 'lbry://?';
|
const APPPAGEURL = 'lbry://?';
|
||||||
|
@ -113,8 +112,6 @@ document.addEventListener('click', event => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('contextmenu', initContextMenu);
|
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
autoUpdater.on('update-downloaded', () => {
|
autoUpdater.on('update-downloaded', () => {
|
||||||
app.store.dispatch(doAutoUpdate());
|
app.store.dispatch(doAutoUpdate());
|
||||||
|
@ -149,7 +146,7 @@ const init = () => {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<div>
|
<div>
|
||||||
<App onContextMenu={e => openContextMenu(e)} />
|
<App />
|
||||||
<SnackBar />
|
<SnackBar />
|
||||||
</div>
|
</div>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
|
|
|
@ -21,26 +21,41 @@ function injectDevelopmentTemplate(event, templates) {
|
||||||
return templates;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openContextMenu(event, templates = [], addDefaultTemplates = true) {
|
export function openContextMenu(event, templates = []) {
|
||||||
if (addDefaultTemplates) {
|
const isSomethingSelected = window.getSelection().toString().length > 0;
|
||||||
|
const { type } = event.target;
|
||||||
|
const isInput = event.target.matches('input') && (type === 'text' || type === 'number');
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
const inputTemplates = [
|
|
||||||
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' },
|
templates.push({
|
||||||
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', role: 'copy' },
|
label: 'Copy',
|
||||||
{
|
accelerator: 'CmdOrCtrl+C',
|
||||||
|
role: 'copy',
|
||||||
|
enabled: isSomethingSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
// If context menu is opened on Input and there is text on the input and something is selected.
|
||||||
|
const { selectionStart, selectionEnd } = event.target;
|
||||||
|
if (!!value && isInput && selectionStart !== selectionEnd) {
|
||||||
|
templates.push({ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// If context menu is opened on Input and text is present on clipboard
|
||||||
|
if (clipboard.readText().length > 0 && isInput) {
|
||||||
|
templates.push({
|
||||||
label: 'Paste',
|
label: 'Paste',
|
||||||
accelerator: 'CmdOrCtrl+V',
|
accelerator: 'CmdOrCtrl+V',
|
||||||
role: 'paste',
|
role: 'paste',
|
||||||
enabled: clipboard.readText().length > 0,
|
});
|
||||||
},
|
}
|
||||||
{
|
|
||||||
|
// If context menu is opened on Input
|
||||||
|
if (isInput && value) {
|
||||||
|
templates.push({
|
||||||
label: 'Select All',
|
label: 'Select All',
|
||||||
accelerator: 'CmdOrCtrl+A',
|
accelerator: 'CmdOrCtrl+A',
|
||||||
role: 'selectall',
|
role: 'selectall',
|
||||||
enabled: !!value,
|
});
|
||||||
},
|
|
||||||
];
|
|
||||||
templates.push(...inputTemplates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
injectDevelopmentTemplate(event, templates);
|
injectDevelopmentTemplate(event, templates);
|
||||||
|
@ -57,12 +72,3 @@ export function openCopyLinkMenu(text, event) {
|
||||||
];
|
];
|
||||||
openContextMenu(event, templates, false);
|
openContextMenu(event, templates, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initContextMenu(event) {
|
|
||||||
const { type } = event.target;
|
|
||||||
if (event.target.matches('input') && (type === 'text' || type === 'number')) {
|
|
||||||
openContextMenu(event);
|
|
||||||
} else {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue