Skip to content

Commit

Permalink
Improve condition in solution. Remove debugger referrence. Add unit t…
Browse files Browse the repository at this point in the history
…est and description to manual
  • Loading branch information
Mateusz Samsel committed Jul 17, 2017
1 parent aa275a0 commit 77bffe3
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 2 deletions.
3 changes: 1 addition & 2 deletions plugins/tabletools/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@
}

function deleteColumns( selection ) {
// debugger;
var ranges = selection.getRanges(),
cells = getSelectedCells( selection ),
firstCell = cells[ 0 ],
Expand All @@ -314,7 +313,7 @@
// #577
// Map might contain multiple times this same element, because of existings collspan.
// We don't want to overwrite startIndex in such situation and take first one.
if ( !startColIndex && map[ i ][ j ] == firstCell.$ ) {
if ( startColIndex === undefined && map[ i ][ j ] == firstCell.$ ) {
startColIndex = j;
}
if ( map[ i ][ j ] == lastCell.$ ) {
Expand Down
331 changes: 331 additions & 0 deletions tests/plugins/tabletools/columndeletion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
<textarea id="table-1">
<table>
<tr>
<td>[foo]</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>[foo]</td>
<td>bar</td>
<td>baz</td>
</tr>
</table>
=>
<table>
<tbody>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="table-2">
<table>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>[bar</td>
<td>baz]</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
</table>
=>
<table>
<tbody>
<tr>
<td>foo</td>
</tr>
<tr>
<td>foo</td>
</tr>
<tr>
<td>foo</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="table-3">
<table>
<thead>
<tr>
<th colspan="2" scope="col">
[Header1]
</th>
<th colspan="1" scope="col">
Header2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
=>
<table>
<thead>
<tr>
<th colspan="1" scope="col">
Header2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>baz</td>
</tr>
<tr>
<td>baz</td>
</tr>
<tr>
<td>baz</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="table-4">
<table>
<thead>
<tr>
<th colspan="3" scope="col">
Header
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>[baz]</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
=>
<table>
<thead>
<tr>
<th colspan="2" scope="col">
Header
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="table-5">
<table>
<thead>
<tr>
<th colspan="3" scope="col">
Header1
</th>
<th colspan="3" scope="col">
Header2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>[baz</td>
<td>foo]</td>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
=>
<table>
<thead>
<tr>
<th colspan="2" scope="col">
Header1
</th>
<th colspan="2" scope="col">
Header2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="table-6">
<table>
<thead>
<tr>
<th colspan="3" scope="col">
Header1
</th>
<th colspan="3" scope="col">
Header2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
<td>[foo</td>
<td>bar</td>
<td>baz]</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
<td>[foo</td>
<td>bar</td>
<td>baz]</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
<td>[foo</td>
<td>bar</td>
<td>baz]</td>
</tr>
</tbody>
</table>
=>
<table>
<thead>
<tr>
<th colspan="3" scope="col">
Header1
</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
</tbody>
</table>
</textarea>

<textarea id="table-7">
<table>
<tr>
<td>[foo</td>
<td>bar</td>
<td>baz]</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>baz</td>
</tr>
</table>
=>

</textarea>
Loading

0 comments on commit 77bffe3

Please sign in to comment.