Skip to content

Commit

Permalink
Fix SelectAll, Undo, Redo
Browse files Browse the repository at this point in the history
  • Loading branch information
belcherj committed Aug 17, 2020
1 parent 4f1c795 commit 63ef0c0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 68 deletions.
4 changes: 2 additions & 2 deletions desktop/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const importNotes = require('./evernote-import');
const platform = require('./detect/platform');
const updater = require('./updater');
const { isDev } = require('./env');
const spellcheck = require('./spellchecker');
const contextMenu = require('./context-menu');

require('module').globalPaths.push(path.resolve(path.join(__dirname)));

Expand Down Expand Up @@ -76,7 +76,7 @@ module.exports = function main() {
mainWindow.loadUrl(url);
}

spellcheck(mainWindow);
contextMenu(mainWindow);

if (
'test' !== process.env.NODE_ENV &&
Expand Down
45 changes: 45 additions & 0 deletions desktop/context-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

/**
* External dependencies
*/
const { Menu } = require('electron');

const { appCommandSender } = require('../menus/utils');

module.exports = function (mainWindow) {
mainWindow.webContents.on('context-menu', (event, params) => {
const { editFlags } = params;
const template = [
{
id: 'selectAll',
label: 'Select All',
click: appCommandSender({ action: 'selectAll' }),
enabled: editFlags.canSelectAll,
},
{
id: 'cut',
label: 'Cut',
role: 'cut',
enabled: editFlags.canCut,
},
{
id: 'copy',
label: 'Copy',
role: 'copy',
enabled: editFlags.canCopy,
},
{
id: 'paste',
label: 'Paste',
role: 'paste',
enabled: editFlags.canPaste,
},
{
type: 'separator',
},
];
const menu = Menu.buildFromTemplate(template);
menu.popup({});
});
};
6 changes: 3 additions & 3 deletions desktop/menus/edit-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const buildEditMenu = (settings, isAuthenticated) => {
submenu: [
{
label: '&Undo',
role: 'undo',
click: appCommandSender({ action: 'undo' }),
},
{
label: '&Redo',
role: 'redo',
click: appCommandSender({ action: 'redo' }),
},
{
type: 'separator',
Expand All @@ -32,7 +32,7 @@ const buildEditMenu = (settings, isAuthenticated) => {
},
{
label: '&Select All',
role: 'selectall',
click: appCommandSender({ action: 'selectAll' }),
},
{ type: 'separator' },
{
Expand Down
63 changes: 0 additions & 63 deletions desktop/spellchecker/index.js

This file was deleted.

15 changes: 15 additions & 0 deletions lib/note-content-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class NoteContentEditor extends Component<Props> {
if (this.bootTimer) {
clearTimeout(this.bootTimer);
}
window?.electron.removeListener('editorCommand');
window.removeEventListener('keydown', this.handleKeys, true);
}

Expand Down Expand Up @@ -189,6 +190,20 @@ class NoteContentEditor extends Component<Props> {
this.editor = editor;
this.monaco = monaco;

window?.electron.receive('editorCommand', (command) => {
switch (command.action) {
case 'redo':
editor.trigger('', 'redo');
return;
case 'selectAll':
editor.setSelection(editor.getModel().getFullModelRange());
return;
case 'undo':
editor.trigger('', 'undo');
return;
}
});

const titleDecoration = (line: number) => ({
range: new monaco.Range(line, 1, line, 1),
options: {
Expand Down

0 comments on commit 63ef0c0

Please sign in to comment.