mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-128: Merge fix clipboard bounce.
This commit is contained in:
@@ -44,6 +44,14 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
|||||||
*/
|
*/
|
||||||
var CLIPBOARD_READ_DELAY = 100;
|
var CLIPBOARD_READ_DELAY = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The promise associated with the current pending clipboard read attempt.
|
||||||
|
* If no clipboard read is active, this will be null.
|
||||||
|
*
|
||||||
|
* @type Promise.<ClipboardData>
|
||||||
|
*/
|
||||||
|
var pendingRead = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the window.document object.
|
* Reference to the window.document object.
|
||||||
*
|
*
|
||||||
@@ -78,6 +86,7 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Prevent events generated due to execCommand() from disturbing external things
|
// Prevent events generated due to execCommand() from disturbing external things
|
||||||
|
clipboardContent.addEventListener('cut', stopEventPropagation);
|
||||||
clipboardContent.addEventListener('copy', stopEventPropagation);
|
clipboardContent.addEventListener('copy', stopEventPropagation);
|
||||||
clipboardContent.addEventListener('paste', stopEventPropagation);
|
clipboardContent.addEventListener('paste', stopEventPropagation);
|
||||||
|
|
||||||
@@ -398,8 +407,16 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
|||||||
*/
|
*/
|
||||||
service.getLocalClipboard = function getLocalClipboard() {
|
service.getLocalClipboard = function getLocalClipboard() {
|
||||||
|
|
||||||
|
// If the clipboard is already being read, do not overlap the read
|
||||||
|
// attempts; instead share the result across all requests
|
||||||
|
if (pendingRead)
|
||||||
|
return pendingRead;
|
||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
// Mark read attempt as in progress
|
||||||
|
pendingRead = deferred.promise;
|
||||||
|
|
||||||
// Wait for the next event queue run before attempting to read
|
// Wait for the next event queue run before attempting to read
|
||||||
// clipboard data (in case the copy/cut has not yet completed)
|
// clipboard data (in case the copy/cut has not yet completed)
|
||||||
$window.setTimeout(function deferredClipboardRead() {
|
$window.setTimeout(function deferredClipboardRead() {
|
||||||
@@ -467,6 +484,9 @@ angular.module('clipboard').factory('clipboardService', ['$injector',
|
|||||||
originalElement.focus();
|
originalElement.focus();
|
||||||
popSelection();
|
popSelection();
|
||||||
|
|
||||||
|
// No read is pending any longer
|
||||||
|
pendingRead = null;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ensure clipboard element is blurred (and that the "focus" event
|
// Ensure clipboard element is blurred (and that the "focus" event
|
||||||
|
@@ -137,8 +137,8 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
|||||||
|
|
||||||
// Attempt to read the clipboard if it may have changed
|
// Attempt to read the clipboard if it may have changed
|
||||||
$window.addEventListener('load', checkClipboard, true);
|
$window.addEventListener('load', checkClipboard, true);
|
||||||
$window.addEventListener('copy', checkClipboard, true);
|
$window.addEventListener('copy', checkClipboard);
|
||||||
$window.addEventListener('cut', checkClipboard, true);
|
$window.addEventListener('cut', checkClipboard);
|
||||||
$window.addEventListener('focus', function focusGained(e) {
|
$window.addEventListener('focus', function focusGained(e) {
|
||||||
|
|
||||||
// Only recheck clipboard if it's the window itself that gained focus
|
// Only recheck clipboard if it's the window itself that gained focus
|
||||||
|
Reference in New Issue
Block a user