mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 17:25:52 +01:00
chore(ckeditor5/plugins): integrate internal link
This commit is contained in:
30
packages/ckeditor5/src/plugins/internallink.ts
Normal file
30
packages/ckeditor5/src/plugins/internallink.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ButtonView, Plugin } from 'ckeditor5';
|
||||
import internalLinkIcon from '../icons/trilium.svg?raw';
|
||||
|
||||
export default class InternalLinkPlugin extends Plugin {
|
||||
init() {
|
||||
const editor = this.editor;
|
||||
|
||||
editor.ui.componentFactory.add('internalLink', locale => {
|
||||
const view = new ButtonView( locale );
|
||||
|
||||
view.set( {
|
||||
label: 'Internal Trilium link (CTRL-L)',
|
||||
icon: internalLinkIcon,
|
||||
tooltip: true
|
||||
} );
|
||||
|
||||
// enable internal link only if the editor is not read only
|
||||
view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly);
|
||||
|
||||
view.on('execute', () => {
|
||||
const editorEl = editor.editing.view.getDomRoot();
|
||||
const component = glob.getComponentByEl(editorEl);
|
||||
|
||||
component.triggerCommand('addLinkToText');
|
||||
} );
|
||||
|
||||
return view;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user