-
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 5 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 PASTE_AS_PLAIN_TEXT_ACCELERATOR = 'CmdOrCtrl+Shift+V'; | ||
|
||
app.setName('New Expensify'); | ||
|
||
|
@@ -29,12 +30,22 @@ app.commandLine.appendSwitch('enable-network-information-downlink-max'); | |
// 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: 'Option+Shift+CmdOrCtrl+V', | ||
}), | ||
new MenuItem({ | ||
label: Localize.translate(CONST.LOCALES.DEFAULT, 'desktopApplicationMenu.pasteAsPlainText'), | ||
visible: parameters.isEditable && parameters.editFlags.canPaste, | ||
accelerator:PASTE_AS_PLAIN_TEXT_ACCELERATOR, | ||
ygshbht marked this conversation as resolved.
Show resolved
Hide resolved
|
||
click: () => { | ||
// Insert the plain text from the clipboard | ||
const text = clipboard.readText(); | ||
browserWindow.webContents.insertText(text); | ||
}, | ||
}), | ||
], | ||
}); | ||
|
@@ -323,7 +334,20 @@ const mainWindow = () => { | |
{id: 'cut', role: 'cut'}, | ||
{id: 'copy', role: 'copy'}, | ||
{id: 'paste', role: 'paste'}, | ||
{id: 'pasteAndMatchStyle', role: 'pasteAndMatchStyle'}, | ||
{ | ||
id: 'pasteAndMatchStyle', | ||
role: 'pasteAndMatchStyle', | ||
accelerator: 'Option+Shift+CmdOrCtrl+V', | ||
}, | ||
{ | ||
id: 'pasteAsPlainText', | ||
accelerator: PASTE_AS_PLAIN_TEXT_ACCELERATOR, | ||
click: () => { | ||
// Insert the plain text from the clipboard | ||
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. This code is duplicated, let's create a method for this. |
||
const text = clipboard.readText(); | ||
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. Generally if I copy an image and then try to Paste, |
||
browserWindow.webContents.insertText(text); | ||
}, | ||
}, | ||
{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.
If we have more than one accelerators, then we should move this to CONST.