diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx index bd1cdc98f1..f7db5c8e3e 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx @@ -1344,7 +1344,9 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { editor.on(TinyMceEditorEvents.KeyUp, onKeyUp); editor.on(TinyMceEditorEvents.KeyDown, onKeyDown); editor.on(TinyMceEditorEvents.KeyPress, onKeypress); - editor.on(TinyMceEditorEvents.Paste, onPaste); + // Passing `true` adds the listener to the front of the listener list. + // This allows overriding TinyMCE's built-in paste handler with .preventDefault. + editor.on(TinyMceEditorEvents.Paste, onPaste, true); editor.on(TinyMceEditorEvents.PasteAsText, onPasteAsText); editor.on(TinyMceEditorEvents.Copy, onCopy); // `compositionend` means that a user has finished entering a Chinese diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/utils/useContextMenu.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/utils/useContextMenu.ts index e62bfd27bc..1cb626cf2a 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/utils/useContextMenu.ts +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/utils/useContextMenu.ts @@ -8,7 +8,7 @@ import { menuItems } from '../../../utils/contextMenu'; import MenuUtils from '@joplin/lib/services/commands/MenuUtils'; import CommandService from '@joplin/lib/services/CommandService'; import Setting from '@joplin/lib/models/Setting'; -import type { Event as ElectronEvent } from 'electron'; +import type { Event as ElectronEvent, MenuItemConstructorOptions } from 'electron'; import Resource from '@joplin/lib/models/Resource'; import { TinyMceEditorEvents } from './types'; @@ -17,6 +17,7 @@ import { Editor } from 'tinymce'; import { EditDialogControl } from './useEditDialog'; import { Dispatch } from 'redux'; import { _ } from '@joplin/lib/locale'; +import type { MenuItem as MenuItemType } from 'electron'; const Menu = bridge().Menu; const MenuItem = bridge().MenuItem; @@ -137,13 +138,20 @@ export default function(editor: Editor, plugins: PluginStates, dispatch: Dispatc event.preventDefault(); const menu = new Menu(); - const menuItems = []; + const menuItems: MenuItemType[] = []; + const toMenuItems = (specs: MenuItemConstructorOptions[]) => { + return specs.map(spec => new MenuItem(spec)); + }; menuItems.push(...makeEditableMenuItems(element)); menuItems.push(...makeMainMenuItems(element)); const spellCheckerMenuItems = SpellCheckerService.instance().contextMenuItems(params.misspelledWord, params.dictionarySuggestions); - menuItems.push(...spellCheckerMenuItems); - menuItems.push(...menuUtils.pluginContextMenuItems(plugins, MenuItemLocation.EditorContextMenu)); + menuItems.push( + ...toMenuItems(spellCheckerMenuItems), + ); + menuItems.push( + ...toMenuItems(menuUtils.pluginContextMenuItems(plugins, MenuItemLocation.EditorContextMenu)), + ); for (const item of menuItems) { menu.append(item);