1
- const { app, dialog, BrowserWindow, Menu, MenuItem, shell, ipcMain} = require ( 'electron' ) ;
1
+ const { app, dialog, clipboard , BrowserWindow, Menu, MenuItem, shell, ipcMain} = require ( 'electron' ) ;
2
2
const _ = require ( 'underscore' ) ;
3
3
const serve = require ( 'electron-serve' ) ;
4
4
const contextMenu = require ( 'electron-context-menu' ) ;
@@ -12,6 +12,7 @@ const CONST = require('../src/CONST').default;
12
12
const Localize = require ( '../src/libs/Localize' ) ;
13
13
14
14
const port = process . env . PORT || 8080 ;
15
+ const { DESKTOP_SHORTCUT_ACCELERATOR } = CONST ;
15
16
16
17
app . setName ( 'New Expensify' ) ;
17
18
@@ -25,16 +26,32 @@ app.setName('New Expensify');
25
26
// See: https://github.com/electron/electron/issues/22597
26
27
app . commandLine . appendSwitch ( 'enable-network-information-downlink-max' ) ;
27
28
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
+
28
39
// Initialize the right click menu
29
40
// See https://github.com/sindresorhus/electron-context-menu
30
41
// Add the Paste and Match Style command to the context menu
31
42
contextMenu ( {
32
- append : ( defaultActions , parameters ) => [
43
+ append : ( defaultActions , parameters , browserWindow ) => [
33
44
new MenuItem ( {
34
45
// Only enable the menu item for Editable context which supports paste
35
46
visible : parameters . isEditable && parameters . editFlags . canPaste ,
36
47
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 ) ,
38
55
} ) ,
39
56
] ,
40
57
} ) ;
@@ -323,7 +340,16 @@ const mainWindow = () => {
323
340
{ id : 'cut' , role : 'cut' } ,
324
341
{ id : 'copy' , role : 'copy' } ,
325
342
{ 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
+ } ,
327
353
{ id : 'delete' , role : 'delete' } ,
328
354
{ id : 'selectAll' , role : 'selectAll' } ,
329
355
{ type : 'separator' } ,
0 commit comments