Merge branch 'dev' into fix_active_window

This commit is contained in:
Laurent Cozic
2026-02-04 09:54:23 +00:00
committed by GitHub
2 changed files with 10 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import { ContextMenuParams, Event } from 'electron';
import { useEffect, RefObject } from 'react';
import { useEffect, RefObject, useContext } from 'react';
import { _ } from '@joplin/lib/locale';
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
import { EditContextMenuFilterObject, MenuItemLocation } from '@joplin/lib/services/plugins/api/types';
@@ -11,6 +11,7 @@ import type CodeMirrorControl from '@joplin/editor/CodeMirror/CodeMirrorControl'
import eventManager from '@joplin/lib/eventManager';
import bridge from '../../../../../services/bridge';
import Setting from '@joplin/lib/models/Setting';
import { WindowIdContext } from '../../../../NewWindowOrIFrame';
const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem;
@@ -29,6 +30,7 @@ interface ContextMenuProps {
const useContextMenu = (props: ContextMenuProps) => {
const editorRef = props.editorRef;
const windowId = useContext(WindowIdContext);
// The below code adds support for spellchecking when it is enabled
// It might be buggy, refer to the below issue
@@ -156,10 +158,7 @@ const useContextMenu = (props: ContextMenuProps) => {
// Prepend the event listener so that it gets called before
// the listener that shows the default menu.
// Use mainWindow() instead of activeWindow() because activeWindow() can return
// the DevTools window when it's focused, causing the listener to be registered
// on the wrong webContents.
const targetWindow = bridge().mainWindow();
const targetWindow = bridge().windowById(windowId);
targetWindow.webContents.prependListener('context-menu', onContextMenu);
return () => {
@@ -170,6 +169,7 @@ const useContextMenu = (props: ContextMenuProps) => {
}, [
props.plugins, props.editorClassName, editorRef, props.containerRef,
props.editorCutText, props.editorCopyText, props.editorPaste,
windowId,
]);
};

View File

@@ -1,7 +1,7 @@
import { MenuItemLocation } from '@joplin/lib/services/plugins/api/types';
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService';
import { useEffect } from 'react';
import { useContext, useEffect } from 'react';
import bridge from '../../../../../services/bridge';
import { ContextMenuOptions, ContextMenuItemType } from '../../../utils/contextMenuUtils';
import { menuItems } from '../../../utils/contextMenu';
@@ -18,6 +18,7 @@ import { Dispatch } from 'redux';
import { _ } from '@joplin/lib/locale';
import type { MenuItem as MenuItemType } from 'electron';
import isItemId from '@joplin/lib/models/utils/isItemId';
import { WindowIdContext } from '../../../../NewWindowOrIFrame';
const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem;
@@ -30,14 +31,12 @@ interface ContextMenuActionOptions {
const contextMenuActionOptions: ContextMenuActionOptions = { current: null };
export default function(editor: Editor, plugins: PluginStates, dispatch: Dispatch, htmlToMd: HtmlToMarkdownHandler, mdToHtml: MarkupToHtmlHandler, editDialog: EditDialogControl) {
const windowId = useContext(WindowIdContext);
useEffect(() => {
if (!editor) return () => {};
const contextMenuItems = menuItems(dispatch);
// Use mainWindow() instead of activeWindow() because activeWindow() can return
// the DevTools window when it's focused, causing the listener to be registered
// on the wrong webContents.
const targetWindow = bridge().mainWindow();
const targetWindow = bridge().windowById(windowId);
const makeMainMenuItems = (element: Element) => {
let itemType: ContextMenuItemType = ContextMenuItemType.None;
@@ -178,5 +177,5 @@ export default function(editor: Editor, plugins: PluginStates, dispatch: Dispatc
targetWindow.webContents.off('context-menu', onElectronContextMenu);
}
};
}, [editor, plugins, dispatch, htmlToMd, mdToHtml, editDialog]);
}, [editor, plugins, dispatch, htmlToMd, mdToHtml, editDialog, windowId]);
}