1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { Command } from 'ckeditor5/src/core';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export default class SelectRowCommand extends Command {
|
21 | |
22 |
|
23 |
|
24 | constructor(editor) {
|
25 | super(editor);
|
26 |
|
27 | this.affectsData = false;
|
28 | }
|
29 | |
30 |
|
31 |
|
32 | refresh() {
|
33 | const tableUtils = this.editor.plugins.get('TableUtils');
|
34 | const selectedCells = tableUtils.getSelectionAffectedTableCells(this.editor.model.document.selection);
|
35 | this.isEnabled = selectedCells.length > 0;
|
36 | }
|
37 | |
38 |
|
39 |
|
40 | execute() {
|
41 | const model = this.editor.model;
|
42 | const tableUtils = this.editor.plugins.get('TableUtils');
|
43 | const referenceCells = tableUtils.getSelectionAffectedTableCells(model.document.selection);
|
44 | const rowIndexes = tableUtils.getRowIndexes(referenceCells);
|
45 | const table = referenceCells[0].findAncestor('table');
|
46 | const rangesToSelect = [];
|
47 | for (let rowIndex = rowIndexes.first; rowIndex <= rowIndexes.last; rowIndex++) {
|
48 | for (const cell of table.getChild(rowIndex).getChildren()) {
|
49 | rangesToSelect.push(model.createRangeOn(cell));
|
50 | }
|
51 | }
|
52 | model.change(writer => {
|
53 | writer.setSelection(rangesToSelect);
|
54 | });
|
55 | }
|
56 | }
|