1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { Command } from 'ckeditor5/src/core';
|
9 | import { getSelectedListItems } from '../list/utils';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export default class ListStartCommand extends Command {
|
15 | |
16 |
|
17 |
|
18 | refresh() {
|
19 | const value = this._getValue();
|
20 | this.value = value;
|
21 | this.isEnabled = value != null;
|
22 | }
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | execute({ startIndex = 1 } = {}) {
|
30 | const model = this.editor.model;
|
31 | const listItems = getSelectedListItems(model)
|
32 | .filter(item => item.getAttribute('listType') == 'numbered');
|
33 | model.change(writer => {
|
34 | for (const item of listItems) {
|
35 | writer.setAttribute('listStart', startIndex >= 0 ? startIndex : 1, item);
|
36 | }
|
37 | });
|
38 | }
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | _getValue() {
|
45 | const listItem = this.editor.model.document.selection.getFirstPosition().parent;
|
46 | if (listItem && listItem.is('element', 'listItem') && listItem.getAttribute('listType') == 'numbered') {
|
47 | return listItem.getAttribute('listStart');
|
48 | }
|
49 | return null;
|
50 | }
|
51 | }
|