Skip to content

Commit

Permalink
Updated test case and fixed selection controlrange bug
Browse files Browse the repository at this point in the history
  • Loading branch information
timdown committed Mar 29, 2011
1 parent 6b80488 commit 0e0f0ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/js/core/wrappedselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ rangy.createModule("WrappedSelection", function(api, module) {
updateEmptySelection(sel);
} else {
var controlRange = sel.docSelection.createRange();
if (isTextRange(range)) {
if (isTextRange(controlRange)) {
// This case (where the selection type is "Control" and calling createRange() on the selection returns
// a TextRange) can happen in IE 9. It happens, for example, when all elements in the selected
// ControlRange have been removed from the ControlRange and removed from the document.
updateFromTextRange(sel, range);
updateFromTextRange(sel, controlRange);
} else {
sel.rangeCount = controlRange.length;
var range, doc = dom.getDocument(controlRange.item(0));
Expand Down
7 changes: 5 additions & 2 deletions test/ie9controlrange.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
controlRange.remove(input2);
input2.parentNode.removeChild(input2);
alert("Type before creating range: " + document.selection.type);
var sel = document.selection;
var range = document.selection.createRange();
var sel2 = document.selection;
var selChanged = (sel != sel2);
var rangeType = (typeof range.text == "undefined") ? "ControlRange" : "TextRange";
alert("Type after creating range: " + document.selection.type + ". Range type: " + rangeType);
alert("Type after creating range: " + document.selection.type + ". Range type: " + rangeType + ", selChanged: " + selChanged);
};
</script>
</head>
<body>
<input id="i1"><input id="i2">
<input id="i1"> and <input id="i2">

</body>
</html>

0 comments on commit 0e0f0ec

Please sign in to comment.