mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Desktop: Fixes #3697: Fixed copying link in Rich Text editor
This commit is contained in:
parent
8b5a99d494
commit
83619b279d
File diff suppressed because one or more lines are too long
@ -1,51 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
|
||||||
const React = require('react');
|
|
||||||
const react_1 = require('react');
|
|
||||||
const KeymapService_1 = require('../../lib/services/KeymapService');
|
|
||||||
const styles_1 = require('./styles');
|
|
||||||
const { _ } = require('lib/locale');
|
|
||||||
const keymapService = KeymapService_1.default.instance();
|
|
||||||
exports.ShortcutRecorder = ({ onSave, onReset, onCancel, onError, initialAccelerator, commandName, themeId }) => {
|
|
||||||
const styles = styles_1.default(themeId);
|
|
||||||
const [accelerator, setAccelerator] = react_1.useState(initialAccelerator);
|
|
||||||
const [saveAllowed, setSaveAllowed] = react_1.useState(true);
|
|
||||||
react_1.useEffect(() => {
|
|
||||||
try {
|
|
||||||
// Only perform validations if there's an accelerator provided
|
|
||||||
// Otherwise performing a save means that it's going to be disabled
|
|
||||||
if (accelerator) {
|
|
||||||
keymapService.validateAccelerator(accelerator);
|
|
||||||
keymapService.validateKeymap({ accelerator, command: commandName });
|
|
||||||
}
|
|
||||||
// Discard previous errors
|
|
||||||
onError({ recorderError: null });
|
|
||||||
setSaveAllowed(true);
|
|
||||||
} catch (recorderError) {
|
|
||||||
onError({ recorderError });
|
|
||||||
setSaveAllowed(false);
|
|
||||||
}
|
|
||||||
}, [accelerator]);
|
|
||||||
const handleKeydown = (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
const newAccelerator = keymapService.domToElectronAccelerator(event);
|
|
||||||
switch (newAccelerator) {
|
|
||||||
case 'Enter':
|
|
||||||
if (saveAllowed) { return onSave({ commandName, accelerator }); }
|
|
||||||
break;
|
|
||||||
case 'Escape':
|
|
||||||
return onCancel({ commandName });
|
|
||||||
case 'Backspace':
|
|
||||||
case 'Delete':
|
|
||||||
return setAccelerator('');
|
|
||||||
default:
|
|
||||||
setAccelerator(newAccelerator);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return (React.createElement('div', { style: styles.recorderContainer },
|
|
||||||
React.createElement('input', { value: accelerator, placeholder: _('Press the shortcut'), onKeyDown: handleKeydown, style: styles.recorderInput, readOnly: true, autoFocus: true }),
|
|
||||||
React.createElement('button', { style: styles.inlineButton, disabled: !saveAllowed, onClick: () => onSave({ commandName, accelerator }) }, _('Save')),
|
|
||||||
React.createElement('button', { style: styles.inlineButton, onClick: () => onReset({ commandName }) }, _('Restore')),
|
|
||||||
React.createElement('button', { style: styles.inlineButton, onClick: () => onCancel({ commandName }) }, _('Cancel'))));
|
|
||||||
};
|
|
||||||
// # sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2hvcnRjdXRSZWNvcmRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIlNob3J0Y3V0UmVjb3JkZXIudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0JBQStCO0FBQy9CLGlDQUEyRDtBQUUzRCxvRUFBNkQ7QUFDN0QscUNBQStCO0FBRS9CLE1BQU0sRUFBRSxDQUFDLEVBQUUsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUM7QUFDcEMsTUFBTSxhQUFhLEdBQUcsdUJBQWEsQ0FBQyxRQUFRLEVBQUUsQ0FBQztBQVlsQyxRQUFBLGdCQUFnQixHQUFHLENBQUMsRUFBRSxNQUFNLEVBQUUsT0FBTyxFQUFFLFFBQVEsRUFBRSxPQUFPLEVBQUUsa0JBQWtCLEVBQUUsV0FBVyxFQUFFLE9BQU8sRUFBeUIsRUFBRSxFQUFFO0lBQzNJLE1BQU0sTUFBTSxHQUFHLGdCQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7SUFFaEMsTUFBTSxDQUFDLFdBQVcsRUFBRSxjQUFjLENBQUMsR0FB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LENBQUMsSUFDMUUsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUNKLENBQ0osQ0FDTixDQUFDO0FBQ0gsQ0FBQyxDQUFDIn0=
|
|
@ -1,53 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
|
||||||
const { buildStyle } = require('lib/theme');
|
|
||||||
function styles(themeId) {
|
|
||||||
return buildStyle('KeymapConfigScreen', themeId, (theme) => {
|
|
||||||
return {
|
|
||||||
container: Object.assign(Object.assign({}, theme.containerStyle), { padding: 16 }),
|
|
||||||
actionsContainer: {
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'row',
|
|
||||||
},
|
|
||||||
recorderContainer: {
|
|
||||||
padding: 2,
|
|
||||||
flexGrow: 1,
|
|
||||||
},
|
|
||||||
filterInput: Object.assign(Object.assign({}, theme.inputStyle), { flexGrow: 1, minHeight: 29, alignSelf: 'center' }),
|
|
||||||
recorderInput: Object.assign(Object.assign({}, theme.inputStyle), { minHeight: 29 }),
|
|
||||||
label: Object.assign(Object.assign({}, theme.textStyle), { alignSelf: 'center', marginRight: 10 }),
|
|
||||||
table: Object.assign(Object.assign({}, theme.containerStyle), { marginTop: 16, overflow: 'auto', width: '100%' }),
|
|
||||||
tableShortcutColumn: Object.assign(Object.assign({}, theme.textStyle), { width: '60%' }),
|
|
||||||
tableCommandColumn: Object.assign(Object.assign({}, theme.textStyle), { width: 'auto' }),
|
|
||||||
tableCell: {
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'row',
|
|
||||||
},
|
|
||||||
tableCellContent: {
|
|
||||||
flexGrow: 1,
|
|
||||||
alignSelf: 'center',
|
|
||||||
},
|
|
||||||
tableCellStatus: {
|
|
||||||
height: '100%',
|
|
||||||
alignSelf: 'center',
|
|
||||||
},
|
|
||||||
kbd: {
|
|
||||||
fontFamily: 'sans-serif',
|
|
||||||
border: '1px solid',
|
|
||||||
borderRadius: 4,
|
|
||||||
backgroundColor: theme.raisedBackgroundColor,
|
|
||||||
padding: 2,
|
|
||||||
paddingLeft: 6,
|
|
||||||
paddingRight: 6,
|
|
||||||
},
|
|
||||||
disabled: {
|
|
||||||
color: theme.colorFaded,
|
|
||||||
fontStyle: 'italic',
|
|
||||||
},
|
|
||||||
inlineButton: Object.assign(Object.assign({}, theme.buttonStyle), { marginLeft: 12 }),
|
|
||||||
warning: Object.assign(Object.assign({}, theme.textStyle), { backgroundColor: theme.warningBackgroundColor, paddingLeft: 16, paddingRight: 16, paddingTop: 2, paddingBottom: 2 }),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.default = styles;
|
|
||||||
// # sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLE1BQU0sRUFBRSxVQUFVLEVBQUUsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFFNUMsU0FBd0IsTUFBTSxDQUFDLE9BQWU7SUFDN0MsT0FBTyxVQUFVLENBQUMsb0JBQW9CLEVBQUUsT0FBTyxFQUFFLENBQUMsS0FBVSxFQUFFLEVBQUU7UUFDL0QsT0FBTztZQUNOLFNBQVMsa0NBQ0wsS0FBSyxDQUFDLGNBQWMsS0FDdkIsT0FBTyxFQUFFLEVBQUUsR0FDWDtZQUNELGdCQUFnQixFQUFFO2dCQUNqQixPQUFPLEVBQUUsTUFBTTtnQkFDZixhQUFhLEVBQUUsS0FBSzthQUNwQjtZQUNELGlCQUFpQixFQUFFO2dCQUNsQixPQUFPLEVBQUUsQ0FBQztnQkFDVixRQUFRLEVBQUUsQ0FBQzthQUNYO1lBQ0QsV0FBVyxrQ0FDUCxLQUFLLENBQUMsVUFBVSxLQUNuQixRQUFRLEVBQUUsQ0FBQyxFQUNYLFNBQVMsRUFBRSxFQUFFLEVBQ2Is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UU7Z0JBQ1QsS0FBSyxFQUFFLEtBQUssQ0FBQyxVQUFVO2dCQUN2QixTQUFTLEVBQUUsUUFBUTthQUNuQjtZQUNELFlBQVksa0NBQ1IsS0FBSyxDQUFDLFdBQVcsS0FDcEIsVUFBVSxFQUFFLEVBQUUsR0FDZDtZQUNELE9BQU8sa0NBQ0gsS0FBSyxDQUFDLFNBQVMsS0FDbEIsZUFBZSxFQUFFLEtBQUssQ0FBQyxzQkFBc0IsRUFDN0MsV0FBVyxFQUFFLEVBQUUsRUFDZixZQUFZLEVBQUUsRUFBRSxFQUNoQixVQUFVLEVBQUUsQ0FBQyxFQUNiLGFBQWEsRUFBRSxDQUFDLEdBQ2hCO1NBQ0QsQ0FBQztJQUNILENBQUMsQ0FBQyxDQUFDO0FBQ0osQ0FBQztBQW5GRCx5QkFtRkMifQ==
|
|
@ -1,25 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
|
||||||
const react_1 = require('react');
|
|
||||||
const KeymapService_1 = require('../../../lib/services/KeymapService');
|
|
||||||
const keymapService = KeymapService_1.default.instance();
|
|
||||||
const useCommandStatus = () => {
|
|
||||||
const [status, setStatus] = react_1.useState(() => keymapService.getCommandNames().reduce((accumulator, command) => {
|
|
||||||
accumulator[command] = false;
|
|
||||||
return accumulator;
|
|
||||||
}, {}));
|
|
||||||
const disableStatus = (commandName) => setStatus(prevStatus => (Object.assign(Object.assign({}, prevStatus), { [commandName]: false })));
|
|
||||||
const enableStatus = (commandName) => setStatus(prevStatus => {
|
|
||||||
// Falsify all the commands; Only one command should be truthy at any given time
|
|
||||||
const newStatus = Object.keys(prevStatus).reduce((accumulator, command) => {
|
|
||||||
accumulator[command] = false;
|
|
||||||
return accumulator;
|
|
||||||
}, {});
|
|
||||||
// Make the appropriate command truthful
|
|
||||||
newStatus[commandName] = true;
|
|
||||||
return newStatus;
|
|
||||||
});
|
|
||||||
return [status, enableStatus, disableStatus];
|
|
||||||
};
|
|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DQUFDLENBQUMsV0FBMEIsRUFBRSxPQUFlLEVBQUUsRUFBRTtZQUNoRyxXQUFXLENBQUMsT0FBTyxDQUFDLEdBQUcsS0FBSyxDQUFDO1lBQzdCLE9BQU8sV0FBVyxDQUFDO1FBQ3BCLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FBQztRQUVQLHdDQUF3QztRQUN4QyxTQUFTLENBQUMsV0FBVyxDQUFDLEdBQUcsSUFBSSxDQUFDO1FBQzlCLE9BQU8sU0FBUyxDQUFDO0lBQ2xCLENBQUMsQ0FBQyxDQUFDO0lBRUgsT0FBTyxDQUFDLE1BQU0sRUFBRSxZQUFZLEVBQUUsYUFBYSxDQUFDLENBQUM7QUFDOUMsQ0FBQyxDQUFDO0FBRUYsa0JBQWUsZ0JBQWdCLENBQUMifQ==
|
|
@ -1,68 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
const __awaiter = (this && this.__awaiter) || function(thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function(resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function(resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator['throw'](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
|
||||||
const react_1 = require('react');
|
|
||||||
const KeymapService_1 = require('../../../lib/services/KeymapService');
|
|
||||||
const keymapService = KeymapService_1.default.instance();
|
|
||||||
// This custom hook provides a synchronized snapshot of the keymap residing at KeymapService
|
|
||||||
// All the logic regarding altering and interacting with the keymap is isolated from the components
|
|
||||||
const useKeymap = () => {
|
|
||||||
const [keymapItems, setKeymapItems] = react_1.useState(() => keymapService.getKeymapItems());
|
|
||||||
const [keymapError, setKeymapError] = react_1.useState(null);
|
|
||||||
const setAccelerator = (commandName, accelerator) => {
|
|
||||||
setKeymapItems(prevKeymap => {
|
|
||||||
const newKeymap = [...prevKeymap];
|
|
||||||
newKeymap.find(item => item.command === commandName).accelerator = accelerator || null /* Disabled */;
|
|
||||||
return newKeymap;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const resetAccelerator = (commandName) => {
|
|
||||||
const defaultAccelerator = keymapService.getDefaultAccelerator(commandName);
|
|
||||||
setKeymapItems(prevKeymap => {
|
|
||||||
const newKeymap = [...prevKeymap];
|
|
||||||
newKeymap.find(item => item.command === commandName).accelerator = defaultAccelerator;
|
|
||||||
return newKeymap;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const overrideKeymapItems = (customKeymapItems) => {
|
|
||||||
const oldKeymapItems = [...customKeymapItems];
|
|
||||||
keymapService.initialize(); // Start with a fresh keymap
|
|
||||||
try {
|
|
||||||
// First, try to update the in-memory keymap of KeymapService
|
|
||||||
// This function will throw if there are any issues with the new custom keymap
|
|
||||||
keymapService.overrideKeymap(customKeymapItems);
|
|
||||||
// Then, update the state with the data from KeymapService
|
|
||||||
// Side-effect: Changes will also be saved to the disk
|
|
||||||
setKeymapItems(keymapService.getKeymapItems());
|
|
||||||
} catch (err) {
|
|
||||||
// oldKeymapItems includes even the unchanged keymap items
|
|
||||||
// However, it is not an issue because the logic accounts for such scenarios
|
|
||||||
keymapService.overrideKeymap(oldKeymapItems);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const exportCustomKeymap = (customKeymapPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
||||||
// KeymapService is already synchronized automatically with the in-state keymap
|
|
||||||
yield keymapService.saveCustomKeymap(customKeymapPath);
|
|
||||||
});
|
|
||||||
react_1.useEffect(() => {
|
|
||||||
try {
|
|
||||||
keymapService.overrideKeymap(keymapItems);
|
|
||||||
keymapService.saveCustomKeymap();
|
|
||||||
setKeymapError(null);
|
|
||||||
} catch (err) {
|
|
||||||
setKeymapError(err);
|
|
||||||
}
|
|
||||||
}, [keymapItems]);
|
|
||||||
return [keymapItems, keymapError, overrideKeymapItems, exportCustomKeymap, setAccelerator, resetAccelerator];
|
|
||||||
};
|
|
||||||
exports.default = useKeymap;
|
|
||||||
// # sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXNlS2V5bWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidXNlS2V5bWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7O0FBQUEsaUNBQTRDO0FBQzVDLHVFQUFnRjtBQUVoRixNQUFNLGFBQWEsR0FBRyx1QkFBYSxDQUFDLFFBQVEsRUFBRSxDQUFDO0FBRS9DLDRGQUE0RjtBQUM1RixtR0FBbUc7QUFFbkcsTUFBTSxTQUFTLEdBQUcsR0FPaEIsRUFBRTtJQUNILE1BQU0sQ0FBQyxXQUFXLEVBQUUsY0FBYyxDQUFDLEdBQUcsZ0JBQVEsQ0FBZSxHQUFHLEVBQUUsQ0FBQyxhQUFhLENBQUMsY0FBYyxFQUFFLENBQUMsQ0FBQztJQUNuRyxNQUFNLENBQUMsV0FBVyxFQUFFLGNBQWMsQ0FBQyxHQUFHLGdCQUFRLENBQVEsSUFBSSxDQUFDLENBQUM7SUFFNUQsTUFBTSxjQUFjLEdBQUcsQ0FBQyxXQUFtQixFQUFFLFdBQW1CLEVBQUUsRUFBRTtRQUNuRSxjQUFjLENBQUMsVUFBVSxDQUFDLEVBQUU7WUFDM0IsTUFBTSxTQUFTLEdBQUcsQ0FBQyxHQUFHLFVBQVUsQ0FBQyxDQUFDO1lBRWxDLFNBQVMsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxJQUFJLENBQUMsT0FBTyxLQUFLLFdBQVcsQ0FBQyxDQUFDLFdBQVcsR0FBRyxXQUFXLElBQUks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0FBYyxDQUFDLENBQUM7WUFDN0MsTUFBTSxHQUFHLENBQUM7U0FDVjtJQUNGLENBQUMsQ0FBQztJQUVGLE1BQU0sa0JBQWtCLEdBQUcsQ0FBTyxnQkFBd0IsRUFBRSxFQUFFO1FBQzdELCtFQUErRTtRQUMvRSxNQUFNLGFBQWEsQ0FBQyxnQkFBZ0IsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO0lBQ3hELENBQUMsQ0FBQSxDQUFDO0lBRUYsaUJBQVMsQ0FBQyxHQUFHLEVBQUU7UUFDZCxJQUFJO1lBQ0gsYUFBYSxDQUFDLGNBQWMsQ0FBQyxXQUFXLENBQUMsQ0FBQztZQUMxQyxhQUFhLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQztZQUNqQyxjQUFjLENBQUMsSUFBSSxDQUFDLENBQUM7U0FDckI7UUFBQyxPQUFPLEdBQUcsRUFBRTtZQUNiLGNBQWMsQ0FBQyxHQUFHLENBQUMsQ0FBQztTQUNwQjtJQUNGLENBQUMsRUFBRSxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7SUFFbEIsT0FBTyxDQUFDLFdBQVcsRUFBRSxXQUFXLEVBQUUsbUJBQW1CLEVBQUUsa0JBQWtCLEVBQUUsY0FBYyxFQUFFLGdCQUFnQixDQUFDLENBQUM7QUFDOUcsQ0FBQyxDQUFDO0FBRUYsa0JBQWUsU0FBUyxDQUFDIn0=
|
|
@ -626,6 +626,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
update: function(element:any) {
|
update: function(element:any) {
|
||||||
let itemType:ContextMenuItemType = ContextMenuItemType.None;
|
let itemType:ContextMenuItemType = ContextMenuItemType.None;
|
||||||
let resourceId = '';
|
let resourceId = '';
|
||||||
|
let linkToCopy = null;
|
||||||
|
|
||||||
if (element.nodeName === 'IMG') {
|
if (element.nodeName === 'IMG') {
|
||||||
itemType = ContextMenuItemType.Image;
|
itemType = ContextMenuItemType.Image;
|
||||||
@ -633,6 +634,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
} else if (element.nodeName === 'A') {
|
} else if (element.nodeName === 'A') {
|
||||||
resourceId = Resource.pathToId(element.href);
|
resourceId = Resource.pathToId(element.href);
|
||||||
itemType = resourceId ? ContextMenuItemType.Resource : ContextMenuItemType.Link;
|
itemType = resourceId ? ContextMenuItemType.Resource : ContextMenuItemType.Link;
|
||||||
|
linkToCopy = element.getAttribute('href') || '';
|
||||||
} else {
|
} else {
|
||||||
itemType = ContextMenuItemType.Text;
|
itemType = ContextMenuItemType.Text;
|
||||||
}
|
}
|
||||||
@ -640,6 +642,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
|
|||||||
contextMenuActionOptions.current = {
|
contextMenuActionOptions.current = {
|
||||||
itemType,
|
itemType,
|
||||||
resourceId,
|
resourceId,
|
||||||
|
linkToCopy,
|
||||||
textToCopy: null,
|
textToCopy: null,
|
||||||
htmlToCopy: editor.selection ? editor.selection.getContent() : '',
|
htmlToCopy: editor.selection ? editor.selection.getContent() : '',
|
||||||
insertContent: (content:string) => {
|
insertContent: (content:string) => {
|
||||||
|
@ -20,6 +20,7 @@ export enum ContextMenuItemType {
|
|||||||
export interface ContextMenuOptions {
|
export interface ContextMenuOptions {
|
||||||
itemType: ContextMenuItemType,
|
itemType: ContextMenuItemType,
|
||||||
resourceId: string,
|
resourceId: string,
|
||||||
|
linkToCopy: string,
|
||||||
textToCopy: string,
|
textToCopy: string,
|
||||||
htmlToCopy: string,
|
htmlToCopy: string,
|
||||||
insertContent: Function,
|
insertContent: Function,
|
||||||
@ -114,7 +115,7 @@ export function menuItems():ContextMenuItems {
|
|||||||
copyLinkUrl: {
|
copyLinkUrl: {
|
||||||
label: _('Copy Link Address'),
|
label: _('Copy Link Address'),
|
||||||
onAction: async (options:ContextMenuOptions) => {
|
onAction: async (options:ContextMenuOptions) => {
|
||||||
clipboard.writeText(options.textToCopy);
|
clipboard.writeText(options.linkToCopy !== null ? options.linkToCopy : options.textToCopy);
|
||||||
},
|
},
|
||||||
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Link,
|
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Link,
|
||||||
},
|
},
|
||||||
|
@ -41,6 +41,7 @@ export default function useMessageHandler(scrollWhenReady:any, setScrollWhenRead
|
|||||||
itemType: arg0 && arg0.type,
|
itemType: arg0 && arg0.type,
|
||||||
resourceId: arg0.resourceId,
|
resourceId: arg0.resourceId,
|
||||||
textToCopy: arg0.textToCopy,
|
textToCopy: arg0.textToCopy,
|
||||||
|
linkToCopy: null,
|
||||||
htmlToCopy: '',
|
htmlToCopy: '',
|
||||||
insertContent: () => { console.warn('insertContent() not implemented'); },
|
insertContent: () => { console.warn('insertContent() not implemented'); },
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user