-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Paste as plain text #24029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paste as plain text #24029
Changes from all commits
5a834e6
be0f4fe
17edf60
72fd957
3788766
fa44ec2
e90afa7
b3e1f4a
ff5c901
c9f48fa
b51c796
2361416
aeb0d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const {app, dialog, BrowserWindow, Menu, MenuItem, shell, ipcMain} = require('electron'); | ||
const {app, dialog, clipboard, BrowserWindow, Menu, MenuItem, shell, ipcMain} = require('electron'); | ||
const _ = require('underscore'); | ||
const serve = require('electron-serve'); | ||
const contextMenu = require('electron-context-menu'); | ||
|
@@ -12,6 +12,7 @@ const CONST = require('../src/CONST').default; | |
const Localize = require('../src/libs/Localize'); | ||
|
||
const port = process.env.PORT || 8080; | ||
const {DESKTOP_SHORTCUT_ACCELERATOR} = CONST; | ||
|
||
app.setName('New Expensify'); | ||
|
||
|
@@ -25,16 +26,32 @@ app.setName('New Expensify'); | |
// See: https://github.com/electron/electron/issues/22597 | ||
app.commandLine.appendSwitch('enable-network-information-downlink-max'); | ||
|
||
/** | ||
* Inserts the plain text from the clipboard into the provided browser window's web contents. | ||
* | ||
* @param {BrowserWindow} browserWindow - The Electron BrowserWindow instance where the text should be inserted. | ||
*/ | ||
function pasteAsPlainText(browserWindow) { | ||
const text = clipboard.readText(); | ||
browserWindow.webContents.insertText(text); | ||
} | ||
|
||
// Initialize the right click menu | ||
// See https://github.com/sindresorhus/electron-context-menu | ||
// Add the Paste and Match Style command to the context menu | ||
contextMenu({ | ||
append: (defaultActions, parameters) => [ | ||
append: (defaultActions, parameters, browserWindow) => [ | ||
new MenuItem({ | ||
// Only enable the menu item for Editable context which supports paste | ||
visible: parameters.isEditable && parameters.editFlags.canPaste, | ||
role: 'pasteAndMatchStyle', | ||
accelerator: 'CmdOrCtrl+Shift+V', | ||
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AND_MATCH_STYLE, | ||
}), | ||
new MenuItem({ | ||
label: Localize.translate(CONST.LOCALES.DEFAULT, 'desktopApplicationMenu.pasteAsPlainText'), | ||
visible: parameters.isEditable && parameters.editFlags.canPaste && clipboard.readText().length > 0, | ||
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AS_PLAIN_TEXT, | ||
click: () => pasteAsPlainText(browserWindow), | ||
}), | ||
], | ||
}); | ||
|
@@ -323,7 +340,16 @@ const mainWindow = () => { | |
{id: 'cut', role: 'cut'}, | ||
{id: 'copy', role: 'copy'}, | ||
{id: 'paste', role: 'paste'}, | ||
{id: 'pasteAndMatchStyle', role: 'pasteAndMatchStyle'}, | ||
{ | ||
id: 'pasteAndMatchStyle', | ||
role: 'pasteAndMatchStyle', | ||
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AND_MATCH_STYLE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to add the accelerator here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, as per my testing, shortcuts that are defined in the App Menu work, while the shortcuts defined in contextMenu dont. Their only purpose seems to show their value next to their name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoretically, from what i understand, contextMenu shortcuts are meant to work only when contextMenu is open. However, practically, if you press any key, contextMenu is gone and the shortcut, thus, won't work |
||
}, | ||
{ | ||
id: 'pasteAsPlainText', | ||
accelerator: DESKTOP_SHORTCUT_ACCELERATOR.PASTE_AS_PLAIN_TEXT, | ||
click: () => pasteAsPlainText(browserWindow), | ||
}, | ||
{id: 'delete', role: 'delete'}, | ||
{id: 'selectAll', role: 'selectAll'}, | ||
{type: 'separator'}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought
CONST
is already imported on L11?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not importing here,just destructuing
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad 🤦