mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-22 10:08:55 +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';
|
||||
import * as log from 'loglevel';
|
||||
|
||||
import { isOSX, openExternal } from '../helpers/helpers';
|
||||
import { cleanupPlainText, isOSX, openExternal } from '../helpers/helpers';
|
||||
import {
|
||||
clearAppData,
|
||||
getCurrentURL,
|
||||
@ -94,6 +94,15 @@ export function generateMenu(
|
||||
accelerator: 'CmdOrCtrl+C',
|
||||
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',
|
||||
accelerator: 'CmdOrCtrl+L',
|
||||
|
@ -2,6 +2,7 @@ import {
|
||||
linkIsInternal,
|
||||
getCounterValue,
|
||||
removeUserAgentSpecifics,
|
||||
cleanupPlainText,
|
||||
} from './helpers';
|
||||
|
||||
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(`${appName}/${appVersion} `, ' ');
|
||||
}
|
||||
|
||||
/** Removes extra spaces from a text */
|
||||
export function cleanupPlainText(text: string): string {
|
||||
return text.trim().replace(/\s+/g, ' ');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user