Skip to content

Commit b1206a8

Browse files
committed
Fix(main, globals): Corrected issue with clobering the html from the model too easily.
Added getDomFromHtml() and corrected when this is used.
1 parent 6ffcdc5 commit b1206a8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/globals.js

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ function stripHtmlToText(html)
5757
res = res.replace(/\n/, "");
5858
return res.trim();
5959
}
60+
// get html
61+
function getDomFromHtml(html)
62+
{
63+
var tmp = document.createElement("DIV");
64+
tmp.innerHTML = html;
65+
return tmp;
66+
}
67+
6068

6169
// Global to textAngular REGEXP vars for block and list elements.
6270

src/main.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,10 @@ textAngular.directive("textAngular", [
403403
_model = scope.html;
404404
}
405405
var _html = scope.displayElements.html[0].value;
406-
// find first non-tag match - ie start of string or after tag that is not whitespace
407-
var _firstMatchModel = /(^[^<]|>)[^<]/i.exec(_model);
408-
var _firstMatchHtml = /(^[^<]|>)[^<]/i.exec(_html);
409-
if (_firstMatchHtml && _firstMatchModel) {
410-
if ((_firstMatchHtml.index !== _firstMatchModel.index)) {
411-
// the model and the html do not agree
412-
// they can get out of sync and when they do, we correct that here...
413-
//console.log('model', _firstMatchModel, _model);
414-
//console.log('html', _firstMatchHtml, _html);
415-
scope.displayElements.html.val(_model);
416-
}
406+
if (getDomFromHtml(_html).childElementCount !== getDomFromHtml(_model).childElementCount) {
407+
// the model and the html do not agree
408+
// they can get out of sync and when they do, we correct that here...
409+
scope.displayElements.html.val(_model);
417410
}
418411
if(scope.showHtml){
419412
//defer until the element is visible

0 commit comments

Comments
 (0)