1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Desktop: Resolves #11687: Plugins: Allow editor plugins to support multiple windows (#12041)

This commit is contained in:
Henry Heino
2025-06-06 02:00:47 -07:00
committed by GitHub
parent 291ba88224
commit 608dbab453
46 changed files with 1022 additions and 195 deletions

View File

@@ -1,8 +1,8 @@
import { CommandContext, CommandDeclaration, CommandRuntime } from '../services/CommandService';
import CommandService, { CommandContext, CommandDeclaration, CommandRuntime } from '../services/CommandService';
import { _ } from '../locale';
import Setting from '../models/Setting';
import getActivePluginEditorView from '../services/plugins/utils/getActivePluginEditorView';
import Logger from '@joplin/utils/Logger';
import getActivePluginEditorViews from '../services/plugins/utils/getActivePluginEditorViews';
import getShownPluginEditorView from '../services/plugins/utils/getShownPluginEditorView';
const logger = Logger.create('toggleEditorPlugin');
@@ -15,29 +15,34 @@ export const declaration: CommandDeclaration = {
export const runtime = (): CommandRuntime => {
return {
execute: async (context: CommandContext) => {
const shownEditorViewIds = Setting.value('plugins.shownEditorViewIds');
const { editorPlugin, editorView } = getActivePluginEditorView(context.state.pluginService.plugins);
const activeWindowId = context.state.windowId;
const activePluginStates = getActivePluginEditorViews(context.state.pluginService.plugins, activeWindowId);
if (!editorPlugin) {
if (activePluginStates.length === 0) {
logger.warn('No editor plugin to toggle to');
return;
}
const idx = shownEditorViewIds.indexOf(editorView.id);
let hasBeenHidden = false;
let showedView = false;
const setEditorPluginVisible = async (viewId: string, visible: boolean) => {
await CommandService.instance().execute('showEditorPlugin', viewId, visible);
showedView ||= visible;
};
if (idx < 0) {
shownEditorViewIds.push(editorView.id);
} else {
shownEditorViewIds.splice(idx, 1);
hasBeenHidden = true;
const { editorView: visibleView } = getShownPluginEditorView(context.state.pluginService.plugins, activeWindowId);
// Hide the visible view
if (visibleView) {
await setEditorPluginVisible(visibleView.id, false);
}
logger.info('New shown editor views: ', shownEditorViewIds);
// Show the next view
const visibleViewIndex = activePluginStates.findIndex(state => state.editorView.id === visibleView?.id);
const nextIndex = visibleViewIndex + 1;
if (nextIndex < activePluginStates.length) {
await setEditorPluginVisible(activePluginStates[nextIndex].editorView.id, true);
}
Setting.setValue('plugins.shownEditorViewIds', shownEditorViewIds);
if (hasBeenHidden) {
if (!showedView) {
// When the plugin editor goes from visible to hidden, we need to reload the note
// because it may have been changed via the data API.
context.dispatch({