diff --git a/guacamole/src/main/frontend/src/app/textInput/directives/guacTextInput.js b/guacamole/src/main/frontend/src/app/textInput/directives/guacTextInput.js index eeac777e3e..8936176ea8 100644 --- a/guacamole/src/main/frontend/src/app/textInput/directives/guacTextInput.js +++ b/guacamole/src/main/frontend/src/app/textInput/directives/guacTextInput.js @@ -286,6 +286,41 @@ angular.module('textInput').directive('guacTextInput', [function guacTextInput() }; + // Handle paste events separately from other input events. + target.addEventListener("paste", function targetPaste(e) { + + if (!e.clipboardData) + return; + + var content = e.clipboardData.getData('text/plain'); + + if (content === null) + return; + + // Normalize line endings to \n before replaying as key events. + content = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); + + // Release modifiers first to avoid pasted characters being + // interpreted as Ctrl+char or Alt+char combinations in the + // remote session. + $rootScope.$broadcast('guacSyntheticKeyup', 0xFFE3); // Left Ctrl + $rootScope.$broadcast('guacSyntheticKeyup', 0xFFE4); // Right Ctrl + $rootScope.$broadcast('guacSyntheticKeyup', 0xFFE9); // Left Alt + $rootScope.$broadcast('guacSyntheticKeyup', 0xFFEA); // Right Alt + + sendString(content); + + releaseStickyKeys(); + resetTextInputTarget(TEXT_INPUT_PADDING); + + // Prevent the input handler from also processing pasted content. + // This also prevents additional insertParagraph events from being + // generated by Chrome. + e.preventDefault(); + e.stopPropagation(); + + }, false); + target.addEventListener("input", function(e) { // Ignore input events during text composition