Skip to content

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

Merged
merged 13 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions desktop/main.js
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');
Expand All @@ -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';
Copy link
Collaborator

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.

DESKTOP_SHORTCUT_ACCELERATOR: {
    PASTE_AS_PLAIN_TEXT: ...,
    PASTE_AND_MATCH_STYLE:...
}



app.setName('New Expensify');

Expand All @@ -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,
click: () => {
// Insert the plain text from the clipboard
const text = clipboard.readText();
browserWindow.webContents.insertText(text);
},
}),
],
});
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally if I copy an image and then try to Paste, macOS will default to disable the menu. Here I can see we always show the menu. Is there a way we can disable the menu in the Toolbar, and hide from the Context menu if there is no text to paste?

browserWindow.webContents.insertText(text);
},
},
{id: 'delete', role: 'delete'},
{id: 'selectAll', role: 'selectAll'},
{type: 'separator'},
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ export default {
copy: 'Copy',
paste: 'Paste',
pasteAndMatchStyle: 'Paste and Match Style',
pasteAsPlainText:'Paste As Plain Text',
delete: 'Delete',
selectAll: 'Select All',
speechSubmenu: 'Speech',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ export default {
copy: 'Copiar',
paste: 'Pegar',
pasteAndMatchStyle: 'Pegar adaptando el estilo',
pasteAsPlainText:'Pegar como texto sin formato',
delete: 'Eliminar',
selectAll: 'Seleccionar todo',
speechSubmenu: 'Voz',
Expand Down