mirror of
https://github.com/zadam/trilium.git
synced 2025-11-09 06:45:49 +01:00
feat(slash): insert internal link
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ButtonView, Command, Plugin } from 'ckeditor5';
|
||||
import dateTimeIcon from '../icons/date-time.svg?raw';
|
||||
|
||||
const COMMAND_NAME = 'insertDateTimeToText';
|
||||
export const COMMAND_NAME = 'insertDateTimeToText';
|
||||
|
||||
export default class InsertDateTimePlugin extends Plugin {
|
||||
init() {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { ButtonView, Plugin } from 'ckeditor5';
|
||||
import { ButtonView, Command, Plugin } from 'ckeditor5';
|
||||
import internalLinkIcon from '../icons/trilium.svg?raw';
|
||||
import ReferenceLink from './referencelink';
|
||||
|
||||
export const COMMAND_NAME = 'insertInternalLink';
|
||||
|
||||
export default class InternalLinkPlugin extends Plugin {
|
||||
|
||||
static get requires() {
|
||||
@@ -11,6 +13,8 @@ export default class InternalLinkPlugin extends Plugin {
|
||||
init() {
|
||||
const editor = this.editor;
|
||||
|
||||
editor.commands.add(COMMAND_NAME, new InsertInternalLinkCommand(editor));
|
||||
|
||||
editor.ui.componentFactory.add('internalLink', locale => {
|
||||
const view = new ButtonView( locale );
|
||||
|
||||
@@ -21,16 +25,28 @@ export default class InternalLinkPlugin extends Plugin {
|
||||
} );
|
||||
|
||||
// enable internal link only if the editor is not read only
|
||||
view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly);
|
||||
|
||||
const command = editor.commands.get(COMMAND_NAME)!;
|
||||
view.bind('isEnabled').to(command, 'isEnabled');
|
||||
view.on('execute', () => {
|
||||
const editorEl = editor.editing.view.getDomRoot();
|
||||
const component = glob.getComponentByEl(editorEl);
|
||||
|
||||
component.triggerCommand('addLinkToText');
|
||||
editor.execute(COMMAND_NAME);
|
||||
} );
|
||||
|
||||
return view;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class InsertInternalLinkCommand extends Command {
|
||||
|
||||
refresh() {
|
||||
this.isEnabled = !this.editor.isReadOnly;
|
||||
}
|
||||
|
||||
execute() {
|
||||
const editor = this.editor;
|
||||
const editorEl = editor.editing.view.getDomRoot();
|
||||
const component = glob.getComponentByEl(editorEl);
|
||||
|
||||
component.triggerCommand('addLinkToText');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user