Skip to content

Commit

Permalink
GUACAMOLE-1904: Allow a custom field to request keyboard access when …
Browse files Browse the repository at this point in the history
…menu is closed.
  • Loading branch information
jmuehlner committed Jan 12, 2024
1 parent c7e3b03 commit ebb36a0
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams

};

/**
* True if and only if a "guacFieldFocused" event was received, and a
* corresponding "guacFieldBlurred" event has not yet been received.
* This is intended to allow fields to receive keyboard input even when
* the menu is not being shown.
*
* @type {boolean}
*/
$scope.fieldIsFocused = false;

// Enable and disable the custom field focused state as the relevant
// events are received
$scope.$on('guacFieldFocused', () => $scope.fieldIsFocused = true);
$scope.$on('guacFieldBlurred', () => $scope.fieldIsFocused = false);

// Convenience method for closing the menu
$scope.closeMenu = function closeMenu() {
$scope.menu.shown = false;
Expand Down Expand Up @@ -468,7 +483,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
else if (menuShownPreviousState)
$scope.applyParameterChanges($scope.focusedClient);

/* Broadcast changes to the menu display state */
// Broadcast changes to the menu display state
$scope.$broadcast('guacMenuShown', menuShown);

});
Expand Down Expand Up @@ -610,15 +625,17 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams

}

// Prevent all keydown events while menu is open
else if ($scope.menu.shown)
// Prevent all keydown events while menu is open, or if a field has
// explicity requested the focused state
else if ($scope.menu.shown || $scope.fieldIsFocused)
event.preventDefault();

});

// Prevent all keyup events while menu is open
// Prevent all keyup events while menu is open,
// or while a custom field is focused.
$scope.$on('guacBeforeKeyup', function incomingKeyup(event, keysym, keyboard) {
if ($scope.menu.shown)
if ($scope.menu.shown || $scope.fieldIsFocused)
event.preventDefault();
});

Expand Down

0 comments on commit ebb36a0

Please sign in to comment.