Skip to content

Commit 1c8f935

Browse files
authored
Merge pull request #24029 from ygshbht/paste-as-plain-text
Paste as plain text
2 parents 4230f28 + aeb0d0c commit 1c8f935

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

desktop/main.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {app, dialog, BrowserWindow, Menu, MenuItem, shell, ipcMain} = require('electron');
1+
const {app, dialog, clipboard, BrowserWindow, Menu, MenuItem, shell, ipcMain} = require('electron');
22
const _ = require('underscore');
33
const serve = require('electron-serve');
44
const contextMenu = require('electron-context-menu');
@@ -12,6 +12,7 @@ const CONST = require('../src/CONST').default;
1212
const Localize = require('../src/libs/Localize');
1313

1414
const port = process.env.PORT || 8080;
15+
const {DESKTOP_SHORTCUT_ACCELERATOR} = CONST;
1516

1617
app.setName('New Expensify');
1718

@@ -25,16 +26,32 @@ app.setName('New Expensify');
2526
// See: https://github.com/electron/electron/issues/22597
2627
app.commandLine.appendSwitch('enable-network-information-downlink-max');
2728

29+
/**
30+
* Inserts the plain text from the clipboard into the provided browser window's web contents.
31+
*
32+
* @param {BrowserWindow} browserWindow - The Electron BrowserWindow instance where the text should be inserted.
33+
*/
34+
function pasteAsPlainText(browserWindow) {
35+
const text = clipboard.readText();
36+
browserWindow.webContents.insertText(text);
37+
}
38+
2839
// Initialize the right click menu
2940
// See https://github.com/sindresorhus/electron-context-menu
3041
// Add the Paste and Match Style command to the context menu
3142
contextMenu({
32-
append: (defaultActions, parameters) => [
43+
append: (defaultActions, parameters, browserWindow) => [
3344
new MenuItem({
3445
// Only enable the menu item for Editable context which supports paste
3546
visible: parameters.isEditable && parameters.editFlags.canPaste,
3647
role: 'pasteAndMatchStyle',
37-
accelerator: 'CmdOrCtrl+Shift+V',
48+
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AND_MATCH_STYLE,
49+
}),
50+
new MenuItem({
51+
label: Localize.translate(CONST.LOCALES.DEFAULT, 'desktopApplicationMenu.pasteAsPlainText'),
52+
visible: parameters.isEditable && parameters.editFlags.canPaste && clipboard.readText().length > 0,
53+
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AS_PLAIN_TEXT,
54+
click: () => pasteAsPlainText(browserWindow),
3855
}),
3956
],
4057
});
@@ -323,7 +340,16 @@ const mainWindow = () => {
323340
{id: 'cut', role: 'cut'},
324341
{id: 'copy', role: 'copy'},
325342
{id: 'paste', role: 'paste'},
326-
{id: 'pasteAndMatchStyle', role: 'pasteAndMatchStyle'},
343+
{
344+
id: 'pasteAndMatchStyle',
345+
role: 'pasteAndMatchStyle',
346+
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AND_MATCH_STYLE,
347+
},
348+
{
349+
id: 'pasteAsPlainText',
350+
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AS_PLAIN_TEXT,
351+
click: () => pasteAsPlainText(browserWindow),
352+
},
327353
{id: 'delete', role: 'delete'},
328354
{id: 'selectAll', role: 'selectAll'},
329355
{type: 'separator'},

src/CONST.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ const CONST = {
141141
MAX_AGE: 150,
142142
},
143143

144+
DESKTOP_SHORTCUT_ACCELERATOR: {
145+
PASTE_AND_MATCH_STYLE: 'Option+Shift+CmdOrCtrl+V',
146+
PASTE_AS_PLAIN_TEXT: 'CmdOrCtrl+Shift+V',
147+
},
148+
144149
// This is used to enable a rotation/transform style to any component.
145150
DIRECTION: {
146151
LEFT: 'left',

src/languages/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ export default {
14271427
copy: 'Copy',
14281428
paste: 'Paste',
14291429
pasteAndMatchStyle: 'Paste and Match Style',
1430+
pasteAsPlainText: 'Paste as Plain Text',
14301431
delete: 'Delete',
14311432
selectAll: 'Select All',
14321433
speechSubmenu: 'Speech',

src/languages/es.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ export default {
14381438
copy: 'Copiar',
14391439
paste: 'Pegar',
14401440
pasteAndMatchStyle: 'Pegar adaptando el estilo',
1441+
pasteAsPlainText: 'Pegar como texto sin formato',
14411442
delete: 'Eliminar',
14421443
selectAll: 'Seleccionar todo',
14431444
speechSubmenu: 'Voz',

0 commit comments

Comments
 (0)