WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / src / commands / deleteTableCells.js
1 wysihtml5.commands.deleteTableCells = {
2   exec: function(composer, command, value) {
3       if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
4           var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
5               idx = wysihtml5.dom.table.indexOf(tableSelect.start),
6               selCell,
7               table = composer.tableSelection.table;
8
9           wysihtml5.dom.table.removeCells(tableSelect.start, value);
10           setTimeout(function() {
11               // move selection to next or previous if not present
12               selCell = wysihtml5.dom.table.findCell(table, idx);
13
14               if (!selCell){
15                   if (value == "row") {
16                       selCell = wysihtml5.dom.table.findCell(table, {
17                           "row": idx.row - 1,
18                           "col": idx.col
19                       });
20                   }
21
22                   if (value == "column") {
23                       selCell = wysihtml5.dom.table.findCell(table, {
24                           "row": idx.row,
25                           "col": idx.col - 1
26                       });
27                   }
28               }
29               if (selCell) {
30                   composer.tableSelection.select(selCell, selCell);
31               }
32           }, 0);
33
34       }
35   },
36
37   state: function(composer, command) {
38       return false;
39   }
40 };