Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into row-column-remove-no-container
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
mightyiam committed Nov 27, 2015
2 parents 10ab6c4 + 4f6f147 commit d9db8ca
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ WYMeditor.

* [#761](https://github.com/wymeditor/wymeditor/pull/761)
Fix: Image resize handle below end of iframe
* [#748](https://github.com/wymeditor/wymeditor/issues/748)
Reposition caret when removing row/column that contains selection
* [#763](https://github.com/wymeditor/wymeditor/issues/763)
Enable Firefox's native table editing
* [#764](https://github.com/wymeditor/wymeditor/pull/764)
TablePlugin row/column remove:
refrain from error when no selectedContainer
Expand Down
154 changes: 44 additions & 110 deletions src/test/unit/plugin_tests/table_test.js
@@ -1,5 +1,6 @@
/* jshint maxlen: 90 */
/* global
inPhantomjs,
expectOneMore,
SKIP_KNOWN_FAILING_TESTS,
prepareUnitTestModule,
Expand Down Expand Up @@ -905,120 +906,88 @@ test("Deleting all columns removes table", function () {
});
});

test("Deselects before removing row that contains collapsed selection",
function () {
test("Removing tr, caret is set to first td of previous tr if no next tr", function () {
var prevTd;
manipulationTestHelper({
startHtml: basicTableHtml,
setCaretInSelector: "#td_3_1",
manipulationFunc: function (wymeditor) {
var tr = wymeditor.$body().find("#tr_3")[0];
prevTd = tr.previousSibling.childNodes[0];
if (
inPhantomjs ||
(jQuery.browser.msie && jQuery.browser.versionNumber === 8)
) {
// the caret ends up inside #span_2_1,
// which is fine
prevTd = prevTd.childNodes[0];
}
wymeditor.tableEditor.removeRow(tr);
},
additionalAssertionsFunc: function (wymeditor) {
expectOneMore();
// This doesn't really test that .deselect() was called. We'd need
// a spy for that. Good enough.
strictEqual(
wymeditor.hasSelection(),
false,
"No selection"
wymeditor.selectedContainer(),
prevTd,
"selected container"
);
},
expectedResultHtml: removedRow3Html
}
});
});

test("Deselects before removing row that fully contains non-collapsed " +
"selection", function () {
test("Removing tr, caret is set to first td of next tr, if exists", function () {
var nextTd;
manipulationTestHelper({
startHtml: basicTableHtml,
prepareFunc: function (wymeditor) {
var td32 = wymeditor.$body().find("#td_3_2")[0],
td33 = wymeditor.$body().find("#td_3_3")[0];
makeTextSelection(
wymeditor,
td32,
td33,
0,
3
);
},
setCaretInSelector: "#td_3_1",
manipulationFunc: function (wymeditor) {
var tr = wymeditor.$body().find("#tr_3")[0];
var tr = wymeditor.$body().find("#tr_2")[0];
nextTd = tr.nextSibling.childNodes[0];
wymeditor.tableEditor.removeRow(tr);
},
additionalAssertionsFunc: function (wymeditor) {
expectOneMore();
// This doesn't really test that .deselect() was called. We'd need
// a spy for that. Good enough.
strictEqual(
wymeditor.hasSelection(),
false,
"No selection"
wymeditor.selectedContainer(),
nextTd,
"selected container"
);
},
expectedResultHtml: removedRow3Html
}
});
});

test("Deselects before removing row that partially contains non-collapsed " +
"selection", function () {
test("Removing column, caret is set to next td, if exists", function () {
var nextTd;
manipulationTestHelper({
startHtml: basicTableHtml,
prepareFunc: function (wymeditor) {
var td22 = wymeditor.$body().find("#td_2_2")[0],
td33 = wymeditor.$body().find("#td_3_3")[0];
var td32 = wymeditor.$body().find("#td_3_2")[0];
makeTextSelection(
wymeditor,
td22,
td33,
td32,
td32,
0,
3
);
nextTd = td32.nextSibling;
},
manipulationFunc: function (wymeditor) {
var tr = wymeditor.$body().find("#tr_3")[0];
wymeditor.tableEditor.removeRow(tr);
var td12 = wymeditor.$body().find("#td_1_2")[0];
wymeditor.tableEditor.removeColumn(td12);
},
additionalAssertionsFunc: function (wymeditor) {
expectOneMore();
// This doesn't really test that .deselect() was called. We'd need
// a spy for that. Good enough.
strictEqual(
wymeditor.hasSelection(),
false,
"No selection"
wymeditor.selectedContainer(),
nextTd,
"selected container"
);
},
expectedResultHtml: removedRow3Html
});
});

test("Deselects before removing column that contains collapsed selection",
function () {
manipulationTestHelper({
startHtml: basicTableHtml,
setCaretInSelector: "#td_3_3",
manipulationFunc: function (wymeditor) {
var td13 = wymeditor.$body().find("#td_1_3")[0];
wymeditor.tableEditor.removeColumn(td13);
},
additionalAssertionsFunc: function (wymeditor) {
expectOneMore();
// This doesn't really test that .deselect() was called. We'd need
// a spy for that. Good enough.
strictEqual(
wymeditor.hasSelection(),
false,
"No selection"
);
},
expectedResultHtml: removedColumn3Html
}
});
});

test("Deselects before removing column that fully contains non-collapsed " +
"selection", function () {
test("Removing column, caret is set to previous td, if no next td", function () {
var prevTd;
manipulationTestHelper({
startHtml: basicTableHtml,
prepareFunc: function (wymeditor) {
Expand All @@ -1030,55 +999,20 @@ test("Deselects before removing column that fully contains non-collapsed " +
0,
3
);
prevTd = td33.previousSibling;
},
manipulationFunc: function (wymeditor) {
var td13 = wymeditor.$body().find("#td_1_3")[0];
wymeditor.tableEditor.removeColumn(td13);
},
additionalAssertionsFunc: function (wymeditor) {
expectOneMore();
// This doesn't really test that .deselect() was called. We'd need
// a spy for that. Good enough.
strictEqual(
wymeditor.hasSelection(),
false,
"No selection"
);
},
expectedResultHtml: removedColumn3Html
});
});

test("Deselects before removing column that partially contains non-collapsed " +
"selection", function () {
manipulationTestHelper({
startHtml: basicTableHtml,
prepareFunc: function (wymeditor) {
var td13 = wymeditor.$body().find("#td_1_3")[0],
td33 = wymeditor.$body().find("#td_3_3")[0];
makeTextSelection(
wymeditor,
td13,
td33,
0,
3
);
},
manipulationFunc: function (wymeditor) {
var td13 = wymeditor.$body().find("#td_1_3")[0];
wymeditor.tableEditor.removeColumn(td13);
},
additionalAssertionsFunc: function (wymeditor) {
expectOneMore();
// This doesn't really test that .deselect() was called. We'd need
// a spy for that. Good enough.
strictEqual(
wymeditor.hasSelection(),
false,
"No selection"
wymeditor.selectedContainer(),
prevTd,
"selected container"
);
},
expectedResultHtml: removedColumn3Html
}
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/wymeditor/editor/gecko.js
Expand Up @@ -146,7 +146,8 @@ WYMeditor.WymClassGecko.prototype._designModeQuirks = function () {
try {
wym._doc.execCommand("styleWithCSS", '', false);
wym._doc.execCommand("enableObjectResizing", false, false);
wym._doc.execCommand("enableInlineTableEditing", false, false);
// commented out in #763
//wym._doc.execCommand("enableInlineTableEditing", false, false);
} catch (e) {}
};

Expand Down
23 changes: 21 additions & 2 deletions src/wymeditor/plugins/table/jquery.wymeditor.table.js
Expand Up @@ -581,11 +581,21 @@ TableEditor.prototype.removeRow = function (elmnt) {
return;
}
table = wym.findUp(elmnt, 'table');
var $tr = jQuery(tr);
if (
wym.hasSelection() === true &&
wym.doesElementContainSelection(elmnt) === true
) {
wym.deselect();
// place the caret somewhere reasonable
// instead of allowing it to disappear
// along with the removed row
var $target = $tr.next('tr').children('td').first();
if (!$target.length) {
$target = $tr.prev('tr').children('td').first();
}
if ($target.length) {
wym.setCaretIn($target[0]);
}
}
jQuery(tr).remove();
tableEditor.removeEmptyTable(table);
Expand Down Expand Up @@ -655,7 +665,16 @@ TableEditor.prototype.removeColumn = function (elmnt) {
wym.hasSelection() === true &&
wym.doesElementContainSelection($cell[0]) === true
) {
wym.deselect();
// place the caret somewhere reasonable
// instead of allowing it to disappear
// along with the removed column
var $target = $cell.next('td');
if (!$target.length) {
$target = $cell.prev('td');
}
if ($target.length) {
wym.setCaretIn($target[0]);
}
}
$cell.remove();
});
Expand Down

0 comments on commit d9db8ca

Please sign in to comment.