Skip to content
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

[Rewrite Branch] Fixes undo redo selectall #2181

Merged
merged 7 commits into from
Aug 18, 2020
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
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
43 changes: 43 additions & 0 deletions desktop/context-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

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

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

module.exports = function (mainWindow) {
mainWindow.webContents.on('context-menu', (event, params) => {
const { editFlags } = params;
Menu.buildFromTemplate([
{
id: 'selectAll',
label: 'Select All',
click: editorCommandSender({ 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',
},
]).popup({});
});
};
8 changes: 4 additions & 4 deletions desktop/menus/edit-menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { appCommandSender } = require('./utils');
const { appCommandSender, editorCommandSender } = require('./utils');

const buildEditMenu = (settings, isAuthenticated) => {
settings = settings || {};
Expand All @@ -9,11 +9,11 @@ const buildEditMenu = (settings, isAuthenticated) => {
submenu: [
{
label: '&Undo',
role: 'undo',
click: editorCommandSender({ action: 'undo' }),
},
{
label: '&Redo',
role: 'redo',
click: editorCommandSender({ action: 'redo' }),
},
{
type: 'separator',
Expand All @@ -32,7 +32,7 @@ const buildEditMenu = (settings, isAuthenticated) => {
},
{
label: '&Select All',
role: 'selectall',
click: editorCommandSender({ action: 'selectAll' }),
},
{ type: 'separator' },
{
Expand Down
5 changes: 4 additions & 1 deletion desktop/menus/help-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const buildHelpMenu = (mainWindow, isAuthenticated) => {
{
label: '&Keyboard Shortcuts',
visible: isAuthenticated,
click: appCommandSender({ action: 'showDialog', dialog: 'KEYBINDINGS' }),
click: appCommandSender({
action: 'showDialog',
dialog: 'KEYBINDINGS',
}),
},
{ type: 'separator' },
{
Expand Down
11 changes: 10 additions & 1 deletion desktop/menus/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ const buildRadioGroup = ({ action, propName, settings }) => {
};

const appCommandSender = (arg) => {
commandSender('appCommand', arg);
};

const editorCommandSender = (arg) => {
commandSender('editorCommand', arg);
};

const commandSender = (commandName, arg) => {
return (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send('appCommand', arg);
focusedWindow.webContents.send(commandName, arg);
}
};
};

module.exports = {
buildRadioGroup,
appCommandSender,
editorCommandSender,
};
8 changes: 6 additions & 2 deletions desktop/menus/view-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const buildViewMenu = (settings, isAuthenticated) => {
label: '&Reversed',
type: 'checkbox',
checked: settings.sortReversed,
click: appCommandSender({ action: 'toggleSortOrder' }),
click: appCommandSender({
action: 'toggleSortOrder',
}),
},
]),
},
Expand Down Expand Up @@ -96,7 +98,9 @@ const buildViewMenu = (settings, isAuthenticated) => {
label: '&Sort Alphabetically',
type: 'checkbox',
checked: settings.sortTagsAlpha,
click: appCommandSender({ action: 'toggleSortTagsAlpha' }),
click: appCommandSender({
action: 'toggleSortTagsAlpha',
}),
},
],
},
Expand Down
1 change: 1 addition & 0 deletions desktop/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { contextBridge, ipcRenderer, remote } = require('electron');
const validChannels = [
'appCommand',
'clearCookies',
'editorCommand',
'importNotes',
'noteImportChannel',
'setAutoHideMenuBar',
Expand Down
63 changes: 0 additions & 63 deletions desktop/spellchecker/index.js

This file was deleted.

16 changes: 16 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,21 @@ class NoteContentEditor extends Component<Props> {
this.editor = editor;
this.monaco = monaco;

window.electron?.receive('editorCommand', (command) => {
debugger;
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