2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-22 10:08:55 +00:00

Feature: Add "copy as plain text" in edit menu (PR #1351, fix #1144)

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:
Abhishek Mehandiratta 2022-02-10 19:09:56 +05:30 committed by GitHub
parent 35fb0fa7ff
commit 64ed2a856b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -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',

View File

@ -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');
});
});

View File

@ -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, ' ');
}