From acaa4229929aa0ed611c2aef73dd565e42b2735e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 25 Jun 2019 14:15:15 -0700 Subject: [PATCH] GUACAMOLE-302: Do not rely on $evalAsync() for assigning focus. $evalAsync() does not necessarily guarantee execution within a timer; the provided function may well execute after the current $digest loop without control returning to the browser. If we need a timer to ensure focus() behaves reliably, we should explicitly use one via $timeout. --- .../src/main/webapp/app/element/directives/guacFocus.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/guacamole/src/main/webapp/app/element/directives/guacFocus.js b/guacamole/src/main/webapp/app/element/directives/guacFocus.js index 71e745396..5087e7f92 100644 --- a/guacamole/src/main/webapp/app/element/directives/guacFocus.js +++ b/guacamole/src/main/webapp/app/element/directives/guacFocus.js @@ -20,7 +20,11 @@ /** * A directive which allows elements to be manually focused / blurred. */ -angular.module('element').directive('guacFocus', ['$parse', function guacFocus($parse) { +angular.module('element').directive('guacFocus', ['$injector', function guacFocus($injector) { + + // Required services + var $parse = $injector.get('$parse'); + var $timeout = $injector.get('$timeout'); return { restrict: 'A', @@ -44,7 +48,7 @@ angular.module('element').directive('guacFocus', ['$parse', function guacFocus($ // Set/unset focus depending on value of guacFocus $scope.$watch(guacFocus, function updateFocus(value) { - $scope.$evalAsync(function updateFocusAsync() { + $timeout(function updateFocusAfterRender() { if (value) element.focus(); else