Skip to content

Commit

Permalink
fix(textAngular): Prevent updateSelectedStyles loop when out of docum…
Browse files Browse the repository at this point in the history
…ent focus

Potential fix for #443
  • Loading branch information
SimeonC authored and SimeonC committed Dec 16, 2014
1 parent 0187345 commit 81a37de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/textAngular.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ textAngular.directive("textAngular", [
_toolbars.updateSelectedStyles(angular.element(_selection));
}else _toolbars.updateSelectedStyles();
// used to update the active state when a key is held down, ie the left arrow
if(scope._bUpdateSelectedStyles) $timeout(scope.updateSelectedStyles, 200);
/* istanbul ignore else: browser only check */
if(scope._bUpdateSelectedStyles && $document.hasFocus()) $timeout(scope.updateSelectedStyles, 200);
else scope._bUpdateSelectedStyles = false;
};
// start updating on keydown
_keydown = function(){
Expand Down
4 changes: 3 additions & 1 deletion src/textAngular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,9 @@ textAngular.directive("textAngular", [
_toolbars.updateSelectedStyles(angular.element(_selection));
}else _toolbars.updateSelectedStyles();
// used to update the active state when a key is held down, ie the left arrow
if(scope._bUpdateSelectedStyles) $timeout(scope.updateSelectedStyles, 200);
/* istanbul ignore else: browser only check */
if(scope._bUpdateSelectedStyles && $document.hasFocus()) $timeout(scope.updateSelectedStyles, 200);
else scope._bUpdateSelectedStyles = false;
};
// start updating on keydown
_keydown = function(){
Expand Down
3 changes: 2 additions & 1 deletion test/textAngular.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,8 @@ describe('textAngular', function(){
expect(!iButton.hasClass('active'));
});

it('should change on keydown and stop on keyup', inject(function($timeout){
it('should change on keydown and stop on keyup', inject(function($timeout, $document){
$document.hasFocus = function(){return true;};
editorScope.displayElements.text.triggerHandler('keydown');
range.selectNodeContents(editorScope.displayElements.text.find('p').find('u')[0]);
sel.setSingleRange(range);
Expand Down

0 comments on commit 81a37de

Please sign in to comment.