You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-08-10 22:11:50 +02:00
Desktop: Rich text editor: Add a right-click "Open" menu item for external links (#12391)
This commit is contained in:
@@ -39,7 +39,7 @@ export default function(editor: Editor, plugins: PluginStates, dispatch: Dispatc
|
||||
const makeMainMenuItems = (element: Element) => {
|
||||
let itemType: ContextMenuItemType = ContextMenuItemType.None;
|
||||
let resourceId = '';
|
||||
let linkToCopy = null;
|
||||
let linkUrl = null;
|
||||
|
||||
const pathToId = (path: string) => {
|
||||
const id = Resource.pathToId(path);
|
||||
@@ -52,7 +52,7 @@ export default function(editor: Editor, plugins: PluginStates, dispatch: Dispatc
|
||||
} else if (element.nodeName === 'A') {
|
||||
resourceId = pathToId((element as HTMLAnchorElement).href);
|
||||
itemType = resourceId ? ContextMenuItemType.Resource : ContextMenuItemType.Link;
|
||||
linkToCopy = element.getAttribute('href') || '';
|
||||
linkUrl = element.getAttribute('href') || '';
|
||||
} else {
|
||||
itemType = ContextMenuItemType.Text;
|
||||
}
|
||||
@@ -62,7 +62,8 @@ export default function(editor: Editor, plugins: PluginStates, dispatch: Dispatc
|
||||
resourceId,
|
||||
filename: null,
|
||||
mime: null,
|
||||
linkToCopy,
|
||||
linkToCopy: linkUrl,
|
||||
linkToOpen: linkUrl,
|
||||
textToCopy: null,
|
||||
htmlToCopy: editor.selection ? editor.selection.getContent() : '',
|
||||
insertContent: (content: string) => {
|
||||
|
@@ -15,6 +15,7 @@ import Setting from '@joplin/lib/models/Setting';
|
||||
import ItemChange from '@joplin/lib/models/ItemChange';
|
||||
import shim from '@joplin/lib/shim';
|
||||
import { openFileWithExternalEditor } from '@joplin/lib/services/ExternalEditWatcher/utils';
|
||||
import CommandService from '@joplin/lib/services/CommandService';
|
||||
const fs = require('fs-extra');
|
||||
const { writeFile } = require('fs-extra');
|
||||
const { clipboard } = require('electron');
|
||||
@@ -84,9 +85,18 @@ export function menuItems(dispatch: Function): ContextMenuItems {
|
||||
open: {
|
||||
label: _('Open...'),
|
||||
onAction: async (options: ContextMenuOptions) => {
|
||||
await openItemById(options.resourceId, dispatch);
|
||||
if (options.resourceId) {
|
||||
await openItemById(options.resourceId, dispatch);
|
||||
} else if (options.linkToOpen) {
|
||||
await CommandService.instance().execute('openItem', options.linkToOpen);
|
||||
} else {
|
||||
await shim.showErrorDialog('No link found');
|
||||
}
|
||||
},
|
||||
isActive: (itemType: ContextMenuItemType, options: ContextMenuOptions) => !options.textToCopy && (itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource),
|
||||
isActive: (itemType: ContextMenuItemType, options: ContextMenuOptions) => (
|
||||
(!options.textToCopy && (itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource))
|
||||
|| (!!options.linkToOpen && itemType === ContextMenuItemType.Link)
|
||||
),
|
||||
},
|
||||
saveAs: {
|
||||
label: _('Save as...'),
|
||||
|
@@ -17,6 +17,7 @@ export interface ContextMenuOptions {
|
||||
resourceId: string;
|
||||
mime: string;
|
||||
filename: string;
|
||||
linkToOpen: string;
|
||||
linkToCopy: string;
|
||||
textToCopy: string;
|
||||
htmlToCopy: string;
|
||||
|
@@ -52,6 +52,7 @@ export default function useMessageHandler(
|
||||
resourceId: arg0.resourceId,
|
||||
filename: arg0.filename,
|
||||
mime: arg0.mime,
|
||||
linkToOpen: null,
|
||||
textToCopy: arg0.textToCopy,
|
||||
linkToCopy: arg0.linkToCopy || null,
|
||||
htmlToCopy: '',
|
||||
|
@@ -62,6 +62,7 @@ export default function PdfViewer(props: Props) {
|
||||
mime: 'text/plain',
|
||||
textToCopy: text,
|
||||
linkToCopy: null,
|
||||
linkToOpen: null,
|
||||
htmlToCopy: '',
|
||||
insertContent: () => { console.warn('insertContent() not implemented'); },
|
||||
fireEditorEvent: () => { console.warn('fireEditorEvent() not implemented'); },
|
||||
|
Reference in New Issue
Block a user