mike-jumper commented on code in PR #1201:
URL: https://github.com/apache/guacamole-client/pull/1201#discussion_r3085635108


##########
guacamole/src/main/frontend/src/app/textInput/directives/guacTextInput.js:
##########
@@ -286,6 +286,35 @@ angular.module('textInput').directive('guacTextInput', 
[function guacTextInput()
 
             };
 
+            // Handle paste separately from normal input.
+            target.addEventListener("paste", function targetPaste(e) {
+
+                if (!e.clipboardData)
+                    return;
+
+                // Take over paste handling before the browser inserts 
anything.
+                e.preventDefault();
+                e.stopPropagation();
+
+                var content = e.clipboardData.getData('text/plain');
+
+                // Normalize line endings to \n.
+                content = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');

Review Comment:
   This is the proper place for normalization (rather than assuming `type()` 
should not send linefeed keysyms), but would `/\r\n|\r/g` not work here 
(instead of multiple calls to `replace()`)?



##########
guacamole-common-js/src/main/webapp/modules/Keyboard.js:
##########
@@ -1060,7 +1061,31 @@ Guacamole.Keyboard = function Keyboard(element) {
             if (str.charCodeAt(i) !== codepoint) {
                 i++;
             }
-            var keysym = keysym_from_charcode(codepoint);
+
+            // CR and LF are handled explicitly; all other codepoints go 
through
+            // keysym_from_charcode().
+            var keysym;
+
+            if (codepoint === 0x0D) {
+                keysym = 0xFF0D;
+
+                // CRLF pairs are collapsed to produce a single Return.
+                var nextCodepoint = (i + 1 < str.length)
+                    ? (str.codePointAt ? str.codePointAt(i + 1) : 
str.charCodeAt(i + 1))
+                    : 0;
+
+                if (nextCodepoint === 0x0A)
+                    i++;
+            }
+            else if (codepoint === 0x0A) {
+                // keysym_from_charcode(0x0A) would return 0xFF0A which is not
+                // a keyboard character and is ignored by protocol input
+                // handlers.

Review Comment:
   `0xFF0A` is, in fact, a valid X11 keysym (see 
https://cgit.freedesktop.org/xorg/proto/x11proto/tree/keysymdef.h).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to