aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/cke/wiki-link/insertcommand.js
blob: 1bf36b89350656fc91ddec59b5613e08ae5c945e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Command } from 'ckeditor5/src/core';

export default class InsertCommand extends Command {
    refresh() {
        const model = this.editor.model;
        const selection = model.document.selection;
        const allowedIn = model.schema.findAllowedParent(selection.getFirstPosition(), '$text');
        this.isEnabled = allowedIn !== null;
    }

    execute({ keyword, label }) {
        this.editor.model.change((writer) => {
            this.editor.model.insertContent(
                writer.createText(label !== '' ? `[[${keyword}|${label}]]` : `[[${keyword}]]`)
            );
        });
    }
}