Skip to content

Commit 91fe5bf

Browse files
committed
Fix(main): Corrected issues with html and model getting out of synch!
1 parent 31cf9c4 commit 91fe5bf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,26 @@ textAngular.directive("textAngular", [
395395
$animate.enabled(false, scope.displayElements.html);
396396
$animate.enabled(false, scope.displayElements.text);
397397
//Show the HTML view
398-
/* var _model;
398+
var _model;
399+
/* istanbul ignore next: ngModel exists check */
399400
if (attrs.ngModell) {
400401
_model = ngModel.$viewValue;
401402
} else {
402403
_model = scope.html;
403404
}
404405
var _html = scope.displayElements.html[0].value;
405-
console.log('model', _model);
406-
console.log('html', _html);
407-
*/
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+
}
417+
}
408418
if(scope.showHtml){
409419
//defer until the element is visible
410420
$timeout(function(){

0 commit comments

Comments
 (0)