mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-04-02 04:51:49 +00:00
This closes #1144 by adding a "Copy as plain text" function in Edit menu. Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>
This commit is contained in:
parent
35fb0fa7ff
commit
64ed2a856b
@ -10,7 +10,7 @@ import {
|
|||||||
} from 'electron';
|
} from 'electron';
|
||||||
import * as log from 'loglevel';
|
import * as log from 'loglevel';
|
||||||
|
|
||||||
import { isOSX, openExternal } from '../helpers/helpers';
|
import { cleanupPlainText, isOSX, openExternal } from '../helpers/helpers';
|
||||||
import {
|
import {
|
||||||
clearAppData,
|
clearAppData,
|
||||||
getCurrentURL,
|
getCurrentURL,
|
||||||
@ -94,6 +94,15 @@ export function generateMenu(
|
|||||||
accelerator: 'CmdOrCtrl+C',
|
accelerator: 'CmdOrCtrl+C',
|
||||||
role: 'copy',
|
role: 'copy',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Copy as Plain Text',
|
||||||
|
accelerator: 'CmdOrCtrl+Shift+C',
|
||||||
|
click: (): void => {
|
||||||
|
// We use clipboard.readText to strip down formatting
|
||||||
|
const text = clipboard.readText('selection');
|
||||||
|
clipboard.writeText(cleanupPlainText(text), 'clipboard');
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Copy Current URL',
|
label: 'Copy Current URL',
|
||||||
accelerator: 'CmdOrCtrl+L',
|
accelerator: 'CmdOrCtrl+L',
|
||||||
|
@ -2,6 +2,7 @@ import {
|
|||||||
linkIsInternal,
|
linkIsInternal,
|
||||||
getCounterValue,
|
getCounterValue,
|
||||||
removeUserAgentSpecifics,
|
removeUserAgentSpecifics,
|
||||||
|
cleanupPlainText,
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
|
|
||||||
const internalUrl = 'https://medium.com/';
|
const internalUrl = 'https://medium.com/';
|
||||||
@ -261,3 +262,9 @@ describe('removeUserAgentSpecifics', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('cleanupPlainText', () => {
|
||||||
|
test('removes extra spaces from text', () => {
|
||||||
|
expect(cleanupPlainText(' this is a test ')).toBe('this is a test');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -185,3 +185,8 @@ export function removeUserAgentSpecifics(
|
|||||||
.replace(`Electron/${process.versions.electron} `, '')
|
.replace(`Electron/${process.versions.electron} `, '')
|
||||||
.replace(`${appName}/${appVersion} `, ' ');
|
.replace(`${appName}/${appVersion} `, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes extra spaces from a text */
|
||||||
|
export function cleanupPlainText(text: string): string {
|
||||||
|
return text.trim().replace(/\s+/g, ' ');
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user