aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/cke/wiki-link/insertcommand.js
blob: a1ca9e2b30d6ebb6c10445a6995b9c97ab47dde5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Command } from '@ckeditor/ckeditor5-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} ]]`)
            );
        });
    }
}