1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Mobile: Add support for plugin editor views (#11831)

Co-authored-by: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com>
This commit is contained in:
Laurent Cozic
2025-02-17 13:47:56 +00:00
committed by GitHub
parent d2aad1d6c7
commit c6154cfb4e
20 changed files with 337 additions and 164 deletions

View File

@@ -5,7 +5,9 @@ import * as historyForward from './historyForward';
import * as openMasterPasswordDialog from './openMasterPasswordDialog';
import * as permanentlyDeleteNote from './permanentlyDeleteNote';
import * as renderMarkup from './renderMarkup';
import * as showEditorPlugin from './showEditorPlugin';
import * as synchronize from './synchronize';
import * as toggleEditorPlugin from './toggleEditorPlugin';
const index: any[] = [
deleteNote,
@@ -14,7 +16,9 @@ const index: any[] = [
openMasterPasswordDialog,
permanentlyDeleteNote,
renderMarkup,
showEditorPlugin,
synchronize,
toggleEditorPlugin,
];
export default index;

View File

@@ -0,0 +1,55 @@
import { CommandContext, CommandDeclaration, CommandRuntime } from '../services/CommandService';
import Setting from '../models/Setting';
import getActivePluginEditorView from '../services/plugins/utils/getActivePluginEditorView';
import Logger from '@joplin/utils/Logger';
const logger = Logger.create('showEditorPlugin');
export const declaration: CommandDeclaration = {
name: 'showEditorPlugin',
label: () => 'Show editor plugin',
iconName: 'fas fa-eye',
};
export const runtime = (): CommandRuntime => {
return {
execute: async (context: CommandContext, editorViewId = '', show = true) => {
logger.info('View:', editorViewId, 'Show:', show);
const shownEditorViewIds = Setting.value('plugins.shownEditorViewIds');
if (!editorViewId) {
const { editorPlugin, editorView } = getActivePluginEditorView(context.state.pluginService.plugins);
if (!editorPlugin) {
logger.warn('No editor plugin to toggle to');
return;
}
editorViewId = editorView.id;
}
const idx = shownEditorViewIds.indexOf(editorViewId);
if (show) {
if (idx >= 0) {
logger.info(`Editor is already visible: ${editorViewId}`);
return;
}
shownEditorViewIds.push(editorViewId);
} else {
if (idx < 0) {
logger.info(`Editor is already hidden: ${editorViewId}`);
return;
}
shownEditorViewIds.splice(idx, 1);
}
logger.info('Shown editor IDs:', shownEditorViewIds);
Setting.setValue('plugins.shownEditorViewIds', shownEditorViewIds);
},
};
};

View File

@@ -0,0 +1,49 @@
import { 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';
const logger = Logger.create('toggleEditorPlugin');
export const declaration: CommandDeclaration = {
name: 'toggleEditorPlugin',
label: () => _('Toggle editor plugin'),
iconName: 'fas fa-eye',
};
export const runtime = (): CommandRuntime => {
return {
execute: async (context: CommandContext) => {
const shownEditorViewIds = Setting.value('plugins.shownEditorViewIds');
const { editorPlugin, editorView } = getActivePluginEditorView(context.state.pluginService.plugins);
if (!editorPlugin) {
logger.warn('No editor plugin to toggle to');
return;
}
const idx = shownEditorViewIds.indexOf(editorView.id);
let hasBeenHidden = false;
if (idx < 0) {
shownEditorViewIds.push(editorView.id);
} else {
shownEditorViewIds.splice(idx, 1);
hasBeenHidden = true;
}
logger.info('New shown editor views: ', shownEditorViewIds);
Setting.setValue('plugins.shownEditorViewIds', shownEditorViewIds);
if (hasBeenHidden) {
// 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({
type: 'EDITOR_NOTE_NEEDS_RELOAD',
});
}
},
};
};