File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -395,16 +395,26 @@ textAngular.directive("textAngular", [
395
395
$animate . enabled ( false , scope . displayElements . html ) ;
396
396
$animate . enabled ( false , scope . displayElements . text ) ;
397
397
//Show the HTML view
398
- /* var _model;
398
+ var _model ;
399
+ /* istanbul ignore next: ngModel exists check */
399
400
if ( attrs . ngModell ) {
400
401
_model = ngModel . $viewValue ;
401
402
} else {
402
403
_model = scope . html ;
403
404
}
404
405
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
+ }
408
418
if ( scope . showHtml ) {
409
419
//defer until the element is visible
410
420
$timeout ( function ( ) {
You can’t perform that action at this time.
0 commit comments